Documentation ¶
Overview ¶
Package types implements the language built in primitypes types, the Object type and the Object wrappers for each primitive type.
Documentation: https://es5.github.io/#x8
Index ¶
- Variables
- func CopyProperties(dst, src *PropertyDescriptor)
- func IsPrimitive(val Value) bool
- func IsSameDescriptor(a, b *PropertyDescriptor) bool
- func IsSameDescriptorSettings(a, b *PropertyDescriptor) bool
- func StrictEqual(a, b Value) bool
- type Bool
- func (b Bool) Equal(a Bool) bool
- func (b Bool) IsFalse() bool
- func (b Bool) IsTrue() bool
- func (_ Bool) Kind() Kind
- func (b Bool) ToBool() Bool
- func (b Bool) ToNumber() Number
- func (b Bool) ToObject() (Object, error)
- func (b Bool) ToPrimitive(hint Kind) (Value, error)
- func (b Bool) ToString() String
- type Builtinfn
- type DataObject
- func (o *DataObject) CanPut(name utf16.Str) bool
- func (o *DataObject) Class() string
- func (o *DataObject) DefaultValue(hint Kind) (Value, error)
- func (o *DataObject) DefineOwnProperty(name utf16.Str, desc Value, throw bool) (bool, error)
- func (o *DataObject) DefineOwnPropertyP(name utf16.Str, desc *PropertyDescriptor, throw bool) (bool, error)
- func (o *DataObject) Get(name utf16.Str) (Value, error)
- func (o *DataObject) GetOwnProperty(name utf16.Str) Value
- func (o *DataObject) GetProperty(name utf16.Str) Value
- func (o *DataObject) HasProperty(name utf16.Str) bool
- func (o *DataObject) IsFalse() bool
- func (o *DataObject) IsTrue() bool
- func (*DataObject) Kind() Kind
- func (o *DataObject) NotExtensible() bool
- func (o *DataObject) Put(name utf16.Str, val Value, throw bool) error
- func (o *DataObject) String() string
- func (*DataObject) ToBool() Bool
- func (o *DataObject) ToNumber() Number
- func (o *DataObject) ToObject() (Object, error)
- func (o *DataObject) ToPrimitive(hint Kind) (Value, error)
- func (o *DataObject) ToPropertyDescriptor() *PropertyDescriptor
- func (o *DataObject) ToString() String
- type ECMAObject
- type Execfn
- type Function
- type Kind
- type Number
- func (a Number) Equal(b Number) bool
- func (a Number) IsFalse() bool
- func (a Number) IsTrue() bool
- func (_ Number) Kind() Kind
- func (a Number) String() string
- func (a Number) ToBool() Bool
- func (a Number) ToNumber() Number
- func (a Number) ToObject() (Object, error)
- func (a Number) ToPrimitive(hint Kind) (Value, error)
- func (a Number) ToString() String
- func (a Number) Value() float64
- type Object
- type PropertyDescriptor
- func DefaultAcessorPropDesc() *PropertyDescriptor
- func DefaultDataPropDesc() *PropertyDescriptor
- func DefaultPrototypeDesc() *PropertyDescriptor
- func NewAcessorPropDesc(get, set Value, enum, cfg bool) *PropertyDescriptor
- func NewDataPropDesc(value Value, wrt, enum, cfg bool) *PropertyDescriptor
- func NewGenericPropDesc() *PropertyDescriptor
- func (p *PropertyDescriptor) Cfg() Value
- func (p *PropertyDescriptor) Enum() Value
- func (p *PropertyDescriptor) Get() Value
- func (p *PropertyDescriptor) HasCfg() bool
- func (p *PropertyDescriptor) HasEnum() bool
- func (p *PropertyDescriptor) HasGet() bool
- func (p *PropertyDescriptor) HasSet() bool
- func (p *PropertyDescriptor) HasValue() bool
- func (p *PropertyDescriptor) HasWritable() bool
- func (p *PropertyDescriptor) IsAbsentDescriptor() bool
- func (p *PropertyDescriptor) IsAcessorDescriptor() bool
- func (p *PropertyDescriptor) IsDataDescriptor() bool
- func (p *PropertyDescriptor) IsGenericDescriptor() bool
- func (p *PropertyDescriptor) Set() Value
- func (p *PropertyDescriptor) SetCfg(b Bool)
- func (p *PropertyDescriptor) SetEnum(b Bool)
- func (p *PropertyDescriptor) SetGet(get Value)
- func (p *PropertyDescriptor) SetSet(set Value)
- func (p *PropertyDescriptor) SetValue(v Value)
- func (p *PropertyDescriptor) SetWritable(b Bool)
- func (p *PropertyDescriptor) ToObject() *DataObject
- func (p *PropertyDescriptor) Value() Value
- func (p *PropertyDescriptor) Writable() Value
- type String
- func (a String) Equal(b String) bool
- func (a String) IsFalse() bool
- func (a String) IsTrue() bool
- func (a String) Kind() Kind
- func (a String) Length() int
- func (a String) String() string
- func (a String) ToBool() Bool
- func (a String) ToNumber() Number
- func (a String) ToObject() (Object, error)
- func (a String) ToPrimitive(hint Kind) (Value, error)
- func (a String) ToString() String
- type TypeError
- type UserFunction
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( DefValue = Undefined DefWritable = False DefGet = Undefined DefSet = Undefined DefEnumerable = False DefConfigurable = False )
Default attribute values Table 7 in https://es5.github.io/#x8.6.1
var Null = null(utf16.S("null"))
var ( // S is an alias to make utf-16 strings. S = utf16.S )
var Undefined = undefined(utf16.S("undefined")) // undefined undefinedness undefining undefined =P
Functions ¶
func CopyProperties ¶
func CopyProperties(dst, src *PropertyDescriptor)
CopyProperties from descriptor src to dst.
func IsSameDescriptor ¶
func IsSameDescriptor(a, b *PropertyDescriptor) bool
IsSameDescriptor compares if descriptors are the same.
func IsSameDescriptorSettings ¶
func IsSameDescriptorSettings(a, b *PropertyDescriptor) bool
IsSameDescriptorSettings compares if descriptors are the same ignoring the value (Looking only at the configs).
func StrictEqual ¶
StrictEqual compares values a and b using ECMAScript === (strict) rules.
Types ¶
type Builtinfn ¶
type Builtinfn struct { *UserFunction // contains filtered or unexported fields }
func NewBuiltinfn ¶
type DataObject ¶
type DataObject struct {
// contains filtered or unexported fields
}
DataObject is a collection of named values.
func NewBaseDataObject ¶
func NewBaseDataObject() *DataObject
NewBaseDataObject is the same as ecmascript code:
Object.create(null);
This is the root of the prototype chain.
func NewDataObject ¶
func NewDataObject(proto Value) *DataObject
NewDataObject creates a new DataObject using proto as prototype.
func NewDataObjectP ¶
func NewDataObjectP(proto *PropertyDescriptor) *DataObject
NewDataObjectP creates an object with PropertyDescriptor proto as prototype attribute. The *everything is an object* concept makes impossible to defineOwnProperties work by passing an object to define an object (recursive definition).
func (*DataObject) DefaultValue ¶
func (o *DataObject) DefaultValue(hint Kind) (Value, error)
func (*DataObject) DefineOwnProperty ¶
func (*DataObject) DefineOwnPropertyP ¶
func (o *DataObject) DefineOwnPropertyP( name utf16.Str, desc *PropertyDescriptor, throw bool, ) (bool, error)
func (*DataObject) Get ¶
func (o *DataObject) Get(name utf16.Str) (Value, error)
Get is the default [[Get]] implementation for objects. https://es5.github.io/#x8.12.3
func (*DataObject) GetOwnProperty ¶
func (o *DataObject) GetOwnProperty(name utf16.Str) Value
func (*DataObject) GetProperty ¶
func (o *DataObject) GetProperty(name utf16.Str) Value
func (*DataObject) HasProperty ¶
func (o *DataObject) HasProperty(name utf16.Str) bool
func (*DataObject) IsFalse ¶
func (o *DataObject) IsFalse() bool
IsFalse SHALL return false for objects.
func (*DataObject) IsTrue ¶
func (o *DataObject) IsTrue() bool
IsTrue SHALL return true for objects.
func (*DataObject) NotExtensible ¶
func (o *DataObject) NotExtensible() bool
func (*DataObject) String ¶
func (o *DataObject) String() string
func (*DataObject) ToBool ¶
func (*DataObject) ToBool() Bool
ToBool SHALL return a True value for object.
func (*DataObject) ToNumber ¶
func (o *DataObject) ToNumber() Number
ToNumber tries to convert the object into a number using several rules (see ToNumber in the spec) but most important rule is look into the valueOf attribute of the object.
func (*DataObject) ToObject ¶
func (o *DataObject) ToObject() (Object, error)
ToObject returns itself.
func (*DataObject) ToPrimitive ¶
func (o *DataObject) ToPrimitive(hint Kind) (Value, error)
func (*DataObject) ToPropertyDescriptor ¶
func (o *DataObject) ToPropertyDescriptor() *PropertyDescriptor
ToPropertyDescriptor creates a PropertyDescriptor from a DataObject. This is required because property descriptors are defined in ECMAScript using objects.
func (*DataObject) ToString ¶
func (o *DataObject) ToString() String
ToString tries to convert the object into a string. It would look into toString method or the valueOf attribute. See the spec.
type ECMAObject ¶
type Number ¶
type Number float64
func (Number) ToBool ¶
ToBool returns a Boolean according to: https://es5.github.io/#x9.2
func (Number) ToNumber ¶
ToNumber retrieves the number. https://es5.github.io/#x9.3
func (Number) ToString ¶
ToString converts the number to string. Check https://es5.github.io/#x9.8 TODO(i4k): revisit this.
type Object ¶
type Object interface { ECMAObject Class() string String() string // contains filtered or unexported methods }
Object is everything that's not a primitive value.
type PropertyDescriptor ¶
type PropertyDescriptor struct {
// contains filtered or unexported fields
}
PropertyDescriptor describes an Object property. An Object is a collection of properties and each property is either a `Named Data Property`, a `Named Acessor Property` or an internal property. PropertyDescriptor describes all of them, why? By ECMA 8.6, the property type should be interpreted by their attributes set (see IsAcessorDescriptor in 8.10.1 and IsDataDescriptor in 8.10.2). A Named Data Property associates a name with an ECMAScript value. Eg.:
this.name = "value";
The code above is the same as:
Object.defineOwnProperty(this.name, { value: "value", writable: true, enumerable: true, configurable: true });
func DefaultAcessorPropDesc ¶
func DefaultAcessorPropDesc() *PropertyDescriptor
func DefaultDataPropDesc ¶
func DefaultDataPropDesc() *PropertyDescriptor
func DefaultPrototypeDesc ¶
func DefaultPrototypeDesc() *PropertyDescriptor
DefaultPrototypeDesc is a base prototype object that extends Null. The root of the prototype-based type hierarchy.
func NewAcessorPropDesc ¶
func NewAcessorPropDesc(get, set Value, enum, cfg bool) *PropertyDescriptor
NewAcessorPropDesc creates a new Acessor Property Descriptor. https://es5.github.io/#x8.10.1
func NewDataPropDesc ¶
func NewDataPropDesc(value Value, wrt, enum, cfg bool) *PropertyDescriptor
NewDataPropDesc creates a new Data Property Descriptor. https://es5.github.io/#x8.10.2
func NewGenericPropDesc ¶
func NewGenericPropDesc() *PropertyDescriptor
NewGenericPropDesc creates a new generic (empty) property descriptor. https://es5.github.io/#x8.10.3
func (*PropertyDescriptor) Cfg ¶
func (p *PropertyDescriptor) Cfg() Value
Cfg returns the [[configurable]] property
func (*PropertyDescriptor) Enum ¶
func (p *PropertyDescriptor) Enum() Value
Enum returns the [[enumerable]] property
func (*PropertyDescriptor) Get ¶
func (p *PropertyDescriptor) Get() Value
Get returns the [[get]] property
func (*PropertyDescriptor) HasCfg ¶
func (p *PropertyDescriptor) HasCfg() bool
HasCfg tells if the property has the 'configurable' property.
func (*PropertyDescriptor) HasEnum ¶
func (p *PropertyDescriptor) HasEnum() bool
HasEnum tells if the property has the 'enumerable' property.
func (*PropertyDescriptor) HasGet ¶
func (p *PropertyDescriptor) HasGet() bool
HasGet tells if the property has the 'get' property.
func (*PropertyDescriptor) HasSet ¶
func (p *PropertyDescriptor) HasSet() bool
HasSet tells if the property has the 'set' property.
func (*PropertyDescriptor) HasValue ¶
func (p *PropertyDescriptor) HasValue() bool
HasValue tells if property has the 'value' attribute.
func (*PropertyDescriptor) HasWritable ¶
func (p *PropertyDescriptor) HasWritable() bool
HasWritable tells if the property has the 'writable' attribute.
func (*PropertyDescriptor) IsAbsentDescriptor ¶
func (p *PropertyDescriptor) IsAbsentDescriptor() bool
func (*PropertyDescriptor) IsAcessorDescriptor ¶
func (p *PropertyDescriptor) IsAcessorDescriptor() bool
func (*PropertyDescriptor) IsDataDescriptor ¶
func (p *PropertyDescriptor) IsDataDescriptor() bool
func (*PropertyDescriptor) IsGenericDescriptor ¶
func (p *PropertyDescriptor) IsGenericDescriptor() bool
IsGenericDescriptor tells if the property is a 'generic descriptor'. Generic descriptor is a descriptor that's not an Acessor Descriptor neither a Data Descriptor.
func (*PropertyDescriptor) Set ¶
func (p *PropertyDescriptor) Set() Value
Set returns the [[set]] property
func (*PropertyDescriptor) SetCfg ¶
func (p *PropertyDescriptor) SetCfg(b Bool)
func (*PropertyDescriptor) SetEnum ¶
func (p *PropertyDescriptor) SetEnum(b Bool)
func (*PropertyDescriptor) SetGet ¶
func (p *PropertyDescriptor) SetGet(get Value)
func (*PropertyDescriptor) SetSet ¶
func (p *PropertyDescriptor) SetSet(set Value)
func (*PropertyDescriptor) SetValue ¶
func (p *PropertyDescriptor) SetValue(v Value)
func (*PropertyDescriptor) SetWritable ¶
func (p *PropertyDescriptor) SetWritable(b Bool)
func (*PropertyDescriptor) ToObject ¶
func (p *PropertyDescriptor) ToObject() *DataObject
func (*PropertyDescriptor) Value ¶
func (p *PropertyDescriptor) Value() Value
Value returns the [[value]] property
func (*PropertyDescriptor) Writable ¶
func (p *PropertyDescriptor) Writable() Value
Writable returns the [[writable]] property
type String ¶
String is the primitive string UTF16-encoded type.
type TypeError ¶
type TypeError struct {
// contains filtered or unexported fields
}
func NewTypeError ¶
type UserFunction ¶
type UserFunction struct { *DataObject // contains filtered or unexported fields }
UserFunction is functions defined by user, ie. they are defined in ecmascript code.
func NewUserFunction ¶
func NewUserFunctionPrototype ¶
func NewUserFunctionPrototype() *UserFunction
type Value ¶
type Value interface { Kind() Kind IsTrue() bool IsFalse() bool ToPrimitive(hint Kind) (Value, error) ToBool() Bool ToNumber() Number ToString() String ToObject() (Object, error) }
Value is a heavy interface. In JS type coercion is crazy... almost everything could be coerced to something else. Then, better to encapsulate the question regarding what a value can be in the same interface than dealing with concrete types every time. Every type implements the Value interface. It seems to be the recomended approach: http://es5.github.io/#x9