lang

package
v0.0.0-...-4ed146b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 8 Imported by: 0

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

View Source
const (
	IntegrityLevelSealed = "sealed"
	IntegrityLevelFrozen = "frozen"
)

Integrity levels as specified in 7.3.14 in the specification.

View Source
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.

View Source
const (
	True  = Boolean(true)
	False = Boolean(false)
)

Available Boolean values

View Source
const (
	// Null represents the Null value as specified by the language spec
	Null = valueNull(0)
)
View Source
const (
	// Undefined represents the Undefined value as specified by the language spec.
	Undefined = valueUndefined(0)
)

Variables

View Source
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
)
View Source
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 CopyDataProperties

func CopyDataProperties()

CopyDataProperties is specified in 7.3.23.

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

func CreateListFromArrayLike(o *Object, elementTypes []Type)

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

func EnsureTypeOneOf(arg Value, ts ...Type)

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

func InternalIsArray(arg Value) bool

InternalIsArray is used to determine whether the given value is an array.

func InternalIsCallable

func InternalIsCallable(arg Value) bool

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

func InternalIsConstructor(arg Value) bool

InternalIsConstructor is used to determine whether the value has a Construct internal method.

func InternalIsExtensible

func InternalIsExtensible(o *Object) bool

InternalIsExtensible is used to determine whether the object is extensible, meaning if new properties can be added.

func InternalIsInteger

func InternalIsInteger(arg Value) bool

InternalIsInteger is used to determine whether the value is an integer.

func InternalIsPropertyKey

func InternalIsPropertyKey(arg Value) bool

InternalIsPropertyKey is used to determine whether the type of the value is String or Symbol.

func InternalIsRegExp

func InternalIsRegExp(arg Value) bool

InternalIsRegExp is used to determine whether the value has a @@match property, or, if not, if it has a RegExpMatcher internal slot.

func InternalIsStringPrefix

func InternalIsStringPrefix(p, q String) bool

InternalIsStringPrefix is used to determine whether p is a prefix of q or not.

func InternalSameValue

func InternalSameValue(x, y Value) bool

InternalSameValue is used to determine, whether x and y have the same value.

func InternalSameValueNonNumber

func InternalSameValueNonNumber(x, y Value) bool

InternalSameValueNonNumber is used to determine, whether x and y have the same value, assuming their type is not Number.

func InternalSameValueZero

func InternalSameValueZero(x, y Value) bool

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

func StringsEqual(s1, s2 String) bool

StringsEqual can be used to determine the equality of two strings. This function compares two given strings to be equalcodepoint by codepoint.

func TypeIsOneOf

func TypeIsOneOf(arg Value, ts ...Type) bool

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

func CreateDataPropertyOrThrow(o *Object, p StringOrSymbol, v Value) (Boolean, errors.Error)

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

func DefinePropertyOrThrow(o *Object, p StringOrSymbol, desc *Property) (Boolean, errors.Error)

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

func IsArray(arg Value) Boolean

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

func IsCallable(arg Value) Boolean

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

func IsConstructor(arg Value) Boolean

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

func IsExtensible(o *Object) Boolean

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

func IsInteger(arg Value) Boolean

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

func IsPropertyKey(arg Value) Boolean

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

func IsRegExp(arg Value) Boolean

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

func IsStringPrefix(p, q String) Boolean

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

func OrdinaryHasInstance(c, o *Object) Boolean

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

func SameValue(x, y Value) Boolean

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

func SameValueNonNumber(x, y Value) Boolean

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

func SameValueZero(x, y Value) Boolean

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

func Set(o *Object, p StringOrSymbol, v Value, throw bool) (Boolean, errors.Error)

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

func SetIntegrityLevel(o *Object, level string) (Boolean, errors.Error)

SetIntegrityLevel is used to fix the set of own properties of an object. SetIntegrityLevel is specified in 7.3.14.

func TestIntegrityLevel

func TestIntegrityLevel(o *Object, level string) Boolean

TestIntegrityLevel is used to determine if the set of own properties of an object are fixed. TestIntegrityLevel is specified in 7.3.15.

func ToBoolean

func ToBoolean(arg Value) Boolean

ToBoolean converts the argument to a Boolean value. ToBoolean is specified in 7.1.2.

func (Boolean) Type

func (Boolean) Type() Type

Type returns lang.TypeBoolean.

func (Boolean) Value

func (b Boolean) Value() interface{}

Value returns the Go value of this Boolean, either true or false.

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

Get retrieves the value of a specific property of an object. Get is specified in 7.3.1.

type NativeFunction

type NativeFunction func(this Value, args ...Value) (Value, errors.Error)

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

func CanonicalNumericIndexString(arg Value) Number

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

func NewNumber(x float64) Number

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

func ToIndex(arg Value) Number

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

func ToInt16(arg Value) (Number, errors.Error)

ToInt16 converts the argument to an int16 Number value. ToInt16 is specified in 7.1.7.

func ToInt32

func ToInt32(arg Value) (Number, errors.Error)

ToInt32 converts the argument to an int32 Number value. ToInt32 is specified in 7.1.5.

func ToInt8

func ToInt8(arg Value) (Number, errors.Error)

ToInt8 converts the argument to an int8 Number value. ToInt8 is specified in 7.1.9.

func ToInteger

func ToInteger(arg Value) (Number, errors.Error)

ToInteger converts the argument to an integer Number value. ToInteger is specified in 7.1.4.

func ToLength

func ToLength(arg Value) Number

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 ToNumber

func ToNumber(arg Value) (Number, errors.Error)

ToNumber converts the argument to a Number. ToNumber is specified in 7.1.3.

func ToUint16

func ToUint16(arg Value) (Number, errors.Error)

ToUint16 converts the argument to an uint16 Number value. ToUint16 is specified in 7.1.8.

func ToUint32

func ToUint32(arg Value) (Number, errors.Error)

ToUint32 converts the argument to an uint32 Number value. ToUint32 is specified in 7.1.6.

func ToUint8

func ToUint8(arg Value) (Number, errors.Error)

ToUint8 converts the argument to an uint8 Number value. ToUint8 is specified in 7.1.10.

func ToUint8Clamp

func ToUint8Clamp(arg Value) (Number, errors.Error)

ToUint8Clamp converts the argument to one of 28 integer values in the range 0 through 255, inclusive. ToUint8Clamp is specified in 7.1.11.

func (Number) String

func (n Number) String() string

func (Number) Type

func (Number) Type() Type

Type returns lang.TypeNumber.

func (Number) Value

func (n Number) Value() interface{}

Value returns the float64 value of the Number. If the Number is NaN, math.NaN() will be returned.

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

func Construct(f, newTarget *Object, args ...Value) (*Object, errors.Error)

Construct is used to call the Construct internal method of a constructor object. Construct is specified in 7.3.13.

func FromPropertyDescriptor

func FromPropertyDescriptor(desc *Property) *Object

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 ToObject

func ToObject(arg Value) *Object

ToObject converts the given argument to an Object. ToObject is specified in 7.1.13.

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) Get

func (o *Object) Get(p StringOrSymbol, receiver Value) (Value, errors.Error)

Get delegates to OrdinaryGet. Get is specified in 9.1.8.

func (*Object) GetOwnProperty

func (o *Object) GetOwnProperty(p StringOrSymbol) *Property

GetOwnProperty delegates to OrdinaryGetOwnProperty. GetOwnProperty is specified in 9.1.5.

func (*Object) GetPrototypeOf

func (o *Object) GetPrototypeOf() Value

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

func (o *Object) IsCompatiblePropertyDescriptor(extensible bool, desc, current *Property) Boolean

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

func (o *Object) IsExtensible() Boolean

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

func (o *Object) OrdinaryGet(p StringOrSymbol, receiver Value) (Value, errors.Error)

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

func (o *Object) OrdinaryGetPrototypeOf() Value

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

func (o *Object) OrdinaryIsExtensible() Boolean

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

func (o *Object) OrdinaryPreventExtensions() Boolean

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

func (o *Object) OrdinarySet(p StringOrSymbol, v, receiver Value) (Boolean, errors.Error)

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

func (o *Object) OrdinarySetPrototypeOf(v Value) Boolean

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

func (o *Object) PreventExtensions() Boolean

PreventExtensions delegates to OrdinaryPreventExtensions. PreventExtensions is specified in 9.1.4.

func (*Object) Set

func (o *Object) Set(p StringOrSymbol, v, receiver Value) (Boolean, errors.Error)

Set delegates to OrdinarySet. Set is specified in 9.1.9.

func (*Object) SetPrototypeOf

func (o *Object) SetPrototypeOf(v Value) Boolean

SetPrototypeOf delegates to OrdinarySetPrototypeOf. SetPrototypeOf is specified in 9.1.2.

func (*Object) Type

func (o *Object) Type() Type

Type returns lang.TypeObject.

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.

func (*Object) Value

func (o *Object) Value() interface{}

Value returns the object itself.

var o *Object
...
o == o.Value() // true

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

func CompletePropertyDescriptor(desc *Property) *Property

CompletePropertyDescriptor TODO:

func NewAccessorProperty

func NewAccessorProperty(get, set *Object, enumerable, configurable Boolean) *Property

NewAccessorProperty creates a new property that is an accessor property descriptor. The fields 'Get', 'Set', 'Enumerable', 'Configurable' are set.

func NewDataProperty

func NewDataProperty(value Value, writable, enumerable, configurable Boolean) *Property

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

func NewPropertyBase(enumerable, configurable Boolean) *Property

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

func ToPropertyDescriptor(obj *Object) *Property

ToPropertyDescriptor TODO:

func (*Property) Configurable

func (p *Property) Configurable() Boolean

Configurable returns the value of the field 'Configurable', or False if the field is not set.

func (*Property) Enumerable

func (p *Property) Enumerable() Boolean

Enumerable returns the value of the field 'Enumerable', or False if the field is not set.

func (*Property) Get

func (p *Property) Get() Value

Get returns the value of the field 'Get', or False if the field is not set.

func (*Property) IsAccessorDescriptor

func (p *Property) IsAccessorDescriptor() Boolean

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

func (p *Property) IsDataDescriptor() Boolean

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

func (p *Property) IsGenericDescriptor() Boolean

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.

func (*Property) Set

func (p *Property) Set() Value

Set returns the value of the field 'Set', or False if the field is not set.

func (*Property) Value

func (p *Property) Value() Value

Value returns the value of this property, or Undefined if the field 'Value' is not set.

func (*Property) Writable

func (p *Property) Writable() Boolean

Writable returns the value of the field 'Writable', or False if the field is not set.

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 NewRecord

func NewRecord() *Record

NewRecord creates a new record with no fields.

func (*Record) GetField

func (r *Record) GetField(n string) (interface{}, bool)

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.

func (*Record) SetField

func (r *Record) SetField(n string, val interface{})

SetField associates a value with a given field name. If the field already exists, it will be overwritten.

func (*Record) Type

func (r *Record) Type() Type

Type returns lang.TypeInternal.

func (*Record) Value

func (r *Record) Value() interface{}

Value returns the Record itself.

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

func NewString(str string) String

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

func NumberToString(n Number) String

NumberToString converts the given Number to a String. NumberToString is specified in 7.1.12.1.

func ToString

func ToString(arg Value) String

ToString converts the argument to a String. ToString is specified in 7.1.12.

func (String) Type

func (String) Type() Type

Type returns lang.TypeString.

func (String) Value

func (s String) Value() interface{}

Value returns a string representing the lang.String. The value of a nil String is nil.

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.

func (Symbol) String

func (s Symbol) String() String

String returns a lang.String, containing the Symbols description. If the symbol's description is not a string, this will panic.

func (Symbol) Type

func (Symbol) Type() Type

Type returns lang.TypeSymbol.

func (Symbol) Value

func (s Symbol) Value() interface{}

Value returns the Value of this symbol's description.

type Type

type Type uint8

Type represents a language type as specified by the ECMAScript Language Types.

const (
	TypeInternal Type = iota

	TypeUndefined
	TypeNull
	TypeBoolean
	TypeString
	TypeSymbol
	TypeNumber
	TypeObject
)

Language Type as specified in 6.1

func (Type) String

func (t Type) String() string

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

func Call(f *Object, thisValue Value, args ...Value) (Value, errors.Error)

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

func Invoke(v Value, p StringOrSymbol, args ...Value) (Value, errors.Error)

Invoke is used to call a method property of an ECMAScript language value. Invoke is specified in 7.3.18.

func OrdinaryToPrimitive

func OrdinaryToPrimitive(o *Object, hint string) (Value, errors.Error)

OrdinaryToPrimitive is specified in 7.1.1.1.

func RequireObjectCoercible

func RequireObjectCoercible(arg Value) (Value, errors.Error)

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.

func ToPrimitive

func ToPrimitive(input Value, preferredType interface{}) (Value, errors.Error)

ToPrimitive attempts to convert the given input to a primitive value, or, if preferredType is not nil, to that preferred type. ToPrimitive is specified in 7.1.1.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL