Documentation ¶
Overview ¶
Package lang contains all ECMAScript-specified language values, i.e. String, Undefined, Null, Symbol etc., as well as Object and some types needed for internal implementation of their behaviours. These additional types are Record, StringAndSymbol (not exhaustive).
The interface Value defined by this package describes any ECMAScript language value (it is referenced as such by the specification) and describes a value that can be accessed and manipulated by ECMAScript code. Since the specification also uses Undefined in some cases for other than ECMAScript language values, this package also declares the interface InternalValue, which represents any value referenced in the specification.
Sometimes, something different than an InternalValue (e.g. a pointer) is used. This often happens, when the language specification states that the object is either provided or is Null. In this case, nil represents the case that the value is Null, and a pointer to an object or property (etc.) represents the case that the value is present.
When using Boolean values, you must not use Boolean(true) to create a Boolean that represents the value True (although this currently would work). Instead, use the provided constants True and False.
You cannot use the type StringOrSymbol as a replacement for a String or Symbol object. Only use a StringOrSymbol object when necessary. The long time goal is, to eliminate the type StringOrSymbol, as it is not a nice solution, but at this point necessary to follow the specification as exactly as possible in many other points.
As for symbols, you should not define new Symbols if not absolutely necessary. This package already defines all symbols necessary to follow the specification.
If you require a bool value, but a function of this package returns a Boolean object, there most likely exists an identical function with an Internal prefix (e.g. SameValue(a, b) Boolean and InternalSameValue(a, b) bool). Use the Internal function instead, since most of the time, the non-internal function uses the return value of the internal function and converts the type to a Boolean object.
Index ¶
- Constants
- Variables
- func CopyDataProperties()
- func CreateArrayFromList(elements []Value)
- func CreateListFromArrayLike(o *Object, elementTypes []Type)
- func EnsureTypeOneOf(arg Value, ts ...Type)
- func EnumerableOwnPropertyNames()
- func InternalIsArray(arg Value) bool
- func InternalIsCallable(arg Value) bool
- func InternalIsConstructor(arg Value) bool
- func InternalIsExtensible(o *Object) bool
- func InternalIsInteger(arg Value) bool
- func InternalIsPropertyKey(arg Value) bool
- func InternalIsRegExp(arg Value) bool
- func InternalIsStringPrefix(p, q String) bool
- func InternalSameValue(x, y Value) bool
- func InternalSameValueNonNumber(x, y Value) bool
- func InternalSameValueZero(x, y Value) bool
- func SpeciesConstructor()
- func StringsEqual(s1, s2 String) bool
- func TypeIsOneOf(arg Value, ts ...Type) bool
- type Boolean
- func CreateDataProperty(o *Object, p StringOrSymbol, v Value) Boolean
- func CreateDataPropertyOrThrow(o *Object, p StringOrSymbol, v Value) (Boolean, errors.Error)
- func CreateMethodProperty(o *Object, p StringOrSymbol, v Value) Boolean
- func DefinePropertyOrThrow(o *Object, p StringOrSymbol, desc *Property) (Boolean, errors.Error)
- func DeletePropertyOrThrow(o *Object, p StringOrSymbol) (Boolean, errors.Error)
- func HasOwnProperty(o *Object, p StringOrSymbol) Boolean
- func HasProperty(o *Object, p StringOrSymbol) Boolean
- func IsArray(arg Value) Boolean
- func IsCallable(arg Value) Boolean
- func IsConstructor(arg Value) Boolean
- func IsExtensible(o *Object) Boolean
- func IsInteger(arg Value) Boolean
- func IsPropertyKey(arg Value) Boolean
- func IsRegExp(arg Value) Boolean
- func IsStringPrefix(p, q String) Boolean
- func OrdinaryHasInstance(c, o *Object) Boolean
- func SameValue(x, y Value) Boolean
- func SameValueNonNumber(x, y Value) Boolean
- func SameValueZero(x, y Value) Boolean
- func Set(o *Object, p StringOrSymbol, v Value, throw bool) (Boolean, errors.Error)
- func SetIntegrityLevel(o *Object, level string) (Boolean, errors.Error)
- func TestIntegrityLevel(o *Object, level string) Boolean
- func ToBoolean(arg Value) Boolean
- type ConstructorKind
- type FunctionKind
- type FunctionMode
- type InternalValue
- type NativeFunction
- type Number
- func CanonicalNumericIndexString(arg Value) Number
- func NewNumber(x float64) Number
- func ToIndex(arg Value) Number
- func ToInt16(arg Value) (Number, errors.Error)
- func ToInt32(arg Value) (Number, errors.Error)
- func ToInt8(arg Value) (Number, errors.Error)
- func ToInteger(arg Value) (Number, errors.Error)
- func ToLength(arg Value) Number
- func ToNumber(arg Value) (Number, errors.Error)
- func ToUint16(arg Value) (Number, errors.Error)
- func ToUint32(arg Value) (Number, errors.Error)
- func ToUint8(arg Value) (Number, errors.Error)
- func ToUint8Clamp(arg Value) (Number, errors.Error)
- type Object
- func (o *Object) DefineOwnProperty(p StringOrSymbol, desc *Property) Boolean
- func (o *Object) Delete(p StringOrSymbol) Boolean
- func (o *Object) Get(p StringOrSymbol, receiver Value) (Value, errors.Error)
- func (o *Object) GetOwnProperty(p StringOrSymbol) *Property
- func (o *Object) GetPrototypeOf() Value
- func (o *Object) HasProperty(p StringOrSymbol) Boolean
- func (o *Object) IsCompatiblePropertyDescriptor(extensible bool, desc, current *Property) Boolean
- func (o *Object) IsExtensible() Boolean
- func (o *Object) OrdinaryDefineOwnProperty(p StringOrSymbol, desc *Property) Boolean
- func (o *Object) OrdinaryDelete(p StringOrSymbol) Boolean
- func (o *Object) OrdinaryGet(p StringOrSymbol, receiver Value) (Value, errors.Error)
- func (o *Object) OrdinaryGetOwnProperty(p StringOrSymbol) *Property
- func (o *Object) OrdinaryGetPrototypeOf() Value
- func (o *Object) OrdinaryHasProperty(p StringOrSymbol) Boolean
- func (o *Object) OrdinaryIsExtensible() Boolean
- func (o *Object) OrdinaryOwnPropertyKeys() []StringOrSymbol
- func (o *Object) OrdinaryPreventExtensions() Boolean
- func (o *Object) OrdinarySet(p StringOrSymbol, v, receiver Value) (Boolean, errors.Error)
- func (o *Object) OrdinarySetPrototypeOf(v Value) Boolean
- func (o *Object) OrdinarySetWithOwnDescriptor(p StringOrSymbol, v, receiver Value, ownDesc *Property) (Boolean, errors.Error)
- func (o *Object) OwnPropertyKeys() []StringOrSymbol
- func (o *Object) PreventExtensions() Boolean
- func (o *Object) Set(p StringOrSymbol, v, receiver Value) (Boolean, errors.Error)
- func (o *Object) SetPrototypeOf(v Value) Boolean
- func (o *Object) Type() Type
- func (o *Object) ValidateAndApplyPropertyDescriptor(p StringOrSymbol, extensible bool, desc, current *Property) Boolean
- func (o *Object) Value() interface{}
- type Property
- func CompletePropertyDescriptor(desc *Property) *Property
- func NewAccessorProperty(get, set *Object, enumerable, configurable Boolean) *Property
- func NewDataProperty(value Value, writable, enumerable, configurable Boolean) *Property
- func NewProperty() *Property
- func NewPropertyBase(enumerable, configurable Boolean) *Property
- func ToPropertyDescriptor(obj *Object) *Property
- func (p *Property) Configurable() Boolean
- func (p *Property) Enumerable() Boolean
- func (p *Property) Get() Value
- func (p *Property) IsAccessorDescriptor() Boolean
- func (p *Property) IsDataDescriptor() Boolean
- func (p *Property) IsGenericDescriptor() Boolean
- func (p *Property) Set() Value
- func (p *Property) Value() Value
- func (p *Property) Writable() Boolean
- type Record
- type String
- type StringOrSymbol
- type Symbol
- type Type
- type Value
- func Call(f *Object, thisValue Value, args ...Value) (Value, errors.Error)
- func GetMethod(v Value, p StringOrSymbol) (Value, errors.Error)
- func GetV(v Value, p StringOrSymbol) (Value, errors.Error)
- func Invoke(v Value, p StringOrSymbol, args ...Value) (Value, errors.Error)
- func OrdinaryToPrimitive(o *Object, hint string) (Value, errors.Error)
- func RequireObjectCoercible(arg Value) (Value, errors.Error)
- func ToPrimitive(input Value, preferredType interface{}) (Value, errors.Error)
Constants ¶
const ( IntegrityLevelSealed = "sealed" IntegrityLevelFrozen = "frozen" )
Integrity levels as specified in 7.3.14 in the specification.
const ( FieldNameValue = "Value" FieldNameWritable = "Writable" FieldNameGet = "Get" FieldNameSet = "Set" FieldNameEnumerable = "Enumerable" FieldNameConfigurable = "Configurable" )
Available field names for a property.
A property is a data property descriptor if the fields 'Value', 'Writable' are set.
A property is an accessor property descriptor if the fields 'Get', 'Set' are set.
Every property must have the fields 'Enumerable', 'Configurable' set.
const ( True = Boolean(true) False = Boolean(false) )
Available Boolean values
const (
// Null represents the Null value as specified by the language spec
Null = valueNull(0)
)
const (
// Undefined represents the Undefined value as specified by the language spec.
Undefined = valueUndefined(0)
)
Variables ¶
var ( // NaN as specified by the language spec. NaN = NewNumber(math.NaN()) // PosInfinity as specified by the language spec. PosInfinity = NewNumber(math.Inf(+1)) // NegInfinity as specified by the language spec. NegInfinity = NewNumber(math.Inf(-1)) // Infinity as specified by the language spec. // This is an alias for PosInfinity. Infinity = PosInfinity // PosZero as specified by the language spec. PosZero = NewNumber(+0) // NegZero as specified by the language spec. NegZero = NewNumber(neg(0)) // Zero as specified by the language spec. // This is an alias for PosZero. Zero = PosZero )
var ( SymbolAsyncIterator = &Symbol{NewString("Symbol.asyncIterator")} SymbolHasInstance = &Symbol{NewString("Symbol.hasInstance")} SymbolIsConcatSpreadable = &Symbol{NewString("Symbol.isConcatSpreadable")} SymbolIterator = &Symbol{NewString("Symbol.iterator")} SymbolMatch = &Symbol{NewString("Symbol.match")} SymbolReplace = &Symbol{NewString("Symbol.replace")} SymbolSearch = &Symbol{NewString("Symbol.search")} SymbolSpecies = &Symbol{NewString("Symbol.species")} SymbolSplit = &Symbol{NewString("Symbol.split")} SymbolToPrimitive = &Symbol{NewString("Symbol.toPrimitive")} SymbolToStringTag = &Symbol{NewString("Symbol.toStringTag")} SymbolUnscopables = &Symbol{NewString("Symbol.unscopables")} )
Well-known symbol descriptions as specified in 6.1.5.1.
Functions ¶
func CreateArrayFromList ¶
func CreateArrayFromList(elements []Value)
CreateArrayFromList creates an array whose elements are provided by a List. CreateArrayFromList is specified in 7.3.16.
func CreateListFromArrayLike ¶
CreateListFromArrayLike creates a List value whose elements are provided by the indexed properties of an array-like object. CreateListFromArrayLike is specified in 7.3.17.
func EnsureTypeOneOf ¶
EnsureTypeOneOf panics, if the type of the given value is not one of the given ECMALanguage data types.
func EnumerableOwnPropertyNames ¶
func EnumerableOwnPropertyNames()
EnumerableOwnPropertyNames is specified in 7.3.21.
func InternalIsArray ¶
InternalIsArray is used to determine whether the given value is an array.
func InternalIsCallable ¶
InternalIsCallable is used to determine whether the value has a Call internal method. If this function returns true, the value can be used as an argument to the function Call.
func InternalIsConstructor ¶
InternalIsConstructor is used to determine whether the value has a Construct internal method.
func InternalIsExtensible ¶
InternalIsExtensible is used to determine whether the object is extensible, meaning if new properties can be added.
func InternalIsInteger ¶
InternalIsInteger is used to determine whether the value is an integer.
func InternalIsPropertyKey ¶
InternalIsPropertyKey is used to determine whether the type of the value is String or Symbol.
func InternalIsRegExp ¶
InternalIsRegExp is used to determine whether the value has a @@match property, or, if not, if it has a RegExpMatcher internal slot.
func InternalIsStringPrefix ¶
InternalIsStringPrefix is used to determine whether p is a prefix of q or not.
func InternalSameValue ¶
InternalSameValue is used to determine, whether x and y have the same value.
func InternalSameValueNonNumber ¶
InternalSameValueNonNumber is used to determine, whether x and y have the same value, assuming their type is not Number.
func InternalSameValueZero ¶
InternalSameValueZero is used to determine, whether x and y have the same value. The difference to InternalSameValue is, that here, +0 == -0.
func SpeciesConstructor ¶
func SpeciesConstructor()
SpeciesConstructor retrieves the constructor that should be used to create new objects that are derived from the argument object o. The defaultConstructor argument is the constructor to use if a constructor's @@species property cannot be found starting from o. SpeciesConstructor is specified in 7.3.20.
func StringsEqual ¶
StringsEqual can be used to determine the equality of two strings. This function compares two given strings to be equalcodepoint by codepoint.
func TypeIsOneOf ¶
TypeIsOneOf is used to determine whether the type of the given value is one of the given ECMALanguage data types.
Types ¶
type Boolean ¶
type Boolean bool
Boolean is a language type as specified by the language spec. Predefined and ready to use values are lang.True and lang.False.
func CreateDataProperty ¶
func CreateDataProperty(o *Object, p StringOrSymbol, v Value) Boolean
CreateDataProperty creates a new own property of an object. CreateDataProperty is specified in 7.3.4.
func CreateDataPropertyOrThrow ¶
CreateDataPropertyOrThrow creates a new own property of an object. It returnes a TypeError exception if the requested property update cannot be performed. CreateDataPropertyOrThrow is specified in 7.3.6.
func CreateMethodProperty ¶
func CreateMethodProperty(o *Object, p StringOrSymbol, v Value) Boolean
CreateMethodProperty creates a new own property of an object. CreateMethodProperty is specified in 7.3.5.
func DefinePropertyOrThrow ¶
DefinePropertyOrThrow is used to call the DefineOwnProperty internal method of an object. If the requested property update cannot be performed, a TypeError is returned. DefinePropertyOrThrow is specified in 7.3.7.
func DeletePropertyOrThrow ¶
func DeletePropertyOrThrow(o *Object, p StringOrSymbol) (Boolean, errors.Error)
DeletePropertyOrThrow removes a specific own property of an object. If the property is not configurable, an exception is returned. DeletePropertyOrThrow is specified in 7.3.8.
func HasOwnProperty ¶
func HasOwnProperty(o *Object, p StringOrSymbol) Boolean
HasOwnProperty is used to determine whether an object has a property with the specified property key. The property can only be an own property of the object. HasProperty is specified in 7.3.11.
func HasProperty ¶
func HasProperty(o *Object, p StringOrSymbol) Boolean
HasProperty is used to determine whether an object has a property with the specified property key. The property can either be inherited or an own property of the object. HasProperty is specified in 7.3.10.
func IsArray ¶
IsArray is used to determine whether the given value is an array. To obtain a bool value, use InternalIsArray instead. IsArray is specified in 7.2.2.
func IsCallable ¶
IsCallable is used to determine whether the value has a Call internal method. If this function returns True, the value can be used as an argument to the function Call. To obtain a bool value, use InternalIsCallable instead. IsCallable is specified in 7.2.3.
func IsConstructor ¶
IsConstructor is used to determine whether the value has a Construct internal method. To obtain a bool value, use InternalIsConstructor instead. IsConstructor is specified in 7.2.3.
func IsExtensible ¶
IsExtensible is used to determine whether the object is extensible, meaning if new properties can be added. IsExtensible is specified in 7.2.5.
func IsInteger ¶
IsInteger is used to determine whether the value is an integer. To obtain a bool value, use InternalIsInteger instead. IsInteger is specified in 7.2.6.
func IsPropertyKey ¶
IsPropertyKey is used to determine whether the type of the value is String or Symbol. To obtain a bool value, use InternalIsPropertyKey instead. IsPropertyKey is specified in 7.2.7.
func IsRegExp ¶
IsRegExp is used to determine whether the value has a @@match property, or, if not, if it has a RegExpMatcher internal slot. To obtain a bool value, use InternalIsRegExp instead. IsRegExp is specified in 7.2.8.
func IsStringPrefix ¶
IsStringPrefix is used to determine whether p is a prefix of q or not. To obtain a bool value, use InternalIsStringPrefix instead. IsStringPrefix is specified in 7.2.9.
func OrdinaryHasInstance ¶
OrdinaryHasInstance implements the default algorithm for determining if an object o inherits from the instance object inheritance path provided by constructor c. OrdinaryHasInstance is specified in 7.3.19.
func SameValue ¶
SameValue is used to determine, whether x and y have the same value. To obtain a bool value, use InternalSameValue instead. SameValue is specified in 7.2.10.
func SameValueNonNumber ¶
SameValueNonNumber is used to determine, whether x and y have the same value, assuming their type is not Number. To obtain a bool value, use InternalSameValueNonNumber instead. SameValueNonNumber is specified in 7.2.12.
func SameValueZero ¶
SameValueZero is used to determine, whether x and y have the same value. The difference to SameValue is, that here, +0 == -0. To obtain a bool value, use InternalSameValueZero instead. SameValueZero is specified in 7.2.11.
func Set ¶
Set is used to set the value of a specific property of an object. If throw == true and the property cannot be set, a TypeError will be returned which then must be thrown. Set is specified in 7.3.3.
func SetIntegrityLevel ¶
SetIntegrityLevel is used to fix the set of own properties of an object. SetIntegrityLevel is specified in 7.3.14.
func TestIntegrityLevel ¶
TestIntegrityLevel is used to determine if the set of own properties of an object are fixed. TestIntegrityLevel is specified in 7.3.15.
type ConstructorKind ¶
type ConstructorKind uint8
ConstructorKind is the kind of a constructor function, as specified in 9.2, Table 27.
const ( ConstructorKindUnknown ConstructorKind = iota ConstructorKindBase ConstructorKindDerived )
Constructor kinds as defined in 9.2, Table 27.
type FunctionKind ¶
type FunctionKind uint8
FunctionKind is the kind of a function, as specified in 9.2, Table 27.
const ( FunctionKindUnknown FunctionKind = iota FunctionKindNormal FunctionKindClassGenerator FunctionKindGenerator FunctionKindAsync )
Function kinds as defined in 9.2, Table 27.
type FunctionMode ¶
type FunctionMode uint8
FunctionMode represents the ThisMode of a function. The ThisMode defines how this references are interpreted within the formal parameters and code body of the function. lexical means that this refers to the this value of a lexically enclosing function. strict means that the this value is used exactly as provided by an invocation of the function. global means that a this value of undefined is interpreted as a reference to the global object.
const ( FunctionModeUnknown FunctionMode = iota FunctionModeLexical FunctionModeStrict FunctionModeGlobal )
Function modes as defined in 9.2, Table 27.
type InternalValue ¶
type InternalValue interface { Value }
InternalValue represents any value used in the specification. This interface was introduced because the specification also uses values like Null and Undefined for non language values like Environments or Properties. Objects that implement this interface must implement a Type method that returns TypeInternal.
func Get ¶
func Get(o *Object, p StringOrSymbol) (InternalValue, errors.Error)
Get retrieves the value of a specific property of an object. Get is specified in 7.3.1.
type NativeFunction ¶
NativeFunction is a type alias for Go functions that represent an ECMAScript function algorithm. It takes a 'this' value, which will be interpreted as the receiver, and zero or more arguments.
A function can return one argument, which may be Null or Undefined, and an error. If an error is returned, the function call is interpreted as a function call with abnormal completion, and the returned error will be interpreted as a thrown error. The runtime must handle this correctly.
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
Number is a language type as specified by the language spec.
func CanonicalNumericIndexString ¶
CanonicalNumericIndexString returns argument converted to a numeric value if it is a String representation of a Number that would be produced by ToString, or the string "-0". Otherwise, it returns Undefined. CanonicalNumericIndexString is specified in 7.1.16.
func NewNumber ¶
NewNumber generates a number language Value from a float64. If the given float64 value is not a number (NaN), the returned Number will represent the NaN value as specified by the language spec.
func ToIndex ¶
ToIndex returns value argument converted to a numeric value if it is a valid integer index value. ToIndex is specified in 7.1.17.
func ToInt16 ¶
ToInt16 converts the argument to an int16 Number value. ToInt16 is specified in 7.1.7.
func ToInt32 ¶
ToInt32 converts the argument to an int32 Number value. ToInt32 is specified in 7.1.5.
func ToInteger ¶
ToInteger converts the argument to an integer Number value. ToInteger is specified in 7.1.4.
func ToLength ¶
ToLength converts argument to an integer suitable for use as the length of an array-like object. ToLength is specified in 7.1.15.
func ToUint16 ¶
ToUint16 converts the argument to an uint16 Number value. ToUint16 is specified in 7.1.8.
func ToUint32 ¶
ToUint32 converts the argument to an uint32 Number value. ToUint32 is specified in 7.1.6.
func ToUint8 ¶
ToUint8 converts the argument to an uint8 Number value. ToUint8 is specified in 7.1.10.
func ToUint8Clamp ¶
ToUint8Clamp converts the argument to one of 28 integer values in the range 0 through 255, inclusive. ToUint8Clamp is specified in 7.1.11.
type Object ¶
type Object struct { Prototype Value // *Object or Null Extensible bool // Function Object Environment InternalValue FormalParameters interface{} FunctionKind FunctionKind ConstructorKind ConstructorKind Realm InternalValue ScriptOrModule interface{} ThisMode FunctionMode Strict bool HomeObject *Object // Call is the Call function of an object as (kind of) specified by the // language spec. This is only not nil for function and constructor function // objects. Call NativeFunction // Construct is the Construct function of an obejct as (kind of) specified // by the language spec. This is only not nil for constructor function // objects. Construct func(*Object, ...Value) (*Object, errors.Error) // contains filtered or unexported fields }
Object is a language type as specified by the language spec.
func Construct ¶
Construct is used to call the Construct internal method of a constructor object. Construct is specified in 7.3.13.
func FromPropertyDescriptor ¶
FromPropertyDescriptor TODO:
func ObjectCreate ¶
func ObjectCreate(proto Value, internalSlotsList ...StringOrSymbol) *Object
ObjectCreate creates a new ordinary object at runtime, where proto is the given prototype (must be an Object or Null), and internalSlotsList is a list of the names of additional internal slots that must be defined as part of the object. If none are provided, an empty list is used. ObjectCreate is specified in 9.1.12.
func (*Object) DefineOwnProperty ¶
func (o *Object) DefineOwnProperty(p StringOrSymbol, desc *Property) Boolean
DefineOwnProperty delegates to OrdinaryDefineOwnProperty. DefineOwnProperty is specified in 9.1.6.
func (*Object) Delete ¶
func (o *Object) Delete(p StringOrSymbol) Boolean
Delete delegates to OrdinaryDelete. Delete is specified in 9.1.10.
func (*Object) GetOwnProperty ¶
func (o *Object) GetOwnProperty(p StringOrSymbol) *Property
GetOwnProperty delegates to OrdinaryGetOwnProperty. GetOwnProperty is specified in 9.1.5.
func (*Object) GetPrototypeOf ¶
GetPrototypeOf delegates to OrdinaryGetPrototypeOf. GetPrototypeOf is specified in 9.1.1.
func (*Object) HasProperty ¶
func (o *Object) HasProperty(p StringOrSymbol) Boolean
HasProperty delegates to OrdinaryHasProperty. HasProperty is specified in 9.1.7.
func (*Object) IsCompatiblePropertyDescriptor ¶
IsCompatiblePropertyDescriptor delegates to ValidateAndApplyPropertyDescriptor on a nil Object and a zero StringOrSymbol. This resembles the behaviour of the object and the property key being Undefined. IsCompatiblePropertyDescriptor is specified in 9.1.6.2.
func (*Object) IsExtensible ¶
IsExtensible delegates to OrdinaryIsExtensible. IsExtensible is specified in 9.1.3.
func (*Object) OrdinaryDefineOwnProperty ¶
func (o *Object) OrdinaryDefineOwnProperty(p StringOrSymbol, desc *Property) Boolean
OrdinaryDefineOwnProperty is used to define an own property of the object. OrdinaryDefineOwnProperty is specified in 9.1.6.1.
func (*Object) OrdinaryDelete ¶
func (o *Object) OrdinaryDelete(p StringOrSymbol) Boolean
OrdinaryDelete removes a property with the name p from the object. OrdinaryDelete is specified in 9.1.10.1.
func (*Object) OrdinaryGet ¶
OrdinaryGet returns the value of the property with the given name. If the property is an own property of this object, its value is returned. If this object does not have a property with the given name, its prototype chain will be checked.
If the found property is a data property descriptor, its value is returned.
If the found property is an accessor property descriptor, the value returned by its [Get] method is returned.
If no property with the given name could be found, Undefined is returned.
func (*Object) OrdinaryGetOwnProperty ¶
func (o *Object) OrdinaryGetOwnProperty(p StringOrSymbol) *Property
OrdinaryGetOwnProperty returns a property with the given key of this object. Where Undefined in the specification is used to indicate no result, here, a nil pointer is used. OrdinaryGetOwnProperty is specified in 9.1.5.1.
func (*Object) OrdinaryGetPrototypeOf ¶
OrdinaryGetPrototypeOf returns the prototype of the object, either an Object or Null. OrdinaryGetPrototypeOf is specified in 9.1.1.1.
func (*Object) OrdinaryHasProperty ¶
func (o *Object) OrdinaryHasProperty(p StringOrSymbol) Boolean
OrdinaryHasProperty is used to determine whether an object or any object in its prototype chain has a property with the given name. OrdinaryHasProperty is specified in 9.1.7.1.
func (*Object) OrdinaryIsExtensible ¶
OrdinaryIsExtensible is used to determine whether the object is extensible. OrdinaryIsExtensible is specified in 9.1.3.1.
func (*Object) OrdinaryOwnPropertyKeys ¶
func (o *Object) OrdinaryOwnPropertyKeys() []StringOrSymbol
OrdinaryOwnPropertyKeys returns a list of names of the properties of this object. That is, given an object with the properties 'A', 'B', and 'C', OrdinaryOwnPropertyKeys will return ['A', 'B', 'C'].
TODO: add comment on ordering and grouping of property names
OrdinaryOwnPropertyKeys is specified in 9.1.11.1.
func (*Object) OrdinaryPreventExtensions ¶
OrdinaryPreventExtensions makes the object non-extensible. After a call to this method, IsExtensible and OrdinaryIsExtensible calls to the object will always return false. OrdinaryPreventExtensions is specified in 9.1.4.1.
func (*Object) OrdinarySet ¶
OrdinarySet is a wrapper around OrdinarySetWithOwnDescriptor, which will resolve p to an own property of the object. OrdinarySet is specified in 9.1.9.1.
func (*Object) OrdinarySetPrototypeOf ¶
OrdinarySetPrototypeOf sets the prototype of the object. The given prototype value can either be an Object or Null. OrdinarySetPrototypeOf is specified in 9.1.2.1.
func (*Object) OrdinarySetWithOwnDescriptor ¶
func (o *Object) OrdinarySetWithOwnDescriptor(p StringOrSymbol, v, receiver Value, ownDesc *Property) (Boolean, errors.Error)
OrdinarySetWithOwnDescriptor is pretty complicated and should be simplified and/or refactored into multiple sub-functions (TODO:). OrdinarySetWithOwnDescriptor is specified in 9.1.9.2.
func (*Object) OwnPropertyKeys ¶
func (o *Object) OwnPropertyKeys() []StringOrSymbol
OwnPropertyKeys delegates to OrdinaryOwnPropertyKeys. OwnPropertyKeys is specified in 9.1.11.
func (*Object) PreventExtensions ¶
PreventExtensions delegates to OrdinaryPreventExtensions. PreventExtensions is specified in 9.1.4.
func (*Object) SetPrototypeOf ¶
SetPrototypeOf delegates to OrdinarySetPrototypeOf. SetPrototypeOf is specified in 9.1.2.
func (*Object) ValidateAndApplyPropertyDescriptor ¶
func (o *Object) ValidateAndApplyPropertyDescriptor(p StringOrSymbol, extensible bool, desc, current *Property) Boolean
ValidateAndApplyPropertyDescriptor is pretty complicated and should be simplified and/or refactored into multiple sub-functions (TODO:). ValidateAndApplyPropertyDescriptor is specified in 9.1.6.3.
type Property ¶
type Property struct {
*Record
}
Property describes a property descriptor that holds 4 fields, ['Value', 'Writable', 'Enumerable', 'Configurable'] or ['Get', 'Set', 'Enumerable', 'Configurable'].
func CompletePropertyDescriptor ¶
CompletePropertyDescriptor TODO:
func NewAccessorProperty ¶
NewAccessorProperty creates a new property that is an accessor property descriptor. The fields 'Get', 'Set', 'Enumerable', 'Configurable' are set.
func NewDataProperty ¶
NewDataProperty creates a new property that is a data property descriptor. The fields 'Value', 'Writable', 'Enumerable', 'Configurable' are set.
func NewProperty ¶
func NewProperty() *Property
NewProperty creates a new, completely empty property record. The fields 'Value', 'Writable', 'Get', 'Set', 'Enumerable', 'Configurable' are NOT set yet.
func NewPropertyBase ¶
NewPropertyBase creates a new property base that is neither a data nor an accessor property. Only the fields 'Enumerable', 'Configurable' are set. A property created by this function is not bound to be a data or an accessor property. It can become either by adding the respective fields to the record.
func ToPropertyDescriptor ¶
ToPropertyDescriptor TODO:
func (*Property) Configurable ¶
Configurable returns the value of the field 'Configurable', or False if the field is not set.
func (*Property) Enumerable ¶
Enumerable returns the value of the field 'Enumerable', or False if the field is not set.
func (*Property) IsAccessorDescriptor ¶
IsAccessorDescriptor determines whether the property is an accessor property descriptor. This is the case if the fields 'Get', 'Set' of the property are set.
func (*Property) IsDataDescriptor ¶
IsDataDescriptor determines whether the property is an data property descriptor. This is the case if the fields 'Value', 'Writable' of the property are set.
func (*Property) IsGenericDescriptor ¶
IsGenericDescriptor determines whether the property is a generic property descriptor. This is the case if the property is neither an accessor property descriptor nor a data property descriptor.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is an object that holds fields. The type of the fields as well as the name of such fields are not specified by the record, but by the entity that is using the record.
func (*Record) GetField ¶
GetField returns the value of the field associated with the given name, and a flag indicating whether such a field is held by the record.
type String ¶
type String []uint16
String is a language type as specified by the language spec. All codepoints are UTF-16 codepoints and will be handled as such.
func NewString ¶
NewString creates a new String from a given string. The given string will be encoded to UTF-16 and will be returned as a lang.String.
func NumberToString ¶
NumberToString converts the given Number to a String. NumberToString is specified in 7.1.12.1.
type StringOrSymbol ¶
type StringOrSymbol struct {
// contains filtered or unexported fields
}
StringOrSymbol is a wrapper around either a lang.String or a lang.Symbol. Upon creation with lang.NewStringOrSymbol, the passed value is checked to be a String or a Symbol. The Value methods Value() and Type() delegate to the wrapped String or Symbol.
func NewStringOrSymbol ¶
func NewStringOrSymbol(arg Value) StringOrSymbol
NewStringOrSymbol creates a new StringOrSymbol from a passed String or Symbol. This function will panic if the passed Value is not a String or a Symbol.
func ToPropertyKey ¶
func ToPropertyKey(arg Value) StringOrSymbol
ToPropertyKey converts the given argument to a StringOrSymbol. ToPropertyKey is specified in 7.1.14.
func (StringOrSymbol) String ¶
func (s StringOrSymbol) String() String
String is a convenience method to convert the lang.StringOrSymbol to a lang.String.
func (StringOrSymbol) Type ¶
func (s StringOrSymbol) Type() Type
Type returns lang.TypeString or lang.TypeSymbol, depending on the wrapped Type.
func (StringOrSymbol) Value ¶
func (s StringOrSymbol) Value() interface{}
Value will return the wrapped value's Value.
type Symbol ¶
type Symbol struct {
Description Value // either Undefined or a String
}
Symbol is a language type as specified by the language spec.
type Type ¶
type Type uint8
Type represents a language type as specified by the ECMAScript Language Types.
type Value ¶
type Value interface { // Type returns the language type of this value as specified by the language spec. Type() Type // Value returns the Go representation of this value. // For example, the Value() of a lang.Boolean should be a bool. Value() interface{} }
Value represents a language value as specified by the language spec.
func Call ¶
Call is used to call the Call internal method of a function object. Call is specified in 7.3.12.
func GetMethod ¶
func GetMethod(v Value, p StringOrSymbol) (Value, errors.Error)
GetMethod retrieves a callable object of a property of an ECMAScript language value. If no error is returned, the object is guaranteed to be callable. GetMethod is specified in 7.3.9.
func GetV ¶
func GetV(v Value, p StringOrSymbol) (Value, errors.Error)
GetV retrieves the value of a specific property of an object, assuming that the value is an ECMAScript language value. If the value is not an object, the property lookup is performed using a wrapper object appropriate for the type of the value. GetV is specified in 7.3.2.
func Invoke ¶
Invoke is used to call a method property of an ECMAScript language value. Invoke is specified in 7.3.18.
func OrdinaryToPrimitive ¶
OrdinaryToPrimitive is specified in 7.1.1.1.
func RequireObjectCoercible ¶
RequireObjectCoercible returns the value and no error if the Value is coercible, meaning that the type of the value is neither Null nor Undefined. RequireObjectCoercible is specified in 7.2.1.