Documentation
¶
Index ¶
- Constants
- Variables
- func AsNumber(v Value) float64
- func AsString(v Value) string
- func ClearShapeCache()
- func CopyBasicStats(vmStats ICacheStats)
- func IsFunction(v Value) bool
- func IsNumber(v Value) bool
- func IsString(v Value) bool
- func PrintExtendedStats(vm *VM)
- func ResetExtendedStats()
- func StringToUTF16(s string) []uint16
- func UTF16Length(s string) int
- func UTF16ToString(units []uint16) string
- func UpdatePrototypeStats(statType string, depth int)
- type ArgumentsObject
- func (a *ArgumentsObject) Callee() Value
- func (a *ArgumentsObject) Get(index int) Value
- func (a *ArgumentsObject) GetNamedProp(name string) (Value, bool)
- func (a *ArgumentsObject) GetSymbolProp(sym *SymbolObject) (Value, bool)
- func (a *ArgumentsObject) HasNamedProp(name string) bool
- func (a *ArgumentsObject) HasOwnSymbolProp(sym *SymbolObject) bool
- func (a *ArgumentsObject) IsStrict() bool
- func (a *ArgumentsObject) Length() int
- func (a *ArgumentsObject) Set(index int, value Value)
- func (a *ArgumentsObject) SetCallee(val Value)
- func (a *ArgumentsObject) SetLength(val int)
- func (a *ArgumentsObject) SetNamedProp(name string, val Value)
- func (a *ArgumentsObject) SetSymbolProp(sym *SymbolObject, val Value)
- type ArrayBufferObject
- func (ab *ArrayBufferObject) Detach()
- func (ab *ArrayBufferObject) GetData() []byte
- func (ab *ArrayBufferObject) GetOwnProperty(name string) (Value, bool)
- func (ab *ArrayBufferObject) HasOwnProperty(name string) bool
- func (ab *ArrayBufferObject) IsDetached() bool
- func (ab *ArrayBufferObject) SetOwnProperty(name string, value Value)
- type ArrayObject
- func (a *ArrayObject) Append(value Value)
- func (a *ArrayObject) DefineAccessorProperty(name string, getter Value, hasGetter bool, setter Value, hasSetter bool, ...)
- func (a *ArrayObject) DefineOwnProperty(name string, value Value, writable, enumerable, configurable bool)
- func (a *ArrayObject) Get(index int) Value
- func (a *ArrayObject) GetNamedPropertyDescriptor(name string) (Value, bool, bool)
- func (a *ArrayObject) GetOwn(name string) (Value, bool)
- func (a *ArrayObject) GetOwnAccessor(name string) (Value, Value, bool, bool, bool)
- func (a *ArrayObject) GetOwnPropertyDescriptor(name string) (Value, PropertyDesc, bool)
- func (a *ArrayObject) GetSymbolProp(sym *SymbolObject) (Value, bool)
- func (a *ArrayObject) HasIndex(index int) bool
- func (a *ArrayObject) HasOwnSymbolProp(sym *SymbolObject) bool
- func (a *ArrayObject) IsExtensible() bool
- func (a *ArrayObject) IsFrozen() bool
- func (a *ArrayObject) Length() int
- func (a *ArrayObject) NamedPropertyKeys() []string
- func (a *ArrayObject) SealProperties()
- func (a *ArrayObject) Set(index int, value Value)
- func (a *ArrayObject) SetElements(elements []Value)
- func (a *ArrayObject) SetExecMeta(index int, input string)
- func (a *ArrayObject) SetExtensible(extensible bool)
- func (a *ArrayObject) SetFrozen(frozen bool)
- func (a *ArrayObject) SetLength(newLength int)
- func (a *ArrayObject) SetOwn(name string, value Value)
- func (a *ArrayObject) SetSymbolProp(sym *SymbolObject, val Value)
- type AsyncGeneratorObject
- type AsyncNativeFunctionObject
- type BigIntObject
- type BoundFunctionObject
- type BoundNativeFunctionObject
- type BufferData
- type BytecodeCall
- type CallFrame
- type Chunk
- func (c *Chunk) AddConstant(v Value) uint16
- func (c *Chunk) AddVarGlobalIndex(idx uint16)
- func (c *Chunk) DisassembleChunk(name string) string
- func (c *Chunk) DisassembleChunkFiltered(name string, filter string) string
- func (c *Chunk) EmitByte(b byte)
- func (c *Chunk) GetLine(offset int) int
- func (c *Chunk) WriteOpCode(op OpCode, line int)
- func (c *Chunk) WriteUint16(val uint16)
- type ClosureObject
- type Completion
- type DataViewObject
- func (dv *DataViewObject) GetBigInt64(byteOffset int, littleEndian bool) (*big.Int, bool)
- func (dv *DataViewObject) GetBigUint64(byteOffset int, littleEndian bool) (*big.Int, bool)
- func (dv *DataViewObject) GetBuffer() *ArrayBufferObject
- func (dv *DataViewObject) GetBufferData() BufferData
- func (dv *DataViewObject) GetByteLength() int
- func (dv *DataViewObject) GetByteOffset() int
- func (dv *DataViewObject) GetFloat32(byteOffset int, littleEndian bool) (float32, bool)
- func (dv *DataViewObject) GetFloat64(byteOffset int, littleEndian bool) (float64, bool)
- func (dv *DataViewObject) GetInt8(byteOffset int) (int8, bool)
- func (dv *DataViewObject) GetInt16(byteOffset int, littleEndian bool) (int16, bool)
- func (dv *DataViewObject) GetInt32(byteOffset int, littleEndian bool) (int32, bool)
- func (dv *DataViewObject) GetSharedBuffer() *SharedArrayBufferObject
- func (dv *DataViewObject) GetUint8(byteOffset int) (uint8, bool)
- func (dv *DataViewObject) GetUint16(byteOffset int, littleEndian bool) (uint16, bool)
- func (dv *DataViewObject) GetUint32(byteOffset int, littleEndian bool) (uint32, bool)
- func (dv *DataViewObject) IsSharedBuffer() bool
- func (dv *DataViewObject) SetBigInt64(byteOffset int, value *big.Int, littleEndian bool) bool
- func (dv *DataViewObject) SetBigUint64(byteOffset int, value *big.Int, littleEndian bool) bool
- func (dv *DataViewObject) SetFloat32(byteOffset int, value float32, littleEndian bool) bool
- func (dv *DataViewObject) SetFloat64(byteOffset int, value float64, littleEndian bool) bool
- func (dv *DataViewObject) SetInt8(byteOffset int, value int8) bool
- func (dv *DataViewObject) SetInt16(byteOffset int, value int16, littleEndian bool) bool
- func (dv *DataViewObject) SetInt32(byteOffset int, value int32, littleEndian bool) bool
- func (dv *DataViewObject) SetUint8(byteOffset int, value uint8) bool
- func (dv *DataViewObject) SetUint16(byteOffset int, value uint16, littleEndian bool) bool
- func (dv *DataViewObject) SetUint32(byteOffset int, value uint32, littleEndian bool) bool
- type DictObject
- func (d *DictObject) DeleteOwn(name string) bool
- func (d *DictObject) Get(name string) (Value, bool)
- func (d *DictObject) GetOwn(name string) (Value, bool)
- func (d *DictObject) GetOwnDescriptor(name string) (Value, bool, bool, bool, bool)
- func (d *DictObject) GetPrototype() Value
- func (d *DictObject) Has(name string) bool
- func (d *DictObject) HasOwn(name string) bool
- func (d *DictObject) IsExtensible() bool
- func (d *DictObject) IsOwnPropertyNonConfigurable(name string) (exists bool, nonConfigurable bool)
- func (d *DictObject) OwnKeys() []string
- func (d *DictObject) OwnPropertyNames() []string
- func (d *DictObject) SetExtensible(extensible bool)
- func (d *DictObject) SetOwn(name string, v Value)
- func (d *DictObject) SetPrototype(proto Value) bool
- type EvalDriver
- type ExceptionError
- type ExceptionHandler
- type ExceptionState
- type ExecutionContext
- type ExtendedCacheStats
- type Field
- type FunctionObject
- type GeneratorFrame
- type GeneratorObject
- type GeneratorState
- type Heap
- func (h *Heap) ClearUserGlobals()
- func (h *Heap) CloneLayout() *Heap
- func (h *Heap) Delete(index int) bool
- func (h *Heap) Get(index int) (Value, bool)
- func (h *Heap) GetNameByIndex(index int) string
- func (h *Heap) GetNameToIndex() map[string]int
- func (h *Heap) IsConfigurable(index int) bool
- func (h *Heap) IsWritable(index int) bool
- func (h *Heap) Resize(newSize int)
- func (h *Heap) Set(index int, value Value) error
- func (h *Heap) SetBuiltinGlobals(globals map[string]Value, indexMap map[string]int) error
- func (h *Heap) SetConfigurable(index int, configurable bool) error
- func (h *Heap) SetWritable(index int, writable bool) error
- func (h *Heap) Size() int
- func (h *Heap) UpdateNameToIndex(newMappings map[string]int)
- func (h *Heap) Values() []Value
- type ICacheStats
- type InterpretResult
- type KeyKind
- type MapObject
- func (m *MapObject) Clear()
- func (m *MapObject) Delete(key Value) bool
- func (m *MapObject) ForEach(fn func(key Value, value Value))
- func (m *MapObject) Get(key Value) Value
- func (m *MapObject) GetEntryAt(index int) (Value, Value, bool)
- func (m *MapObject) Has(key Value) bool
- func (m *MapObject) OrderLen() int
- func (m *MapObject) Set(key, value Value)
- func (m *MapObject) Size() int
- type ModuleContext
- type ModuleLoader
- type ModuleRecord
- type NativeFunctionObject
- type NativeFunctionObjectWithProps
- type Object
- type OpCode
- type PendingAction
- type PlainObject
- func (o *PlainObject) DefineAccessorProperty(name string, getter Value, hasGetter bool, setter Value, hasSetter bool, ...)
- func (o *PlainObject) DefineAccessorPropertyByKey(key PropertyKey, getter Value, hasGetter bool, setter Value, hasSetter bool, ...)
- func (o *PlainObject) DefineOwnProperty(name string, value Value, writable *bool, enumerable *bool, configurable *bool)
- func (o *PlainObject) DefineOwnPropertyByKey(key PropertyKey, value Value, writable *bool, enumerable *bool, ...)
- func (o *PlainObject) DeleteOwn(name string) bool
- func (o *PlainObject) DeleteOwnByKey(key PropertyKey) bool
- func (o *PlainObject) FreezeAllProperties()
- func (o *PlainObject) Get(name string) (Value, bool)
- func (o *PlainObject) GetOwn(name string) (Value, bool)
- func (o *PlainObject) GetOwnAccessor(name string) (Value, Value, bool, bool, bool)
- func (o *PlainObject) GetOwnAccessorByKey(key PropertyKey) (Value, Value, bool, bool, bool)
- func (o *PlainObject) GetOwnByKey(key PropertyKey) (Value, bool)
- func (o *PlainObject) GetOwnDescriptor(name string) (Value, bool, bool, bool, bool)
- func (o *PlainObject) GetOwnDescriptorByKey(key PropertyKey) (Value, bool, bool, bool, bool)
- func (o *PlainObject) GetPrivateAccessor(name string) (Value, Value, bool)
- func (o *PlainObject) GetPrivateField(name string) (Value, bool)
- func (o *PlainObject) GetPrivateMethod(name string) (Value, bool)
- func (o *PlainObject) GetPrototype() Value
- func (o *PlainObject) Has(name string) bool
- func (o *PlainObject) HasOwn(name string) bool
- func (o *PlainObject) HasOwnByKey(key PropertyKey) bool
- func (o *PlainObject) HasPrivateField(name string) bool
- func (o *PlainObject) IsExtensible() bool
- func (o *PlainObject) IsFrozenProperties() bool
- func (o *PlainObject) IsModuleNamespace() bool
- func (o *PlainObject) IsOwnPropertyNonConfigurable(name string) (exists bool, nonConfigurable bool)
- func (o *PlainObject) IsOwnPropertyNonConfigurableByKey(key PropertyKey) (exists bool, nonConfigurable bool)
- func (o *PlainObject) IsPrivateAccessor(name string) bool
- func (o *PlainObject) IsPrivateMethod(name string) bool
- func (o *PlainObject) IsSealedProperties() bool
- func (o *PlainObject) OwnKeys() []string
- func (o *PlainObject) OwnPropertyNames() []string
- func (o *PlainObject) OwnSymbolKeys() []Value
- func (o *PlainObject) SealAllProperties()
- func (o *PlainObject) SetExtensible(extensible bool)
- func (o *PlainObject) SetImmutablePrototype()
- func (o *PlainObject) SetModuleNamespace(isNamespace bool)
- func (o *PlainObject) SetOwn(name string, v Value)
- func (o *PlainObject) SetOwnNonEnumerable(name string, v Value)
- func (o *PlainObject) SetPrivateAccessor(name string, getter Value, setter Value)
- func (o *PlainObject) SetPrivateField(name string, value Value)
- func (o *PlainObject) SetPrivateMethod(name string, value Value)
- func (o *PlainObject) SetPrototype(proto Value) bool
- type PrivateBrandInfoVM
- type PrivateMemberKindVM
- type PromiseObject
- type PromiseReaction
- type PromiseState
- type PropCacheEntry
- type PropCacheState
- type PropInlineCache
- type PropertyDesc
- type PropertyKey
- type PrototypeCache
- type PrototypeCacheEntry
- type ProxyObject
- type Realm
- func (r *Realm) DefineGlobal(name string, value Value) error
- func (r *Realm) GetGlobal(name string) (Value, bool)
- func (r *Realm) ID() int
- func (r *Realm) InitializePrototypes()
- func (r *Realm) InitializeSymbols()
- func (r *Realm) IsInitialized() bool
- func (r *Realm) MarkInitialized()
- func (r *Realm) SetGlobal(name string, value Value)
- func (r *Realm) VM() *VM
- type RegExpObject
- func (r *RegExpObject) FindAllString(s string, n int) []string
- func (r *RegExpObject) FindAllStringSubmatchIndex(s string, n int) [][]int
- func (r *RegExpObject) FindStringIndex(s string) []int
- func (r *RegExpObject) FindStringSubmatch(s string) []string
- func (r *RegExpObject) FindStringSubmatchIndex(s string) []int
- func (r *RegExpObject) FindStringSubmatchIndexAt(s string, byteStartAt int) []int
- func (r *RegExpObject) GetCompileError() string
- func (r *RegExpObject) GetCompiledRegex() *regexp.Regexp
- func (r *RegExpObject) GetFlags() string
- func (r *RegExpObject) GetLastIndex() int
- func (r *RegExpObject) GetSource() string
- func (r *RegExpObject) HasCompileError() bool
- func (r *RegExpObject) IsDotAll() bool
- func (r *RegExpObject) IsGlobal() bool
- func (r *RegExpObject) IsIgnoreCase() bool
- func (r *RegExpObject) IsMultiline() bool
- func (r *RegExpObject) IsSticky() bool
- func (r *RegExpObject) MatchString(s string) bool
- func (r *RegExpObject) ReplaceAllLiteralString(src, repl string) string
- func (r *RegExpObject) ReplaceAllString(src, repl string) string
- func (r *RegExpObject) ReplaceAllStringFunc(src string, repl func(string) string) string
- func (r *RegExpObject) SetLastIndex(index int)
- func (r *RegExpObject) Split(s string, n int) []string
- func (r *RegExpObject) UsesRegexp2() bool
- type ScopeDescriptor
- type SetObject
- func (s *SetObject) Add(value Value)
- func (s *SetObject) Clear()
- func (s *SetObject) Delete(value Value) bool
- func (s *SetObject) ForEach(fn func(value Value))
- func (s *SetObject) GetValueAt(index int) (Value, bool)
- func (s *SetObject) Has(value Value) bool
- func (s *SetObject) OrderLen() int
- func (s *SetObject) Size() int
- type Shape
- type SharedArrayBufferObject
- func (sab *SharedArrayBufferObject) ByteLength() int
- func (sab *SharedArrayBufferObject) GetData() []byte
- func (sab *SharedArrayBufferObject) GetOwnProperty(name string) (Value, bool)
- func (sab *SharedArrayBufferObject) HasOwnProperty(name string) bool
- func (sab *SharedArrayBufferObject) IsDetached() bool
- func (sab *SharedArrayBufferObject) SetOwnProperty(name string, value Value)
- type StackFrame
- type StringObject
- type SuspendedFrame
- type SymbolObject
- type TypedArrayKind
- type TypedArrayObject
- func (ta *TypedArrayObject) GetBuffer() *ArrayBufferObject
- func (ta *TypedArrayObject) GetBufferData() BufferData
- func (ta *TypedArrayObject) GetByteLength() int
- func (ta *TypedArrayObject) GetByteOffset() int
- func (ta *TypedArrayObject) GetBytesPerElement() int
- func (ta *TypedArrayObject) GetElement(index int) Value
- func (ta *TypedArrayObject) GetElementType() TypedArrayKind
- func (ta *TypedArrayObject) GetLength() int
- func (ta *TypedArrayObject) GetOwnProperty(name string) (Value, bool)
- func (ta *TypedArrayObject) GetSharedBuffer() *SharedArrayBufferObject
- func (ta *TypedArrayObject) HasOwnProperty(name string) bool
- func (ta *TypedArrayObject) IsSharedBuffer() bool
- func (ta *TypedArrayObject) SetElement(index int, value Value)
- func (ta *TypedArrayObject) SetOwnProperty(name string, value Value)
- type Upvalue
- type VM
- func (vm *VM) AddPromiseReaction(promiseVal Value, isFulfilled bool, callback func(Value))
- func (vm *VM) Call(fn Value, thisValue Value, args []Value) (Value, error)
- func (vm *VM) CallFunctionDirectly(fn Value, thisValue Value, args []Value) (Value, error)
- func (vm *VM) Cancel()
- func (vm *VM) CaptureStackTrace() string
- func (vm *VM) ClearErrors()
- func (vm *VM) ClearHandlerFound()
- func (vm *VM) ClearUnwindingState()
- func (vm *VM) Construct(constructor Value, args []Value) (Value, error)
- func (vm *VM) ConstructWithNewTarget(constructor Value, args []Value, newTarget Value) (Value, error)
- func (vm *VM) CreateRealm() *Realm
- func (vm *VM) CurrentRealm() *Realm
- func (vm *VM) DebugPrintGlobals()
- func (vm *VM) DecrementCallDepth()
- func (vm *VM) DefaultRealm() *Realm
- func (vm *VM) DrainMicrotasks()
- func (vm *VM) EnterHelperCall()
- func (vm *VM) ExecuteGenerator(genObj *GeneratorObject, sentValue Value) (Value, error)
- func (vm *VM) ExecuteGeneratorWithException(genObj *GeneratorObject, exception Value) (Value, error)
- func (vm *VM) ExecuteGeneratorWithReturn(genObj *GeneratorObject, returnValue Value) (Value, error)
- func (vm *VM) ExitHelperCall()
- func (vm *VM) GetAsyncRuntime() runtime.AsyncRuntime
- func (vm *VM) GetCacheStats() ICacheStats
- func (vm *VM) GetCallDepth() int
- func (vm *VM) GetFrameCount() int
- func (vm *VM) GetFunctionRealm(fn Value) (*Realm, error)
- func (vm *VM) GetGlobal(name string) (Value, bool)
- func (vm *VM) GetGlobalByIndex(index int) (Value, bool)
- func (vm *VM) GetHeap() *Heap
- func (vm *VM) GetNewTarget() Value
- func (vm *VM) GetProperty(obj Value, propName string) (Value, error)
- func (vm *VM) GetPrototypeFromConstructor(constructor Value, intrinsicDefault string) (Value, error)
- func (vm *VM) GetSymbolProperty(obj Value, symbol Value) (Value, bool)
- func (vm *VM) GetSymbolPropertyWithGetter(obj Value, symbol Value) (Value, bool, error)
- func (vm *VM) GetThis() Value
- func (vm *VM) IncrementCallDepth()
- func (vm *VM) Interpret(chunk *Chunk) (Value, []errors.PaseratiError)
- func (vm *VM) InterpretWithCallerScope(chunk *Chunk, callerRegs []Value, callerThis Value, callerHomeObject Value) (Value, []errors.PaseratiError)
- func (vm *VM) IsConstructor(val Value) bool
- func (vm *VM) IsConstructorCall() bool
- func (vm *VM) IsHandlerFound() bool
- func (vm *VM) IsInStrictMode() bool
- func (vm *VM) IsOriginalEval(v Value) bool
- func (vm *VM) IsUnwinding() bool
- func (vm *VM) IterableToArray(value Value) (Value, error)
- func (vm *VM) NewArrayFromSlice(elements []Value) Value
- func (vm *VM) NewBooleanObject(primitiveValue bool) Value
- func (vm *VM) NewExceptionError(value Value) error
- func (vm *VM) NewNumberObject(primitiveValue float64) Value
- func (vm *VM) NewPendingPromise() Value
- func (vm *VM) NewPromiseFromExecutor(executor Value) (Value, error)
- func (vm *VM) NewRangeError(message string) error
- func (vm *VM) NewReferenceError(message string) error
- func (vm *VM) NewRegExpDeferred(pattern, flags string) Value
- func (vm *VM) NewRejectedPromise(reason Value) Value
- func (vm *VM) NewResolvedPromise(value Value) Value
- func (vm *VM) NewStringObject(primitiveValue string) Value
- func (vm *VM) NewSymbolObject(symbolValue Value) Value
- func (vm *VM) NewSyntaxError(message string) error
- func (vm *VM) NewTypeError(message string) error
- func (vm *VM) NewTypeErrorInRealm(realm *Realm, message string) error
- func (vm *VM) NewURIError(message string) error
- func (vm *VM) PrintCacheStats()
- func (vm *VM) PromiseThen(thisPromise Value, onFulfilled, onRejected Value) (Value, error)
- func (vm *VM) RejectPromise(promise *PromiseObject, reason Value)
- func (vm *VM) Reset()
- func (vm *VM) ResizeHeapForGlobals(allocatedSize int)
- func (vm *VM) ResolvePromise(promise *PromiseObject, value Value)
- func (vm *VM) SetAsyncRuntime(rt runtime.AsyncRuntime)
- func (vm *VM) SetBuiltinGlobals(globals map[string]Value, indexMap map[string]int) error
- func (vm *VM) SetCurrentModulePath(modulePath string)
- func (vm *VM) SetEvalDriver(driver EvalDriver)
- func (vm *VM) SetModuleLoader(loader ModuleLoader)
- func (vm *VM) SetOriginalEval(eval Value)
- func (vm *VM) SetProperty(obj Value, propName string, value Value) error
- func (vm *VM) SyncGlobalNames(nameToIndex map[string]int)
- func (vm *VM) SyncHeapToGlobalObject()
- func (vm *VM) SyncPrototypesToRealm()
- func (vm *VM) ThrowExceptionValue(value Value)
- func (vm *VM) ThrowRangeError(message string)
- func (vm *VM) ThrowReferenceError(message string)
- func (vm *VM) ThrowSyntaxError(message string)
- func (vm *VM) ThrowTypeError(message string)
- func (vm *VM) ToInteger(val Value) int
- func (vm *VM) ToNumber(val Value) float64
- func (vm *VM) ToObject(val Value) (Value, error)
- func (vm *VM) ToPrimitive(val Value, hint string) Value
- func (vm *VM) WithRealm(realm *Realm, fn func())
- func (vm *VM) WithRealmValue(realm *Realm, fn func() Value) Value
- type VMCaller
- type Value
- func BooleanValue(value bool) Value
- func CanonicalizeKeyedCollectionKey(key Value) Value
- func IntegerValue(value int32) Value
- func NewArguments(args []Value, callee Value, isStrict bool) Value
- func NewArray() Value
- func NewArrayBuffer(size int) Value
- func NewArrayBufferFromObject(buffer *ArrayBufferObject) Value
- func NewArrayWithArgs(args []Value) Value
- func NewArrayWithLength(length int) Value
- func NewAsyncGenerator(function Value) Value
- func NewAsyncNativeFunction(arity int, variadic bool, name string, ...) Value
- func NewBigInt(value *big.Int) Value
- func NewBoundFunction(originalFunction Value, boundThis Value, partialArgs []Value, name string) Value
- func NewClosure(fn *FunctionObject, upvalues []*Upvalue) Value
- func NewConstructorWithProps(arity int, variadic bool, name string, fn func(args []Value) (Value, error)) Value
- func NewDataView(buffer BufferData, byteOffset, byteLength int) Value
- func NewDictObject(proto Value) Value
- func NewFunction(arity, length, upvalueCount, registerSize int, variadic bool, name string, ...) Value
- func NewGenerator(function Value) Value
- func NewMap() Value
- func NewNativeConstructor(arity int, variadic bool, name string, fn func(args []Value) (Value, error)) Value
- func NewNativeFunction(arity int, variadic bool, name string, fn func(args []Value) (Value, error)) Value
- func NewNativeFunctionWithProps(arity int, variadic bool, name string, fn func(args []Value) (Value, error)) Value
- func NewObject(proto Value) Value
- func NewProxy(target Value, handler Value) Value
- func NewRegExp(pattern, flags string) (Value, error)
- func NewRegisteredSymbol(value string) Value
- func NewSet() Value
- func NewSharedArrayBuffer(size int) Value
- func NewSharedArrayBufferFromObject(buffer *SharedArrayBufferObject) Value
- func NewString(value string) Value
- func NewSymbol(value string) Value
- func NewSymbolNoDescription() Value
- func NewTypedArray(kind TypedArrayKind, lengthOrBuffer interface{}, byteOffset, length int) Value
- func NewValueFromPlainObject(plainObj *PlainObject) Value
- func NewWeakMap() Value
- func NewWeakMapWithPrototype(prototype Value) Value
- func NewWeakRef(target Value) Value
- func NewWeakRefWithPrototype(target Value, prototype Value) Value
- func NewWeakSet() Value
- func Number(f float64) Value
- func NumberValue(value float64) Value
- func RegExpValue(r *RegExpObject) Value
- func String(s string) Value
- func (v Value) AsArguments() *ArgumentsObject
- func (v Value) AsArray() *ArrayObject
- func (v Value) AsArrayBuffer() *ArrayBufferObject
- func (v Value) AsAsyncGenerator() *AsyncGeneratorObject
- func (v Value) AsAsyncNativeFunction() *AsyncNativeFunctionObject
- func (v Value) AsBigInt() *big.Int
- func (v Value) AsBoolean() bool
- func (v Value) AsBoundFunction() *BoundFunctionObject
- func (v Value) AsClosure() *ClosureObject
- func (v Value) AsDataView() *DataViewObject
- func (v Value) AsDictObject() *DictObject
- func (v Value) AsFloat() float64
- func (v Value) AsFunction() *FunctionObject
- func (v Value) AsGenerator() *GeneratorObject
- func (v Value) AsInteger() int32
- func (v Value) AsMap() *MapObject
- func (v Value) AsNativeFunction() *NativeFunctionObject
- func (v Value) AsNativeFunctionWithProps() *NativeFunctionObjectWithProps
- func (v Value) AsObject() *Object
- func (v Value) AsPlainObject() *PlainObject
- func (v Value) AsPromise() *PromiseObject
- func (v Value) AsProxy() *ProxyObject
- func (v Value) AsRegExpObject() *RegExpObject
- func (v Value) AsSet() *SetObject
- func (v Value) AsSharedArrayBuffer() *SharedArrayBufferObject
- func (v Value) AsString() string
- func (v Value) AsSymbol() string
- func (v Value) AsSymbolObject() *SymbolObject
- func (v Value) AsTypedArray() *TypedArrayObject
- func (v Value) AsWeakMap() *WeakMapObject
- func (v Value) AsWeakRef() *WeakRefObject
- func (v Value) AsWeakSet() *WeakSetObject
- func (v Value) CanBeHeldWeakly() bool
- func (v Value) Equals(other Value) bool
- func (v Value) GetArity() int
- func (v Value) Inspect() string
- func (v Value) InspectNested() string
- func (v Value) Is(other Value) bool
- func (v Value) IsArguments() bool
- func (v Value) IsArray() bool
- func (v Value) IsBigInt() bool
- func (v Value) IsBoolean() bool
- func (v Value) IsCallable() bool
- func (v Value) IsClosure() bool
- func (v Value) IsDictObject() bool
- func (v Value) IsFalsey() bool
- func (v Value) IsFloatNumber() bool
- func (v Value) IsFunction() bool
- func (v Value) IsGenerator() bool
- func (v Value) IsIntegerNumber() bool
- func (v Value) IsNativeFunction() bool
- func (v Value) IsNumber() bool
- func (v Value) IsObject() bool
- func (v Value) IsRegExp() bool
- func (v Value) IsString() bool
- func (v Value) IsSymbol() bool
- func (v Value) IsTruthy() bool
- func (v Value) IsUndefined() bool
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) StrictlyEquals(other Value) bool
- func (v Value) ToFloat() float64
- func (v Value) ToInteger() int32
- func (v Value) ToPrimitive(hint string) Value
- func (v Value) ToString() string
- func (v Value) Type() ValueType
- func (v Value) TypeName() string
- func (v *Value) UnmarshalJSON(data []byte) error
- type ValueType
- type WeakMapEntry
- type WeakMapObject
- type WeakRefObject
- type WeakSetEntry
- type WeakSetObject
Constants ¶
const MaxFrames = 512 // Max call stack depth
const RegFileSize = 256 // Max registers per function call frame
Variables ¶
var ( // EnablePrototypeCache enables caching of prototype chain lookups EnablePrototypeCache = getEnvBool("PASERATI_ENABLE_PROTO_CACHE", false) // EnableDetailedCacheStats enables collection of detailed per-site statistics EnableDetailedCacheStats = getEnvBool("PASERATI_DETAILED_CACHE_STATS", false) // MaxPolymorphicEntries controls how many shapes we track before going megamorphic MaxPolymorphicEntries = getEnvInt("PASERATI_MAX_POLY_ENTRIES", 4) )
Cache configuration flags - can be set via environment variables
var ( Undefined = Value{/* contains filtered or unexported fields */} Null = Value{/* contains filtered or unexported fields */} Hole = Value{/* contains filtered or unexported fields */} // Internal marker for array holes (sparse arrays) Uninitialized = Value{/* contains filtered or unexported fields */} // TDZ marker for let/const before initialization True = Value{/* contains filtered or unexported fields */} False = Value{/* contains filtered or unexported fields */} NaN = Value{/* contains filtered or unexported fields */} )
Functions ¶
func AsNumber ¶
AsNumber returns the numeric value (float64) of a Number value. For integer numbers, it converts to float64.
func ClearShapeCache ¶
func ClearShapeCache()
ClearShapeCache clears the global RootShape transition maps to prevent memory bloat This should be called periodically in test runners that create many short-lived VM instances
func CopyBasicStats ¶
func CopyBasicStats(vmStats ICacheStats)
CopyBasicStats copies basic cache stats from VM to extended stats
func IsFunction ¶
IsFunction reports whether the value is a function (FunctionObject or ClosureObject or NativeFunctionObject).
func IsNumber ¶
--- VM API Helpers --- IsNumber returns true if the value is a JS Number (float or integer).
func PrintExtendedStats ¶
func PrintExtendedStats(vm *VM)
PrintExtendedStats prints detailed cache statistics including prototype chain info
func ResetExtendedStats ¶
func ResetExtendedStats()
ResetExtendedStats resets all extended statistics
func StringToUTF16 ¶
StringToUTF16 converts a Go string (UTF-8/WTF-8) to UTF-16 code units This handles WTF-8 encoded lone surrogates that our lexer produces
func UTF16Length ¶
UTF16Length returns the number of UTF-16 code units in a string This is the correct length for JavaScript string.length property
func UTF16ToString ¶
UTF16ToString converts a slice of UTF-16 code units back to a Go string This preserves lone surrogates using WTF-8 encoding (same as lexer)
func UpdatePrototypeStats ¶
UpdatePrototypeStats updates prototype-specific statistics
Types ¶
type ArgumentsObject ¶
type ArgumentsObject struct {
Object
// contains filtered or unexported fields
}
func AsArguments ¶
func AsArguments(v Value) *ArgumentsObject
AsArguments returns the ArgumentsObject pointer from an Arguments value.
func (*ArgumentsObject) Callee ¶ added in v0.9.3
func (a *ArgumentsObject) Callee() Value
Callee returns the function that created this arguments object
func (*ArgumentsObject) Get ¶
func (a *ArgumentsObject) Get(index int) Value
func (*ArgumentsObject) GetNamedProp ¶ added in v0.9.7
func (a *ArgumentsObject) GetNamedProp(name string) (Value, bool)
GetNamedProp returns a named property from the arguments object's overflow storage
func (*ArgumentsObject) GetSymbolProp ¶ added in v0.9.6
func (a *ArgumentsObject) GetSymbolProp(sym *SymbolObject) (Value, bool)
GetSymbolProp returns a symbol-keyed property from the arguments object
func (*ArgumentsObject) HasNamedProp ¶ added in v0.9.7
func (a *ArgumentsObject) HasNamedProp(name string) bool
HasNamedProp checks if the arguments object has a named property in overflow storage
func (*ArgumentsObject) HasOwnSymbolProp ¶ added in v0.9.6
func (a *ArgumentsObject) HasOwnSymbolProp(sym *SymbolObject) bool
HasOwnSymbolProp checks if the arguments object has an own symbol property
func (*ArgumentsObject) IsStrict ¶ added in v0.9.3
func (a *ArgumentsObject) IsStrict() bool
IsStrict returns whether this arguments object is from strict mode code
func (*ArgumentsObject) Set ¶
func (a *ArgumentsObject) Set(index int, value Value)
func (*ArgumentsObject) SetCallee ¶ added in v0.9.7
func (a *ArgumentsObject) SetCallee(val Value)
SetCallee sets the callee property on the arguments object
func (*ArgumentsObject) SetLength ¶ added in v0.9.7
func (a *ArgumentsObject) SetLength(val int)
SetLength sets the length property on the arguments object
func (*ArgumentsObject) SetNamedProp ¶ added in v0.9.7
func (a *ArgumentsObject) SetNamedProp(name string, val Value)
SetNamedProp sets a named property on the arguments object's overflow storage
func (*ArgumentsObject) SetSymbolProp ¶ added in v0.9.6
func (a *ArgumentsObject) SetSymbolProp(sym *SymbolObject, val Value)
SetSymbolProp sets a symbol-keyed property on the arguments object
type ArrayBufferObject ¶
type ArrayBufferObject struct {
Object
// contains filtered or unexported fields
}
ArrayBufferObject represents a raw binary data buffer
func (*ArrayBufferObject) Detach ¶
func (ab *ArrayBufferObject) Detach()
Detach detaches the ArrayBuffer, making it unusable
func (*ArrayBufferObject) GetData ¶
func (ab *ArrayBufferObject) GetData() []byte
GetData returns the underlying byte slice
func (*ArrayBufferObject) GetOwnProperty ¶ added in v0.9.9
func (ab *ArrayBufferObject) GetOwnProperty(name string) (Value, bool)
GetOwnProperty returns an own property value
func (*ArrayBufferObject) HasOwnProperty ¶ added in v0.9.9
func (ab *ArrayBufferObject) HasOwnProperty(name string) bool
HasOwnProperty checks if the buffer has an own property
func (*ArrayBufferObject) IsDetached ¶
func (ab *ArrayBufferObject) IsDetached() bool
IsDetached returns whether the buffer has been detached
func (*ArrayBufferObject) SetOwnProperty ¶ added in v0.9.9
func (ab *ArrayBufferObject) SetOwnProperty(name string, value Value)
SetOwnProperty sets an own property value
type ArrayObject ¶
type ArrayObject struct {
Object
// contains filtered or unexported fields
}
func AsArray ¶
func AsArray(v Value) *ArrayObject
AsArray returns the ArrayObject pointer from an Array value.
func (*ArrayObject) Append ¶
func (a *ArrayObject) Append(value Value)
Append adds a value to the end of the array
func (*ArrayObject) DefineAccessorProperty ¶ added in v0.9.9
func (a *ArrayObject) DefineAccessorProperty(name string, getter Value, hasGetter bool, setter Value, hasSetter bool, enumerable *bool, configurable *bool)
DefineAccessorProperty defines an accessor property on the array object
func (*ArrayObject) DefineOwnProperty ¶ added in v0.9.7
func (a *ArrayObject) DefineOwnProperty(name string, value Value, writable, enumerable, configurable bool)
DefineOwnProperty sets a named property with specified descriptor attributes
func (*ArrayObject) Get ¶
func (a *ArrayObject) Get(index int) Value
Get returns the element at the given index, or Undefined if out of bounds
func (*ArrayObject) GetNamedPropertyDescriptor ¶ added in v0.9.9
func (a *ArrayObject) GetNamedPropertyDescriptor(name string) (Value, bool, bool)
GetNamedPropertyDescriptor returns the value and descriptor for a named property
func (*ArrayObject) GetOwn ¶
func (a *ArrayObject) GetOwn(name string) (Value, bool)
GetOwn returns a named property from the array (e.g., "index", "input" for match results)
func (*ArrayObject) GetOwnAccessor ¶ added in v0.9.9
GetOwnAccessor returns the getter and setter for an accessor property Returns (getter, setter, enumerable, configurable, isAccessor)
func (*ArrayObject) GetOwnPropertyDescriptor ¶ added in v0.9.7
func (a *ArrayObject) GetOwnPropertyDescriptor(name string) (Value, PropertyDesc, bool)
GetOwnPropertyDescriptor returns the descriptor for a named property
func (*ArrayObject) GetSymbolProp ¶ added in v0.9.9
func (a *ArrayObject) GetSymbolProp(sym *SymbolObject) (Value, bool)
GetSymbolProp returns a symbol-keyed property from the array object
func (*ArrayObject) HasIndex ¶
func (a *ArrayObject) HasIndex(index int) bool
HasIndex returns true if the index has an actual value (not a hole in sparse array)
func (*ArrayObject) HasOwnSymbolProp ¶ added in v0.9.9
func (a *ArrayObject) HasOwnSymbolProp(sym *SymbolObject) bool
HasOwnSymbolProp checks if the array object has an own symbol property
func (*ArrayObject) IsExtensible ¶
func (a *ArrayObject) IsExtensible() bool
IsExtensible returns whether new properties can be added to this array
func (*ArrayObject) IsFrozen ¶ added in v0.9.7
func (a *ArrayObject) IsFrozen() bool
IsFrozen returns whether this array is frozen (elements and named properties)
func (*ArrayObject) Length ¶
func (a *ArrayObject) Length() int
Length returns the length of the array
func (*ArrayObject) NamedPropertyKeys ¶ added in v0.9.9
func (a *ArrayObject) NamedPropertyKeys() []string
NamedPropertyKeys returns all named (non-numeric) property keys on the array
func (*ArrayObject) SealProperties ¶ added in v0.9.10
func (a *ArrayObject) SealProperties()
SealProperties makes all named properties non-configurable (but preserves writable)
func (*ArrayObject) Set ¶
func (a *ArrayObject) Set(index int, value Value)
Set sets the element at the given index, expanding the array if necessary
func (*ArrayObject) SetElements ¶
func (a *ArrayObject) SetElements(elements []Value)
SetElements sets all elements at once and updates length
func (*ArrayObject) SetExecMeta ¶ added in v0.9.9
func (a *ArrayObject) SetExecMeta(index int, input string)
SetExecMeta stores exec result metadata for lazy property access. This avoids allocating a map for index/input/groups on every exec call.
func (*ArrayObject) SetExtensible ¶
func (a *ArrayObject) SetExtensible(extensible bool)
SetExtensible sets whether new properties can be added to this array
func (*ArrayObject) SetFrozen ¶ added in v0.9.7
func (a *ArrayObject) SetFrozen(frozen bool)
SetFrozen sets whether this array is frozen (elements non-writable/non-configurable)
func (*ArrayObject) SetLength ¶
func (a *ArrayObject) SetLength(newLength int)
SetLength sets the length of the array, expanding or truncating as needed
func (*ArrayObject) SetOwn ¶
func (a *ArrayObject) SetOwn(name string, value Value)
SetOwn sets a named property on the array (e.g., "index", "input" for match results)
func (*ArrayObject) SetSymbolProp ¶ added in v0.9.9
func (a *ArrayObject) SetSymbolProp(sym *SymbolObject, val Value)
SetSymbolProp sets a symbol-keyed property on the array object
type AsyncGeneratorObject ¶
type AsyncGeneratorObject GeneratorObject
type AsyncNativeFunctionObject ¶
type AsyncNativeFunctionObject struct {
Object
Arity int
Variadic bool
Name string
// AsyncFn receives a VMCaller interface that can call bytecode functions
AsyncFn func(caller VMCaller, args []Value) Value
}
AsyncNativeFunctionObject represents a native function that can call bytecode functions This uses Go channels for async communication with the VM
type BigIntObject ¶
type BigIntObject struct {
Object
// contains filtered or unexported fields
}
type BoundFunctionObject ¶
type BoundFunctionObject struct {
Object
OriginalFunction Value // The function being bound (can be any callable type)
BoundThis Value // The 'this' value to use when calling
PartialArgs []Value // Arguments to prepend to call arguments
Name string // For debugging/inspection
Properties *PlainObject // Per ECMAScript, bound functions can have properties
}
BoundFunctionObject represents any function bound to a 'this' value and optional partial arguments
func AsBoundFunction ¶
func AsBoundFunction(v Value) *BoundFunctionObject
AsBoundFunction returns the BoundFunctionObject pointer from a bound function value.
type BoundNativeFunctionObject ¶
type BoundNativeFunctionObject struct {
Object
ThisValue Value
NativeFunc *NativeFunctionObject
Name string
}
BoundNativeFunctionObject represents a native function bound to a 'this' value
type BufferData ¶ added in v0.9.9
BufferData is an interface for ArrayBuffer-like objects Both ArrayBuffer and SharedArrayBuffer implement this interface
type BytecodeCall ¶
type BytecodeCall struct {
Function Value
ThisValue Value
Args []Value
ResultCh chan Value // Channel to receive the result
}
BytecodeCall represents a request from a native function to call bytecode
type CallFrame ¶
type CallFrame struct {
// contains filtered or unexported fields
}
CallFrame represents a single active function call.
type Chunk ¶
type Chunk struct {
Code []byte // The bytecode instructions (OpCodes and operands)
Constants []Value // Constant pool (Now uses Value from vm package)
Lines []int // Line number for each byte in Code (parallel array)
ExceptionTable []ExceptionHandler // Exception handlers for try/catch blocks
IsStrict bool // Whether this chunk runs in strict mode
HasSimpleParameterList bool // True if all params are plain identifiers (no defaults, rest, or destructuring)
ScopeDesc *ScopeDescriptor // Scope info for direct eval (nil if not needed)
MaxRegs int // Maximum registers needed to execute this chunk
NumSpillSlots int // Number of spill slots needed (for register overflow)
// VarGlobalIndices tracks global indices that are var declarations (non-configurable per ECMAScript)
// These indices should have their heap slots marked as non-configurable (DontDelete)
VarGlobalIndices []uint16
// contains filtered or unexported fields
}
Chunk represents a sequence of bytecode instructions and associated data.
func (*Chunk) AddConstant ¶
AddConstant adds a value to the chunk's constant pool and returns its index. Returns a uint16 as we might need more than 256 constants. Deduplicates constants to avoid storing the same value multiple times. Uses type-specific caches for O(1) lookup of common types (strings, integers, floats).
func (*Chunk) AddVarGlobalIndex ¶ added in v0.9.4
AddVarGlobalIndex registers a global index as a var declaration (non-configurable)
func (*Chunk) DisassembleChunk ¶
DisassembleChunk returns a human-readable string representation of the chunk.
func (*Chunk) DisassembleChunkFiltered ¶
DisassembleChunkFiltered returns a human-readable string representation of the chunk, optionally filtering by function name. It recurses into nested functions.
func (*Chunk) EmitByte ¶ added in v0.9.3
EmitByte adds a raw byte (operand) to the chunk. Uses the line number from the most recent WriteOpCode call. Note: Named EmitByte instead of WriteByte to avoid conflict with io.ByteWriter interface.
func (*Chunk) GetLine ¶
GetLine returns the source line number corresponding to a given bytecode offset. It assumes the Lines slice is populated correctly (same length as Code, storing line per OpCode).
func (*Chunk) WriteOpCode ¶
WriteOpCode adds an opcode to the chunk. The line number is tracked for error reporting.
func (*Chunk) WriteUint16 ¶
WriteUint16 adds a 16-bit unsigned integer operand (e.g., for larger constant indices or jump offsets). Encoded as Big Endian. Uses the line number from the most recent WriteOpCode call.
type ClosureObject ¶
type ClosureObject struct {
Object
Fn *FunctionObject
Upvalues []*Upvalue
WithObjects []Value // Captured with-object stack from enclosing with statements
CapturedThis Value // Captured 'this' for arrow functions (lexical this binding)
CapturedSuperConstructor Value // Captured super constructor for arrow functions with super() calls
CapturedArguments Value // Captured 'arguments' for arrow functions (lexical arguments binding)
CapturedNewTarget Value // Captured 'new.target' for arrow functions (lexical new.target binding)
CapturedHomeObject Value // Captured [[HomeObject]] for arrow functions (for super property access)
Properties *PlainObject // Per-closure properties like .prototype (created lazily, shadows Fn.Properties)
// contains filtered or unexported fields
}
func AsClosure ¶
func AsClosure(v Value) *ClosureObject
AsClosure returns the ClosureObject pointer from a Closure value.
func (*ClosureObject) GetPrototypeWithVM ¶ added in v0.9.3
func (c *ClosureObject) GetPrototypeWithVM(vm *VM) Value
GetPrototypeWithVM returns the prototype to use for instances created with this closure. It first checks the closure's own Properties for a "prototype" property (set via assignment), then falls back to the underlying FunctionObject's prototype. IMPORTANT: When using the function's prototype, we update the constructor property to point to this closure, ensuring `new MyFunc().constructor === MyFunc` works correctly.
type Completion ¶
type Completion struct {
Type PendingAction // ActionBreak or ActionContinue
TargetPC int // Absolute PC to jump to after finally
}
Completion represents a deferred control flow action (break/continue) that needs to execute after a finally block
type DataViewObject ¶ added in v0.9.9
type DataViewObject struct {
Object
// contains filtered or unexported fields
}
DataViewObject represents a DataView that provides a low-level interface for reading and writing multiple number types in an ArrayBuffer
func (*DataViewObject) GetBigInt64 ¶ added in v0.9.9
GetBigInt64 reads a signed 64-bit integer at the specified byte offset
func (*DataViewObject) GetBigUint64 ¶ added in v0.9.9
GetBigUint64 reads an unsigned 64-bit integer at the specified byte offset
func (*DataViewObject) GetBuffer ¶ added in v0.9.9
func (dv *DataViewObject) GetBuffer() *ArrayBufferObject
GetBuffer returns the underlying buffer as an ArrayBufferObject
func (*DataViewObject) GetBufferData ¶ added in v0.9.9
func (dv *DataViewObject) GetBufferData() BufferData
GetBufferData returns the underlying buffer (ArrayBuffer or SharedArrayBuffer)
func (*DataViewObject) GetByteLength ¶ added in v0.9.9
func (dv *DataViewObject) GetByteLength() int
GetByteLength returns the byte length of the view
func (*DataViewObject) GetByteOffset ¶ added in v0.9.9
func (dv *DataViewObject) GetByteOffset() int
GetByteOffset returns the byte offset into the buffer
func (*DataViewObject) GetFloat32 ¶ added in v0.9.9
func (dv *DataViewObject) GetFloat32(byteOffset int, littleEndian bool) (float32, bool)
GetFloat32 reads a 32-bit float at the specified byte offset
func (*DataViewObject) GetFloat64 ¶ added in v0.9.9
func (dv *DataViewObject) GetFloat64(byteOffset int, littleEndian bool) (float64, bool)
GetFloat64 reads a 64-bit float at the specified byte offset
func (*DataViewObject) GetInt8 ¶ added in v0.9.9
func (dv *DataViewObject) GetInt8(byteOffset int) (int8, bool)
GetInt8 reads a signed 8-bit integer at the specified byte offset
func (*DataViewObject) GetInt16 ¶ added in v0.9.9
func (dv *DataViewObject) GetInt16(byteOffset int, littleEndian bool) (int16, bool)
GetInt16 reads a signed 16-bit integer at the specified byte offset
func (*DataViewObject) GetInt32 ¶ added in v0.9.9
func (dv *DataViewObject) GetInt32(byteOffset int, littleEndian bool) (int32, bool)
GetInt32 reads a signed 32-bit integer at the specified byte offset
func (*DataViewObject) GetSharedBuffer ¶ added in v0.9.9
func (dv *DataViewObject) GetSharedBuffer() *SharedArrayBufferObject
GetSharedBuffer returns the underlying SharedArrayBuffer, or nil if not shared
func (*DataViewObject) GetUint8 ¶ added in v0.9.9
func (dv *DataViewObject) GetUint8(byteOffset int) (uint8, bool)
GetUint8 reads an unsigned 8-bit integer at the specified byte offset
func (*DataViewObject) GetUint16 ¶ added in v0.9.9
func (dv *DataViewObject) GetUint16(byteOffset int, littleEndian bool) (uint16, bool)
GetUint16 reads an unsigned 16-bit integer at the specified byte offset
func (*DataViewObject) GetUint32 ¶ added in v0.9.9
func (dv *DataViewObject) GetUint32(byteOffset int, littleEndian bool) (uint32, bool)
GetUint32 reads an unsigned 32-bit integer at the specified byte offset
func (*DataViewObject) IsSharedBuffer ¶ added in v0.9.9
func (dv *DataViewObject) IsSharedBuffer() bool
IsSharedBuffer returns true if the underlying buffer is a SharedArrayBuffer
func (*DataViewObject) SetBigInt64 ¶ added in v0.9.9
SetBigInt64 writes a signed 64-bit integer at the specified byte offset
func (*DataViewObject) SetBigUint64 ¶ added in v0.9.9
SetBigUint64 writes an unsigned 64-bit integer at the specified byte offset
func (*DataViewObject) SetFloat32 ¶ added in v0.9.9
func (dv *DataViewObject) SetFloat32(byteOffset int, value float32, littleEndian bool) bool
SetFloat32 writes a 32-bit float at the specified byte offset
func (*DataViewObject) SetFloat64 ¶ added in v0.9.9
func (dv *DataViewObject) SetFloat64(byteOffset int, value float64, littleEndian bool) bool
SetFloat64 writes a 64-bit float at the specified byte offset
func (*DataViewObject) SetInt8 ¶ added in v0.9.9
func (dv *DataViewObject) SetInt8(byteOffset int, value int8) bool
SetInt8 writes a signed 8-bit integer at the specified byte offset
func (*DataViewObject) SetInt16 ¶ added in v0.9.9
func (dv *DataViewObject) SetInt16(byteOffset int, value int16, littleEndian bool) bool
SetInt16 writes a signed 16-bit integer at the specified byte offset
func (*DataViewObject) SetInt32 ¶ added in v0.9.9
func (dv *DataViewObject) SetInt32(byteOffset int, value int32, littleEndian bool) bool
SetInt32 writes a signed 32-bit integer at the specified byte offset
func (*DataViewObject) SetUint8 ¶ added in v0.9.9
func (dv *DataViewObject) SetUint8(byteOffset int, value uint8) bool
SetUint8 writes an unsigned 8-bit integer at the specified byte offset
type DictObject ¶
type DictObject struct {
Object
// contains filtered or unexported fields
}
func AsDictObject ¶
func AsDictObject(v Value) *DictObject
AsDictObject returns the DictObject pointer from a DictObject value.
func (*DictObject) DeleteOwn ¶
func (d *DictObject) DeleteOwn(name string) bool
DeleteOwn deletes an own property. Returns true if deleted.
func (*DictObject) Get ¶
func (d *DictObject) Get(name string) (Value, bool)
Get looks up a property by name, walking the prototype chain if necessary.
func (*DictObject) GetOwn ¶
func (d *DictObject) GetOwn(name string) (Value, bool)
GetOwn looks up a direct property by name. Returns (value, true) if present.
func (*DictObject) GetOwnDescriptor ¶
GetOwnDescriptor for DictObject returns default data property attributes (true, true, true) if present.
func (*DictObject) GetPrototype ¶
func (d *DictObject) GetPrototype() Value
GetPrototype returns the object's prototype.
func (*DictObject) Has ¶
func (d *DictObject) Has(name string) bool
Has reports whether a property with the given name exists (own or inherited).
func (*DictObject) HasOwn ¶
func (d *DictObject) HasOwn(name string) bool
HasOwn reports whether an own property with the given name exists.
func (*DictObject) IsExtensible ¶
func (d *DictObject) IsExtensible() bool
IsExtensible returns whether new properties can be added to this object
func (*DictObject) IsOwnPropertyNonConfigurable ¶
func (d *DictObject) IsOwnPropertyNonConfigurable(name string) (exists bool, nonConfigurable bool)
IsOwnPropertyNonConfigurable returns (exists, nonConfigurable) for an own property. DictObject properties are always configurable, so nonConfigurable is always false.
func (*DictObject) OwnKeys ¶
func (d *DictObject) OwnKeys() []string
OwnKeys returns the list of own property names. Per ECMAScript spec, integer indices come first (in ascending numeric order), then string keys in their lexicographic order (DictObject doesn't preserve insertion order).
func (*DictObject) OwnPropertyNames ¶
func (d *DictObject) OwnPropertyNames() []string
OwnPropertyNames returns the sorted list of own property names (alias for OwnKeys as DictObject has no non-enumerable props).
func (*DictObject) SetExtensible ¶
func (d *DictObject) SetExtensible(extensible bool)
SetExtensible sets the extensible flag for this object
func (*DictObject) SetOwn ¶
func (d *DictObject) SetOwn(name string, v Value)
SetOwn sets or defines an own property.
func (*DictObject) SetPrototype ¶
func (d *DictObject) SetPrototype(proto Value) bool
SetPrototype sets the object's prototype.
type EvalDriver ¶
type EvalDriver interface {
// EvalCode compiles and executes eval code with the given strict mode inheritance
// Returns (result, errors) - errors is empty on success
// This is used for indirect eval (no caller scope access)
EvalCode(code string, inheritStrict bool) (Value, []error)
// DirectEvalCode compiles and executes direct eval code with access to caller's scope
// scopeDesc contains the name→register mapping for the caller's local variables
// callerRegs is the caller's register array (allows read/write access to locals)
// callerThis is the 'this' value from the caller's execution context
// callerHomeObject is the [[HomeObject]] for super property access
// Returns (result, errors) - errors is empty on success
DirectEvalCode(code string, inheritStrict bool, scopeDesc *ScopeDescriptor, callerRegs []Value, callerThis Value, callerHomeObject Value) (Value, []error)
}
EvalDriver interface for eval() compilation without circular imports This is set by the driver during VM initialization
type ExceptionError ¶
ExceptionError is an interface for errors that should be thrown as VM exceptions
type ExceptionHandler ¶
type ExceptionHandler struct {
TryStart int // PC where try block starts (inclusive)
TryEnd int // PC where try block ends (exclusive)
HandlerPC int // Where to jump when exception caught
CatchReg int // Register to store exception (-1 if finally only)
IsCatch bool // true for catch, false for finally
IsFinally bool // true for finally blocks (Phase 3)
IsIteratorCleanup bool // true for for-of iterator cleanup (only triggered by exceptions, not returns)
FinallyReg int // Register to store pending action/value (-1 if not needed)
}
ExceptionHandler represents an entry in the exception table
type ExceptionState ¶
type ExceptionState struct {
// contains filtered or unexported fields
}
Exception state fields for VM (these will be added to the VM struct in vm.go)
type ExecutionContext ¶
type ExecutionContext struct {
// contains filtered or unexported fields
}
ExecutionContext saves the complete VM state for recursive execution
type ExtendedCacheStats ¶
type ExtendedCacheStats struct {
// Basic stats
TotalHits uint64
TotalMisses uint64
MonomorphicHits uint64
PolymorphicHits uint64
MegamorphicHits uint64
// Prototype chain stats
ProtoChainHits uint64
ProtoChainMisses uint64
ProtoDepth1Hits uint64 // Direct prototype hits
ProtoDepth2Hits uint64 // Prototype.prototype hits
ProtoDepthNHits uint64 // Deeper prototype hits
// Detailed stats (when EnableDetailedCacheStats is true)
PrimitiveMethodHits uint64 // String.prototype, Array.prototype method hits
FunctionProtoHits uint64 // Function.prototype method hits
BoundMethodCached uint64 // Number of bound methods cached
}
ExtendedCacheStats includes prototype-specific statistics
func GetExtendedStats ¶
func GetExtendedStats() ExtendedCacheStats
GetExtendedStats returns a copy of the current extended cache statistics Note: This only returns the extended prototype stats, not the VM's basic cache stats
func GetExtendedStatsFromVM ¶
func GetExtendedStatsFromVM(vm *VM) ExtendedCacheStats
GetExtendedStatsFromVM returns extended stats combined with VM's basic cache stats
type FunctionObject ¶
type FunctionObject struct {
Object
Arity int // Number of declared parameters (used for VM register allocation)
Length int // ECMAScript length property (params before first default, per spec)
Variadic bool
Chunk *Chunk
Name string
UpvalueCount int
RegisterSize int
IsGenerator bool // True for generator functions (function*)
IsAsync bool // True for async functions
IsArrowFunction bool // True for arrow functions (cannot be used as constructors)
IsDerivedConstructor bool // True for derived class constructors (must call super())
IsClassConstructor bool // True for class constructors (calling without 'new' throws TypeError)
Properties *PlainObject // For properties like .prototype (created lazily)
Prototype Value // [[Prototype]] - the function's prototype (usually Function.prototype)
HomeObject Value // [[HomeObject]] - object where method is defined (for super property access)
HomeRealm *Realm // [[Realm]] - the realm where this function was created
NameBindingRegister int // For named function expressions: register to initialize with closure (-1 if not used)
// Deleted intrinsic property tracking - these are configurable:true so can be deleted
DeletedName bool // True if the 'name' property has been deleted
DeletedLength bool // True if the 'length' property has been deleted
// HasLocalCaptures indicates if any nested closure captures locals from this function.
// When false, closeUpvalues can be skipped entirely on return (major performance win).
// Set at compile time when emitting OpClosure with CaptureFromRegister or CaptureFromSpill.
HasLocalCaptures bool
// contains filtered or unexported fields
}
func AsFunction ¶
func AsFunction(v Value) *FunctionObject
AsFunction returns the FunctionObject pointer from a function template value.
func (*FunctionObject) GetOrCreatePrototype ¶ added in v0.9.3
func (fn *FunctionObject) GetOrCreatePrototype() Value
GetOrCreatePrototype lazily creates and returns the function's prototype property
func (*FunctionObject) GetOrCreatePrototypeWithVM ¶ added in v0.9.3
func (fn *FunctionObject) GetOrCreatePrototypeWithVM(vm *VM) Value
GetOrCreatePrototypeWithVM lazily creates and returns the function's prototype property, using the VM's prototypes for proper inheritance chain setup.
type GeneratorFrame ¶
type GeneratorFrame = SuspendedFrame
GeneratorFrame is an alias for backwards compatibility
type GeneratorObject ¶
type GeneratorObject struct {
Object
Function Value // The generator function
State GeneratorState // Current state (suspended/completed/executing)
Frame *SuspendedFrame // Execution frame (nil if completed)
YieldedValue Value // Last yielded value
ReturnValue Value // Final return value (when completed)
Done bool // True when generator is exhausted
Args []Value // Arguments passed when the generator was created
This Value // The 'this' value for the generator context
Prototype *PlainObject // Custom prototype (if set via function.prototype)
DelegatedIterator Value // Iterator being delegated to (for yield* forwarding of .return()/.throw())
DelegationResult Value // Result value when delegation completed via external throw/return with done:true
DelegationResultReady bool // Flag indicating DelegationResult is set (needed because result could be undefined)
}
GeneratorObject represents a JavaScript generator instance Based on the design from generators-implementation-plan.md
type GeneratorState ¶
type GeneratorState int
GeneratorState represents the execution state of a generator This allows the generator to resume execution from where it left off
const ( GeneratorStart GeneratorState = iota // Just created, prologue not yet executed GeneratorSuspendedStart // Prologue executed, ready for first .next() GeneratorSuspendedYield // Suspended at a yield expression GeneratorExecuting // Currently executing GeneratorCompleted // Completed (returned or threw) )
func (GeneratorState) String ¶
func (gs GeneratorState) String() string
String returns a human-readable name for the generator state
type Heap ¶
type Heap struct {
// contains filtered or unexported fields
}
Heap represents a unified global variable storage for the VM. This replaces the module-specific global tables with a single shared heap that all modules and the main program can access consistently.
func (*Heap) ClearUserGlobals ¶
func (h *Heap) ClearUserGlobals()
ClearUserGlobals resets user-defined globals while preserving builtin globals This is used by VM.Reset() to prevent memory leaks without destroying builtins
func (*Heap) CloneLayout ¶ added in v0.9.9
CloneLayout creates a new Heap with the same nameToIndex mapping and size, but with all value slots uninitialized. This is used for realm isolation: compiled bytecode references globals by index, so the new heap must have the same layout. But since values are separate, writes go to the new realm's storage.
func (*Heap) Delete ¶
Delete removes a global variable at the specified index if it's configurable Returns true if deletion succeeded, false if not configurable or doesn't exist
func (*Heap) Get ¶
Get retrieves a value from the heap at the specified index Returns (value, true) if the slot exists AND has been initialized Returns (Undefined, false) if the slot doesn't exist OR hasn't been initialized
func (*Heap) GetNameByIndex ¶
GetNameByIndex returns the name of a global variable by its heap index Returns empty string if the index doesn't have a name mapping
func (*Heap) GetNameToIndex ¶
GetNameToIndex returns the current name->index mapping (if available)
func (*Heap) IsConfigurable ¶
IsConfigurable returns whether a global variable at the specified index can be deleted
func (*Heap) IsWritable ¶ added in v0.9.9
IsWritable returns whether a global variable at the specified index can be assigned to
func (*Heap) SetBuiltinGlobals ¶
SetBuiltinGlobals initializes the heap with builtin global variables This replaces the old SetBuiltinGlobals method on VM
func (*Heap) SetConfigurable ¶
SetConfigurable sets whether a global variable at the specified index can be deleted
func (*Heap) SetWritable ¶ added in v0.9.9
SetWritable sets whether a global variable at the specified index can be assigned to
func (*Heap) UpdateNameToIndex ¶
UpdateNameToIndex merges new name->index mappings into the heap's mapping This is called after compilation to sync user-defined global names from the compiler
type ICacheStats ¶
type ICacheStats struct {
// contains filtered or unexported fields
}
ICacheStats holds statistics about inline cache performance
type InterpretResult ¶
type InterpretResult uint8
InterpretResult represents the outcome of an interpretation.
const ( InterpretOK InterpretResult = iota InterpretCompileError InterpretRuntimeError )
type MapObject ¶
type MapObject struct {
Object
Properties *PlainObject // User-defined properties on the Map object
// contains filtered or unexported fields
}
func (*MapObject) ForEach ¶
ForEach calls fn for each entry in the map in insertion order. Skips entries that have been deleted (tombstones in order array).
func (*MapObject) GetEntryAt ¶ added in v0.9.8
GetEntryAt returns the key-value pair at the given index in insertion order. Returns (key, value, true) if the entry exists, or (Undefined, Undefined, false) if the index is out of bounds or the entry was deleted. Used by live iterators.
type ModuleContext ¶
type ModuleContext struct {
// contains filtered or unexported fields
}
ModuleContext represents a cached module execution context
type ModuleLoader ¶
type ModuleLoader interface {
LoadModule(specifier string, fromPath string) (ModuleRecord, error)
}
ModuleLoader interface for loading modules without circular imports
type ModuleRecord ¶
type ModuleRecord interface {
GetExportValues() map[string]Value
GetExportIndices() map[string]uint16
GetCompiledChunk() *Chunk
GetExportNames() []string
GetError() error
IsJSONModule() bool
GetSource() string
}
ModuleRecord interface to avoid circular imports
type NativeFunctionObject ¶
type NativeFunctionObject struct {
Object
Arity int
Variadic bool
Name string
Fn func(args []Value) (Value, error)
IsConstructor bool // If true, can be used with 'new'; false by default for most native functions
Properties *PlainObject // Lazily created when user code sets properties on this function
HomeRealm *Realm // [[Realm]] - the realm where this function was created
DeletedName bool // True if the 'name' property has been deleted
DeletedLength bool // True if the 'length' property has been deleted
}
NativeFunctionObject represents a native Go function callable from Paserati.
func AsNativeFunction ¶
func AsNativeFunction(v Value) *NativeFunctionObject
AsNativeFunction returns the NativeFunctionObject pointer from a native function value.
type NativeFunctionObjectWithProps ¶
type NativeFunctionObjectWithProps struct {
Object
Arity int
Variadic bool
Name string
Fn func(args []Value) (Value, error)
Properties *PlainObject // Can have properties like static methods
IsConstructor bool // If true, can be used with 'new'; most built-in constructors set this to true
HomeRealm *Realm // [[Realm]] - the realm where this function was created
DeletedName bool // True if the 'name' property has been deleted
DeletedLength bool // True if the 'length' property has been deleted
}
NativeFunctionObjectWithProps represents a native function that can also have properties This is useful for constructors that need static methods (like String.fromCharCode)
type OpCode ¶
type OpCode uint8
OpCode defines the type for bytecode instructions.
const ( // OpNop MUST be 0 - used for self-modifying TDZ checks (rewrite to 0 = no-op) OpNop OpCode = 0 // No operation - skip to next instruction OpLoadConst OpCode = 1 // Rx ConstIdx: Load constant Constants[ConstIdx] into register Rx. OpLoadNull OpCode = 2 // Rx: Load null value into register Rx. OpLoadUndefined OpCode = 3 // Rx: Load undefined value into register Rx. OpLoadTrue OpCode = 4 // Rx: Load boolean true into register Rx. OpLoadFalse OpCode = 5 // Rx: Load boolean false into register Rx. OpMove OpCode = 6 // Rx Ry: Move value from register Ry into register Rx. // Arithmetic (Dest, Left, Right) OpAdd OpCode = 7 // Rx Ry Rz: Rx = Ry + Rz OpSubtract OpCode = 8 // Rx Ry Rz: Rx = Ry - Rz OpMultiply OpCode = 9 // Rx Ry Rz: Rx = Ry * Rz OpDivide OpCode = 10 // Rx Ry Rz: Rx = Ry / Rz // --- NEW: String Operations --- OpStringConcat OpCode = 49 // Rx Ry Rz: Rx = Ry + Rz (optimized string concatenation) // Unary OpNegate OpCode = 11 // Rx Ry: Rx = -Ry OpNot OpCode = 12 // Rx Ry: Rx = !Ry (logical not) OpTypeof OpCode = 48 // Rx Ry: Rx = typeof Ry (returns string) OpToNumber OpCode = 50 // Rx Ry: Rx = Number(Ry) (unary plus conversion) OpToNumeric OpCode = 123 // Rx Ry: Rx = ToNumeric(Ry) (preserves BigInt, converts others to Number) OpLoadNumericOne OpCode = 124 // Rx Ry: If Ry is BigInt, Rx = 1n; else Rx = 1 (for ++/-- operators) // Comparison (Result Dest, Left, Right) -> Result is boolean OpEqual OpCode = 13 // Rx Ry Rz: Rx = (Ry == Rz) OpNotEqual OpCode = 14 // Rx Ry Rz: Rx = (Ry != Rz) OpStrictEqual OpCode = 15 // Rx Ry Rz: Rx = (Ry === Rz) OpStrictNotEqual OpCode = 16 // Rx Ry Rz: Rx = (Ry !== Rz) OpGreater OpCode = 17 // Rx Ry Rz: Rx = (Ry > Rz) OpLess OpCode = 18 // Rx Ry Rz: Rx = (Ry < Rz) OpLessEqual OpCode = 19 // Rx Ry Rz: Rx = (Ry <= Rz) OpGreaterEqual OpCode = 89 // Rx Ry Rz: Rx = (Ry >= Rz) OpDefineMethod OpCode = 90 // ObjReg ValueReg NameIdx(16bit): Define non-enumerable method on object OpIn OpCode = 59 // Rx Ry Rz: Rx = (Ry in Rz) - property existence check OpInstanceof OpCode = 61 // Rx Ry Rz: Rx = (Ry instanceof Rz) - instance check // --- NEW: Remainder and Exponent Opcodes --- OpRemainder OpCode = 31 // Rx Ry Rz: Rx = Ry % Rz (Assuming next available number) OpExponent OpCode = 32 // Rx Ry Rz: Rx = Ry ** Rz (Assuming next available number) // Function/Call related OpCall OpCode = 20 // Rx FuncReg ArgCount: Call function in FuncReg with ArgCount args, result in Rx OpReturn OpCode = 21 // Rx: Return value from register Rx. OpNew OpCode = 45 // Rx ConstructorReg ArgCount Flags: Create new instance, Flags bit0=inherit new.target OpSpreadNew OpCode = 83 // Rx ConstructorReg SpreadArgReg Flags: Create new instance, Flags bit0=inherit new.target OpTailCall OpCode = 109 // Rx FuncReg ArgCount: Tail call (frame reuse) OpTailCallMethod OpCode = 110 // Rx FuncReg ThisReg ArgCount: Tail call method (frame reuse with this) // Closure related OpClosure OpCode = 22 // Rx FuncConstIdx UpvalueCount [IsLocal1 Index1 IsLocal2 Index2 ...]: Create closure for function Const[FuncConstIdx] with UpvalueCount upvalues, store in Rx. OpLoadFree OpCode = 23 // Rx UpvalueIndex: Load free variable (upvalue) at index UpvalueIndex into register Rx. OpSetUpvalue OpCode = 24 // UpvalueIndex Ry: Store value from register Ry into upvalue at index UpvalueIndex. OpReturnUndefined OpCode = 25 // No operands: Return undefined value from current function. // Control Flow OpJumpIfFalse OpCode = 26 // Rx Offset(16bit): Jump by Offset if Rx is falsey. OpJump OpCode = 27 // Offset(16bit): Unconditionally jump by Offset. // Array Operations (NEW) OpMakeArray OpCode = 28 // DestReg StartReg Count: Create array in DestReg from Count values starting at StartReg. OpGetIndex OpCode = 29 // DestReg ArrayReg IndexReg: DestReg = ArrayReg[IndexReg] OpSetIndex OpCode = 30 // ArrayReg IndexReg ValueReg: ArrayReg[IndexReg] = ValueReg OpGetLength OpCode = 140 // DestReg SrcReg: DestReg = length(SrcReg) // --- NEW: Bitwise & Shift --- OpBitwiseNot OpCode = 33 // Rx Ry: Rx = ~Ry OpBitwiseAnd OpCode = 34 // Rx Ry Rz: Rx = Ry & Rz OpBitwiseOr OpCode = 35 // Rx Ry Rz: Rx = Ry | Rz OpBitwiseXor OpCode = 36 // Rx Ry Rz: Rx = Ry ^ Rz OpShiftLeft OpCode = 37 // Rx Ry Rz: Rx = Ry << Rz OpShiftRight OpCode = 38 // Rx Ry Rz: Rx = Ry >> Rz (Arithmetic Shift) OpUnsignedShiftRight OpCode = 39 // Rx Ry Rz: Rx = Ry >>> Rz (Logical Shift) // --- NEW: Object Operations --- OpMakeEmptyObject OpCode = 40 // Rx: Creates an empty object in Rx OpGetProp OpCode = 41 // Rx Ry NameIdx(16bit): Rx = Ry[NameIdx] OpSetProp OpCode = 42 // Rx Ry NameIdx(16bit): Rx[NameIdx] = Ry (Object in Rx, Value in Ry) OpDeleteProp OpCode = 62 // Rx Ry NameIdx(16bit): Rx = delete Ry[NameIdx] (returns boolean) OpDeleteIndex OpCode = 79 // Rx Ry Rz: Rx = delete Ry[Rz] (returns boolean) OpDeleteGlobal OpCode = 86 // Rx HeapIdx(16bit): Rx = delete global[HeapIdx] (returns boolean) OpToPropertyKey OpCode = 87 // Rx Ry: Rx = ToPropertyKey(Ry) - converts value to property key (string), calling toString() if needed OpTypeofIdentifier OpCode = 88 // Rx NameIdx(16bit): Rx = typeof identifier - returns "undefined" if identifier doesn't exist (no ReferenceError) // --- Private Field Operations (ECMAScript # fields) --- OpGetPrivateField OpCode = 91 // Rx Ry NameIdx(16bit): Rx = Ry.#field (private field access) OpSetPrivateField OpCode = 92 // Rx Ry NameIdx(16bit): Rx.#field = Ry (private field assignment) OpSetPrivateMethod OpCode = 98 // Rx Ry NameIdx(16bit): Rx.#method = Ry (private method - not writable) OpHasPrivateField OpCode = 99 // Rx Ry NameIdx(16bit): Rx = #field in Ry (check private field presence) OpSetPrivateAccessor OpCode = 106 // Rx GetterReg SetterReg NameIdx(16bit): Set up private getter/setter on Rx OpCallPrivateSetter OpCode = 161 // Rx Ry NameIdx(16bit): Rx.#setter = Ry (calls setter, throws if not exist) // --- Type Guards for Runtime Validation --- OpTypeGuardIterable OpCode = 93 // Rx: Throw TypeError if Rx is not iterable OpTypeGuardIteratorReturn OpCode = 94 // Rx: Throw TypeError if Rx (iterator.return() result) is not an object // --- NEW: Method Calls and This Context --- OpCallMethod OpCode = 43 // Rx FuncReg ThisReg ArgCount: Call method in FuncReg with ThisReg as 'this', result in Rx OpLoadThis OpCode = 44 // Rx: Load 'this' value from current call context into register Rx OpLoadSuper OpCode = 111 // Rx: Load super base (homeObject.prototype) into register Rx (for super property access) OpGetSuper OpCode = 112 // Rx NameIdx(16bit): Rx = super.propertyName (super property access with static name) OpSetSuper OpCode = 113 // NameIdx(16bit) ValueReg: super.propertyName = ValueReg (super property assignment with static name) OpGetSuperComputed OpCode = 114 // Rx KeyReg: Rx = super[KeyReg] (super property access with computed key) OpSetSuperComputed OpCode = 115 // KeyReg ValueReg: super[KeyReg] = ValueReg (super property assignment with computed key) OpSetSuperComputedWithBase OpCode = 137 // BaseReg KeyReg ValueReg: super[KeyReg] = ValueReg with explicit super base (for correct evaluation order) OpGetSuperConstructor OpCode = 138 // Rx: Get the [[Prototype]] of the current function (for super() calls) OpLoadUninitialized OpCode = 139 // Rx: Load TDZ uninitialized marker into register Rx (for let/const before initialization) OpCheckUninitialized OpCode = 141 // Rx: Check if register Rx is uninitialized (TDZ), throw ReferenceError if so. Self-rewrites to OpNop on success. OpCloseUpvalue OpCode = 142 // Rx: Close any open upvalue pointing to register Rx (for per-iteration bindings in for loops) OpIteratorCleanupAbrupt OpCode = 143 // IteratorReg: Call iterator.return() with error suppression (for exception cleanup per ECMAScript IteratorClose with throw completion) OpIteratorCleanupAbruptIfNotDone OpCode = 155 // IteratorReg DoneReg: Only call iterator.return() if done is false (per spec: don't close if iteration itself threw) OpDefineMethodComputed OpCode = 116 // ObjReg ValueReg KeyReg: Define non-enumerable method on object with computed key (sets [[HomeObject]]) OpDefineMethodEnumerable OpCode = 117 // ObjReg ValueReg NameIdx(16bit): Define enumerable method on object (for object literals, sets [[HomeObject]]) OpDefineMethodComputedEnumerable OpCode = 122 // ObjReg ValueReg KeyReg: Define enumerable method on object with computed key (sets [[HomeObject]], for object literals) OpDefineDataProperty OpCode = 125 // ObjReg ValueReg NameIdx(16bit): Define enumerable data property on object (uses DefineOwnProperty, for object literals) OpDefineComputedDataProperty OpCode = 146 // ObjReg ValueReg KeyReg: Define enumerable data property on object with computed key (uses DefineOwnProperty, for object literals) // --- Direct Eval Support --- OpDirectEval OpCode = 126 // Rx CodeReg: Execute direct eval with code string in CodeReg, result in Rx (inherits caller's strict mode and scope) // --- Caller Scope Access (for direct eval) --- OpGetCallerLocal OpCode = 127 // Rx CallerRegIdx: Load value from caller's register into Rx OpSetCallerLocal OpCode = 128 // CallerRegIdx Rx: Store value from Rx into caller's register // --- With Statement Support --- OpPushWithObject OpCode = 118 // ObjReg: Push object onto VM's with-object stack OpPopWithObject OpCode = 119 // No operands: Pop object from VM's with-object stack OpGetWithProperty OpCode = 120 // Rx NameIdx(16bit): Try to get property from with-object stack, fallback to global lookup OpSetWithProperty OpCode = 121 // NameIdx(16bit) ValueReg: Try to set property on with-object stack, fallback to global assignment OpGetWithOrLocal OpCode = 156 // Rx NameIdx(16bit) LocalReg: Try with-object, fallback to LocalReg (for shadowed locals) OpSetWithOrLocal OpCode = 157 // NameIdx(16bit) ValueReg LocalReg: Set on with-object if exists, else set LocalReg // Reference binding capture (for correct assignment semantics - binding captured BEFORE RHS evaluation) OpResolveWithBinding OpCode = 158 // Rx NameIdx(16bit) LocalReg: Capture binding - Rx = with-object index (or 255 for local) OpSetWithByBinding OpCode = 159 // NameIdx(16bit) ValueReg LocalReg BindingReg: Set using pre-resolved binding OpGetWithByBinding OpCode = 162 // Rx NameIdx(16bit) LocalReg BindingReg: Get using pre-resolved binding OpDeleteWithProperty OpCode = 160 // Rx NameIdx(16bit) Fallback: Delete from with-object, Fallback=0:true, 1:false // --- RegExp Creation --- OpMakeRegExp OpCode = 163 // Rx PatternIdx(16bit) FlagsIdx(16bit): Create new RegExp from pattern and flags constants // --- Function Name Setting --- // Per ECMAScript DefineField step 7: set name of anonymous function assigned to field OpSetFunctionName OpCode = 164 // Rx NameIdx(16bit): If Rx is a function without a name, set its name to constants[NameIdx] // --- With Statement Call Support --- // Per ECMAScript 12.3.4.1: When calling a function resolved from a with environment, // the thisValue should be the with base object (refEnv.WithBaseObject()) OpCallFromWithContext OpCode = 165 // Dest NameIdx(16bit) LocalReg FuncReg ArgCount: Call with proper 'this' based on with context OpSetThis OpCode = 82 // Ry: Set 'this' value in current call context from register Ry OpLoadNewTarget OpCode = 81 // Rx: Load 'new.target' value from current call context into register Rx // --- Decorator Support --- OpMakeAddInitializer OpCode = 166 // Rx Ry: Create addInitializer function in Rx that pushes to array in Ry OpRunInitializers OpCode = 167 // Rx ThisReg: Run all initializer functions in array Rx with 'this' = ThisReg // --- NEW: Global Variable Operations --- OpGetGlobal OpCode = 46 // Rx GlobalIdx(16bit): Rx = Globals[GlobalIdx] (direct indexed access) OpSetGlobal OpCode = 47 // GlobalIdx(16bit) Ry: Globals[GlobalIdx] = Ry (direct indexed access) OpSetGlobalInit OpCode = 145 // GlobalIdx(16bit) Ry: Globals[GlobalIdx] = Ry (init at declaration, bypasses TDZ check) // --- NEW: Efficient Nullish Checks --- OpIsNull OpCode = 51 // Rx Ry: Rx = (Ry === null) - efficient null check OpIsUndefined OpCode = 52 // Rx Ry: Rx = (Ry === undefined) - efficient undefined check OpIsNullish OpCode = 53 // Rx Ry: Rx = (Ry === null || Ry === undefined) - efficient nullish check // Jump variants for control flow optimization OpJumpIfNull OpCode = 54 // Ry Offset(16bit): Jump if Ry === null OpJumpIfUndefined OpCode = 55 // Ry Offset(16bit): Jump if Ry === undefined OpJumpIfNullish OpCode = 56 // Ry Offset(16bit): Jump if Ry is null or undefined // --- NEW: Spread Call Support --- OpSpreadCall OpCode = 57 // Rx FuncReg SpreadArgReg: Call function with spread array as arguments, result in Rx OpSpreadCallMethod OpCode = 58 // Rx FuncReg ThisReg SpreadArgReg: Call method with spread array as arguments, result in Rx // --- NEW: Object Enumeration Support --- OpGetOwnKeys OpCode = 60 // Rx Ry: Get own enumerable property names of object in Ry, store array in Rx // --- NEW: Array Slice Support for Rest Elements --- OpArraySlice OpCode = 63 // Rx Ry Rz: Rx = Ry.slice(Rz) - slice array from start index // --- NEW: Array Spread Support --- OpArraySpread OpCode = 68 // Rx Ry: Append all elements from array in Ry to array in Rx // --- NEW: Object Spread Support --- OpObjectSpread OpCode = 69 // Rx Ry: Copy all enumerable properties from object in Ry to object in Rx // --- NEW: Object Copy Support for Rest Properties --- OpCopyObjectExcluding OpCode = 64 // Rx Ry Rz: Rx = copy Ry excluding properties in array Rz // --- Exception Handling --- OpThrow OpCode = 65 // Rx: Throw exception in register Rx // --- Phase 4a: Return in Finally --- OpReturnFinally OpCode = 66 // Rx: Return value from register Rx (finally context) // --- Phase 4a: Handle Pending Actions --- OpHandlePending OpCode = 67 // Handle pending actions after finally block OpPushBreak OpCode = 107 // TargetPC(16): Push break completion for try-finally OpPushContinue OpCode = 108 // TargetPC(16): Push continue completion for try-finally // --- Module System --- OpEvalModule OpCode = 70 // ModulePathIdx: Execute module idempotently, switch execution context OpGetModuleExport OpCode = 71 // Rx ModulePathIdx ExportNameIdx: Rx = module[exportName] OpCreateNamespace OpCode = 72 // Rx ModulePathIdx: Create namespace object from module exports, store in Rx // --- Arguments Object --- OpGetArguments OpCode = 73 // Rx: Create arguments object from current function arguments, store in Rx // --- Generator Support --- OpCreateGenerator OpCode = 74 // Rx FuncReg: Create generator object from function in FuncReg, store in Rx OpYield OpCode = 75 // Rx, Ry: Suspend generator execution, yield value in Rx, store sent value in Ry OpResumeGenerator OpCode = 76 // Internal: Resume generator execution (used by .next() calls) OpYieldDelegated OpCode = 100 // ResultReg, OutputReg, IteratorReg: Suspend generator for yield*, yield result as-is, store sent value in OutputReg, save iterator in IteratorReg for .return()/.throw() forwarding OpInitYield OpCode = 101 // No operands: Mark end of generator initialization prologue (executed during construction) // --- Async/Await Support --- OpAwait OpCode = 95 // Rx, PromiseReg: Await promise in PromiseReg, store result in Rx when resolved // --- Module Support --- OpLoadImportMeta OpCode = 96 // Rx: Load 'import.meta' object from current module context into register Rx OpDynamicImport OpCode = 97 // Rx SpecifierReg: Dynamically import module at runtime (specifier in SpecifierReg), store namespace in Rx // --- Large Literal Support --- OpAllocArray OpCode = 77 // Rx Len(16bit): Preallocate array of length Len into Rx, filled with undefined OpArrayCopy OpCode = 78 // Rx DestOffset(16bit) StartReg Count: Copy Count registers starting at StartReg into Rx at DestOffset // --- Accessor Property Support --- OpDefineAccessor OpCode = 80 // ObjReg GetterReg SetterReg NameIdx(16bit): Define accessor property on object OpDefineAccessorDynamic OpCode = 84 // ObjReg GetterReg SetterReg NameReg: Define accessor property with dynamic name // --- Prototype Support --- OpSetPrototype OpCode = 85 // ObjReg ProtoReg: Set object's prototype to ProtoReg value (for __proto__ in object literals) OpSetClosureProto OpCode = 129 // ClosureReg ProtoReg: Set closure's internal [[Prototype]] (for class inheritance, C.__proto__ = B) // --- Register Spilling Support --- // When a function has more local variables than available registers (255 limit), // some variables are "spilled" to a spillSlots array. These opcodes load/store spilled values. OpLoadSpill OpCode = 130 // Rx SpillIdx: Load from spillSlots[SpillIdx] into register Rx (8-bit index) OpStoreSpill OpCode = 131 // SpillIdx Rx: Store register Rx into spillSlots[SpillIdx] (8-bit index) // 16-bit spill slot opcodes for functions with more than 255 spilled variables OpLoadSpill16 OpCode = 132 // Rx SpillIdxHi SpillIdxLo: Load from spillSlots[SpillIdx] into register Rx (16-bit index) OpStoreSpill16 OpCode = 133 // SpillIdxHi SpillIdxLo Rx: Store register Rx into spillSlots[SpillIdx] (16-bit index) // 16-bit upvalue count for closures with more than 255 captured variables OpClosure16 OpCode = 134 // Rx FuncConstIdx UpvalueCountHi UpvalueCountLo [CaptureType Index...]: Like OpClosure but with 16-bit upvalue count // 16-bit upvalue index for functions with more than 255 captured variables OpLoadFree16 OpCode = 135 // Rx UpvalueIdxHi UpvalueIdxLo: Load free variable (upvalue) at 16-bit index into register Rx OpSetUpvalue16 OpCode = 136 // UpvalueIdxHi UpvalueIdxLo Ry: Store value from register Ry into upvalue at 16-bit index // --- Class Validation --- OpValidateSuperclass OpCode = 144 // Rx: Validate that Rx is a valid superclass (callable constructor or null), throws TypeError if not )
Enum for Opcodes (Register Machine)
type PendingAction ¶
type PendingAction int
PendingAction represents actions that should be performed after finally blocks complete
const ( ActionNone PendingAction = iota ActionReturn ActionThrow ActionBreak // For break in try-finally blocks ActionContinue // For continue in try-finally blocks )
type PlainObject ¶
type PlainObject struct {
Object
// contains filtered or unexported fields
}
func AsPlainObject ¶
func AsPlainObject(v Value) *PlainObject
AsPlainObject returns the PlainObject pointer from an Object value.
func (*PlainObject) DefineAccessorProperty ¶
func (o *PlainObject) DefineAccessorProperty(name string, getter Value, hasGetter bool, setter Value, hasSetter bool, enumerable *bool, configurable *bool)
DefineAccessorProperty defines or updates an accessor own property.
func (*PlainObject) DefineAccessorPropertyByKey ¶
func (o *PlainObject) DefineAccessorPropertyByKey(key PropertyKey, getter Value, hasGetter bool, setter Value, hasSetter bool, enumerable *bool, configurable *bool)
DefineAccessorPropertyByKey defines or updates an accessor property for arbitrary key kinds.
func (*PlainObject) DefineOwnProperty ¶
func (o *PlainObject) DefineOwnProperty(name string, value Value, writable *bool, enumerable *bool, configurable *bool)
DefineOwnProperty defines or updates an own property with explicit attributes. For existing properties, unspecified attributes (nil) will keep previous values.
func (*PlainObject) DefineOwnPropertyByKey ¶
func (o *PlainObject) DefineOwnPropertyByKey(key PropertyKey, value Value, writable *bool, enumerable *bool, configurable *bool)
DefineOwnPropertyByKey defines or updates an own property for arbitrary key kinds.
func (*PlainObject) DeleteOwn ¶
func (o *PlainObject) DeleteOwn(name string) bool
DeleteOwn removes an own property if present and configurable. Returns true if the property was deleted.
func (*PlainObject) DeleteOwnByKey ¶
func (o *PlainObject) DeleteOwnByKey(key PropertyKey) bool
DeleteOwnByKey removes an own property by key if present and configurable.
func (*PlainObject) FreezeAllProperties ¶ added in v0.9.10
func (o *PlainObject) FreezeAllProperties()
FreezeAllProperties makes all own properties (including non-enumerable and symbol-keyed) non-configurable. Data properties also become non-writable. Accessor properties keep their getter/setter but become non-configurable.
func (*PlainObject) Get ¶
func (o *PlainObject) Get(name string) (Value, bool)
Get looks up a property by name, walking the prototype chain if necessary.
func (*PlainObject) GetOwn ¶
func (o *PlainObject) GetOwn(name string) (Value, bool)
GetOwn looks up a direct (own) property by name. Returns (value, true) if present.
func (*PlainObject) GetOwnAccessor ¶
GetOwnAccessor returns accessor pair for an own property if it is an accessor. Returns (get, set, enumerable, configurable, exists)
func (*PlainObject) GetOwnAccessorByKey ¶
func (o *PlainObject) GetOwnAccessorByKey(key PropertyKey) (Value, Value, bool, bool, bool)
GetOwnAccessorByKey returns accessor pair for an own property by key.
func (*PlainObject) GetOwnByKey ¶
func (o *PlainObject) GetOwnByKey(key PropertyKey) (Value, bool)
GetOwnByKey looks up a direct (own) property by key. Returns (value, true) if present.
func (*PlainObject) GetOwnDescriptor ¶
GetOwnDescriptor returns the value and attribute flags for an own property. Returns (value, writable, enumerable, configurable, exists).
func (*PlainObject) GetOwnDescriptorByKey ¶
func (o *PlainObject) GetOwnDescriptorByKey(key PropertyKey) (Value, bool, bool, bool, bool)
GetOwnDescriptorByKey returns descriptor flags for an own property keyed by PropertyKey.
func (*PlainObject) GetPrivateAccessor ¶
func (o *PlainObject) GetPrivateAccessor(name string) (Value, Value, bool)
GetPrivateAccessor retrieves a private getter/setter pair Returns (getter, setter, exists)
func (*PlainObject) GetPrivateField ¶
func (o *PlainObject) GetPrivateField(name string) (Value, bool)
GetPrivateField retrieves a private field value (ECMAScript # fields) Returns (value, true) if the field exists, (Undefined, false) otherwise
func (*PlainObject) GetPrivateMethod ¶
func (o *PlainObject) GetPrivateMethod(name string) (Value, bool)
GetPrivateMethod retrieves a private method value (ECMAScript # methods)
func (*PlainObject) GetPrototype ¶
func (o *PlainObject) GetPrototype() Value
GetPrototype returns the object's prototype.
func (*PlainObject) Has ¶
func (o *PlainObject) Has(name string) bool
Has reports whether a property with the given name exists (own or inherited).
func (*PlainObject) HasOwn ¶
func (o *PlainObject) HasOwn(name string) bool
HasOwn reports whether an own property with the given name exists.
func (*PlainObject) HasOwnByKey ¶
func (o *PlainObject) HasOwnByKey(key PropertyKey) bool
func (*PlainObject) HasPrivateField ¶
func (o *PlainObject) HasPrivateField(name string) bool
HasPrivateField checks if a private field exists
func (*PlainObject) IsExtensible ¶
func (o *PlainObject) IsExtensible() bool
IsExtensible returns whether new properties can be added to this object
func (*PlainObject) IsFrozenProperties ¶ added in v0.9.10
func (o *PlainObject) IsFrozenProperties() bool
IsFrozenProperty checks if all own properties are non-configurable and (for data properties) non-writable.
func (*PlainObject) IsModuleNamespace ¶ added in v0.9.9
func (o *PlainObject) IsModuleNamespace() bool
IsModuleNamespace returns true if this is a module namespace exotic object
func (*PlainObject) IsOwnPropertyNonConfigurable ¶
func (o *PlainObject) IsOwnPropertyNonConfigurable(name string) (exists bool, nonConfigurable bool)
IsOwnPropertyNonConfigurable returns (exists, nonConfigurable) for an own property. exists is true if the property exists on this object. nonConfigurable is true if the property exists and is not configurable.
func (*PlainObject) IsOwnPropertyNonConfigurableByKey ¶ added in v0.9.9
func (o *PlainObject) IsOwnPropertyNonConfigurableByKey(key PropertyKey) (exists bool, nonConfigurable bool)
IsOwnPropertyNonConfigurableByKey checks if a property exists and is non-configurable by key
func (*PlainObject) IsPrivateAccessor ¶
func (o *PlainObject) IsPrivateAccessor(name string) bool
IsPrivateAccessor checks if a private field is an accessor (has getter or setter)
func (*PlainObject) IsPrivateMethod ¶
func (o *PlainObject) IsPrivateMethod(name string) bool
IsPrivateMethod checks if a private method exists
func (*PlainObject) IsSealedProperties ¶ added in v0.9.10
func (o *PlainObject) IsSealedProperties() bool
IsSealedProperties checks if all own properties are non-configurable.
func (*PlainObject) OwnKeys ¶
func (o *PlainObject) OwnKeys() []string
OwnKeys returns the list of own enumerable string property names. Per ECMAScript spec, integer indices come first (in ascending numeric order), then string keys in insertion order.
func (*PlainObject) OwnPropertyNames ¶
func (o *PlainObject) OwnPropertyNames() []string
OwnPropertyNames returns the list of all own string property names (including non-enumerable). Per ECMAScript spec, integer indices come first (in ascending numeric order), then string keys in insertion order.
func (*PlainObject) OwnSymbolKeys ¶
func (o *PlainObject) OwnSymbolKeys() []Value
OwnSymbolKeys returns the list of own symbol keys in insertion order.
func (*PlainObject) SealAllProperties ¶ added in v0.9.10
func (o *PlainObject) SealAllProperties()
SealAllProperties makes all own properties (including non-enumerable and symbol-keyed) non-configurable, but preserves the writable attribute of data properties.
func (*PlainObject) SetExtensible ¶
func (o *PlainObject) SetExtensible(extensible bool)
SetExtensible sets the extensible flag for this object Per ECMAScript spec, once set to false, it cannot be set back to true
func (*PlainObject) SetImmutablePrototype ¶ added in v0.9.10
func (o *PlainObject) SetImmutablePrototype()
SetImmutablePrototype marks this object's prototype as immutable (ECMAScript 9.4.7).
func (*PlainObject) SetModuleNamespace ¶ added in v0.9.9
func (o *PlainObject) SetModuleNamespace(isNamespace bool)
SetModuleNamespace marks this object as a module namespace exotic object which has special [[Delete]] and [[Set]] behavior per ECMAScript 10.4.6
func (*PlainObject) SetOwn ¶
func (o *PlainObject) SetOwn(name string, v Value)
SetOwn sets or defines an own property. Creates a new shape on first definition. If the property exists and is non-writable, this is a no-op.
func (*PlainObject) SetOwnNonEnumerable ¶
func (o *PlainObject) SetOwnNonEnumerable(name string, v Value)
SetOwnNonEnumerable sets or defines an own property as non-enumerable (for built-in methods). Creates a new shape on first definition with enumerable: false, writable: true, configurable: true.
func (*PlainObject) SetPrivateAccessor ¶
func (o *PlainObject) SetPrivateAccessor(name string, getter Value, setter Value)
SetPrivateAccessor sets a private getter/setter pair (ECMAScript # accessor properties) Pass Undefined for getter or setter if not defined
func (*PlainObject) SetPrivateField ¶
func (o *PlainObject) SetPrivateField(name string, value Value)
SetPrivateField sets a private field value (ECMAScript # fields) Creates the privateFields map if it doesn't exist
func (*PlainObject) SetPrivateMethod ¶
func (o *PlainObject) SetPrivateMethod(name string, value Value)
SetPrivateMethod sets a private method value (ECMAScript # methods) Methods are not writable - any subsequent assignment throws TypeError
func (*PlainObject) SetPrototype ¶
func (o *PlainObject) SetPrototype(proto Value) bool
SetPrototype sets the object's prototype. Returns true if successful, false if the operation failed (e.g. object is non-extensible)
type PrivateBrandInfoVM ¶ added in v0.9.6
type PrivateBrandInfoVM struct {
BrandID int
DeclaredFields map[string]bool
MemberKinds map[string]PrivateMemberKindVM
}
PrivateBrandInfoVM stores brand info for passing to eval compilation. This is the VM's representation of the compiler's PrivateBrandInfo.
type PrivateMemberKindVM ¶ added in v0.9.6
type PrivateMemberKindVM int
PrivateMemberKindVM is the VM's representation of private member kinds. This mirrors the compiler's PrivateMemberKind for use in eval compilation.
const ( PrivateMemberFieldVM PrivateMemberKindVM = iota // Regular data field PrivateMemberMethodVM // Private method PrivateMemberGetterVM // Private getter PrivateMemberSetterVM // Private setter PrivateMemberAccessorVM // Private getter+setter )
type PromiseObject ¶
type PromiseObject struct {
Object
State PromiseState
Result Value // Fulfillment value or rejection reason
FulfillReactions []PromiseReaction
RejectReactions []PromiseReaction
// For async functions: suspended execution state
Frame *SuspendedFrame // Execution frame (nil if not an async function promise)
Function Value // The async function (for resumption)
ThisValue Value // The 'this' value when async function was called
}
PromiseObject represents a JavaScript Promise
func (*PromiseObject) GetResult ¶
func (p *PromiseObject) GetResult() Value
GetResult returns the promise result (value or reason)
func (*PromiseObject) GetState ¶
func (p *PromiseObject) GetState() PromiseState
GetState returns the promise state
type PromiseReaction ¶
type PromiseReaction struct {
Handler Value // Function to call (onFulfilled or onRejected)
Resolve func(Value) // Resolve the chained promise
Reject func(Value) // Reject the chained promise
}
PromiseReaction represents a callback registered via .then()
type PromiseState ¶
type PromiseState int
PromiseState represents the state of a Promise
const ( PromisePending PromiseState = iota PromiseFulfilled PromiseRejected )
type PropCacheEntry ¶
type PropCacheEntry struct {
// contains filtered or unexported fields
}
PropCacheEntry represents a single shape+offset entry in the cache
type PropCacheState ¶
type PropCacheState uint8
PropCacheState represents the different states of inline cache
const ( CacheStateUninitialized PropCacheState = iota CacheStateMonomorphic // Single shape cached CacheStatePolymorphic // Multiple shapes cached (up to 4) CacheStateMegamorphic // Too many shapes, fallback to map lookup )
type PropInlineCache ¶
type PropInlineCache struct {
// contains filtered or unexported fields
}
PropInlineCache represents the inline cache for a property access site
type PropertyDesc ¶ added in v0.9.7
PropertyDesc stores property descriptor attributes
type PropertyKey ¶
type PropertyKey struct {
// contains filtered or unexported fields
}
PropertyKey represents a property key which can be a string, symbol, or private key
func NewStringKey ¶
func NewStringKey(name string) PropertyKey
NewStringKey constructs an exported PropertyKey for string-named properties.
func NewSymbolKey ¶
func NewSymbolKey(sym Value) PropertyKey
NewSymbolKey constructs an exported PropertyKey for symbol-named properties.
type PrototypeCache ¶
type PrototypeCache struct {
// contains filtered or unexported fields
}
PrototypeCache holds prototype chain cache entries for a property access site
func GetOrCreatePrototypeCache ¶
func GetOrCreatePrototypeCache(cacheKey int) *PrototypeCache
GetOrCreatePrototypeCache gets or creates a prototype cache for the given key
func (*PrototypeCache) Lookup ¶
func (pc *PrototypeCache) Lookup(shape *Shape) (*PrototypeCacheEntry, bool)
Lookup checks the prototype chain cache
func (*PrototypeCache) Update ¶
func (pc *PrototypeCache) Update(shape *Shape, protoObj *PlainObject, depth int, offset int, boundMethod Value, isMethod bool)
Update adds or updates a prototype chain cache entry
type PrototypeCacheEntry ¶
type PrototypeCacheEntry struct {
// contains filtered or unexported fields
}
PrototypeCacheEntry represents a cached prototype chain lookup
type ProxyObject ¶
type ProxyObject struct {
Object
Revoked bool // Whether the proxy has been revoked
// contains filtered or unexported fields
}
func (*ProxyObject) Handler ¶
func (p *ProxyObject) Handler() Value
Handler returns the proxy's handler object
func (*ProxyObject) Target ¶
func (p *ProxyObject) Target() Value
Target returns the proxy's target object
type Realm ¶ added in v0.9.9
type Realm struct {
// Global environment
GlobalObject *PlainObject
Heap *Heap
// Built-in prototypes
ObjectPrototype Value
FunctionPrototype Value
ArrayPrototype Value
StringPrototype Value
NumberPrototype Value
BigIntPrototype Value
BooleanPrototype Value
RegExpPrototype Value
MapPrototype Value
SetPrototype Value
WeakMapPrototype Value
WeakSetPrototype Value
WeakRefPrototype Value
GeneratorPrototype Value
AsyncGeneratorPrototype Value
IteratorPrototype Value // %Iterator.prototype% - base for all iterators
IteratorHelperPrototype Value // %IteratorHelperPrototype% - for iterator helper objects
WrapForValidIteratorPrototype Value // For Iterator.from() wrapped iterators
ArrayIteratorPrototype Value
MapIteratorPrototype Value
SetIteratorPrototype Value
StringIteratorPrototype Value
RegExpStringIteratorPrototype Value
PromisePrototype Value
ErrorPrototype Value
TypeErrorPrototype Value
ReferenceErrorPrototype Value
SyntaxErrorPrototype Value
RangeErrorPrototype Value
URIErrorPrototype Value
EvalErrorPrototype Value
AggregateErrorPrototype Value
SymbolPrototype Value
DatePrototype Value
// TypedArray prototypes
TypedArrayPrototype Value // Abstract %TypedArray%.prototype
Uint8ArrayPrototype Value
Uint8ClampedArrayPrototype Value
Int8ArrayPrototype Value
Int16ArrayPrototype Value
Uint16ArrayPrototype Value
Uint32ArrayPrototype Value
Int32ArrayPrototype Value
Float32ArrayPrototype Value
Float64ArrayPrototype Value
BigInt64ArrayPrototype Value
BigUint64ArrayPrototype Value
ArrayBufferPrototype Value
DataViewPrototype Value
// Function-related prototypes
AsyncFunctionPrototype Value
GeneratorFunctionPrototype Value // %GeneratorFunction.prototype%
AsyncGeneratorFunctionPrototype Value // %AsyncGeneratorFunction.prototype%
// Constructors (cached for instanceof checks and error creation)
ErrorConstructor Value
TypedArrayConstructor Value // Abstract %TypedArray% constructor
AsyncFunctionConstructor Value
ArrayConstructor Value
ObjectConstructor Value
FunctionConstructor Value
// Well-known symbols
SymbolIterator Value
SymbolToPrimitive Value
SymbolToStringTag Value
SymbolHasInstance Value
SymbolIsConcatSpreadable Value
SymbolSpecies Value
SymbolMatch Value
SymbolMatchAll Value
SymbolReplace Value
SymbolSearch Value
SymbolSplit Value
SymbolUnscopables Value
SymbolAsyncIterator Value
SymbolDispose Value
// Symbol registry for Symbol.for()
SymbolRegistry map[string]Value
// Intrinsic functions
ThrowTypeErrorFunc Value // %ThrowTypeError% - for strict mode arguments.callee/caller
// Module system (per-realm)
ModuleContexts map[string]*ModuleContext
// contains filtered or unexported fields
}
Realm represents an isolated JavaScript execution environment. Each realm has its own global object, built-in prototypes, and intrinsics. This is the foundation for ECMAScript Realm support and ShadowRealm API.
func NewRealm ¶ added in v0.9.9
NewRealm creates a new realm with uninitialized prototypes. Call InitializePrototypes() and InitializeSymbols() to set up built-ins.
func (*Realm) DefineGlobal ¶ added in v0.9.9
DefineGlobal defines a new global in this realm (used by initializers).
func (*Realm) GetGlobal ¶ added in v0.9.9
GetGlobal retrieves a global variable by name from this realm.
func (*Realm) InitializePrototypes ¶ added in v0.9.9
func (r *Realm) InitializePrototypes()
InitializePrototypes creates the prototype chain for this realm. This sets up the inheritance hierarchy for all built-in types.
func (*Realm) InitializeSymbols ¶ added in v0.9.9
func (r *Realm) InitializeSymbols()
InitializeSymbols creates well-known symbols for this realm. Each realm has its own set of symbols.
func (*Realm) IsInitialized ¶ added in v0.9.9
IsInitialized returns true if this realm has been fully initialized.
func (*Realm) MarkInitialized ¶ added in v0.9.9
func (r *Realm) MarkInitialized()
MarkInitialized marks this realm as fully initialized.
type RegExpObject ¶
type RegExpObject struct {
Object // Embed the base Object for properties and prototype
Properties *PlainObject // Storage for user-defined properties
// contains filtered or unexported fields
}
RegExpObject represents a JavaScript RegExp object backed by Go's regexp package Uses Go's standard regexp (RE2) for simple patterns, falls back to regexp2 for advanced features like lookahead and backreferences.
func (*RegExpObject) FindAllString ¶
func (r *RegExpObject) FindAllString(s string, n int) []string
FindAllString returns all successive matches
func (*RegExpObject) FindAllStringSubmatchIndex ¶
func (r *RegExpObject) FindAllStringSubmatchIndex(s string, n int) [][]int
FindAllStringSubmatchIndex returns all matches with their indices
func (*RegExpObject) FindStringIndex ¶
func (r *RegExpObject) FindStringIndex(s string) []int
FindStringIndex returns the index of the leftmost match
func (*RegExpObject) FindStringSubmatch ¶
func (r *RegExpObject) FindStringSubmatch(s string) []string
FindStringSubmatch returns the leftmost match and any captured submatches
func (*RegExpObject) FindStringSubmatchIndex ¶
func (r *RegExpObject) FindStringSubmatchIndex(s string) []int
FindStringSubmatchIndex returns the index pairs for the leftmost match
func (*RegExpObject) FindStringSubmatchIndexAt ¶ added in v0.9.9
func (r *RegExpObject) FindStringSubmatchIndexAt(s string, byteStartAt int) []int
FindStringSubmatchIndexAt returns the index pairs for the first match starting at or after byteStartAt. Unlike searching a substring, this preserves lookbehind context.
func (*RegExpObject) GetCompileError ¶
func (r *RegExpObject) GetCompileError() string
GetCompileError returns the compilation error message, or empty string if no error
func (*RegExpObject) GetCompiledRegex ¶
func (r *RegExpObject) GetCompiledRegex() *regexp.Regexp
func (*RegExpObject) GetFlags ¶
func (r *RegExpObject) GetFlags() string
func (*RegExpObject) GetLastIndex ¶
func (r *RegExpObject) GetLastIndex() int
func (*RegExpObject) GetSource ¶
func (r *RegExpObject) GetSource() string
Getter methods for RegExpObject
func (*RegExpObject) HasCompileError ¶
func (r *RegExpObject) HasCompileError() bool
HasCompileError returns true if this regex has a deferred compilation error
func (*RegExpObject) IsDotAll ¶
func (r *RegExpObject) IsDotAll() bool
func (*RegExpObject) IsGlobal ¶
func (r *RegExpObject) IsGlobal() bool
func (*RegExpObject) IsIgnoreCase ¶
func (r *RegExpObject) IsIgnoreCase() bool
func (*RegExpObject) IsMultiline ¶
func (r *RegExpObject) IsMultiline() bool
func (*RegExpObject) IsSticky ¶ added in v0.9.9
func (r *RegExpObject) IsSticky() bool
func (*RegExpObject) MatchString ¶
func (r *RegExpObject) MatchString(s string) bool
MatchString returns true if the pattern matches the string
func (*RegExpObject) ReplaceAllLiteralString ¶ added in v0.9.9
func (r *RegExpObject) ReplaceAllLiteralString(src, repl string) string
ReplaceAllLiteralString replaces all matches with a literal replacement string (no $ expansion)
func (*RegExpObject) ReplaceAllString ¶
func (r *RegExpObject) ReplaceAllString(src, repl string) string
ReplaceAllString replaces all matches with the replacement string
func (*RegExpObject) ReplaceAllStringFunc ¶
func (r *RegExpObject) ReplaceAllStringFunc(src string, repl func(string) string) string
ReplaceAllStringFunc replaces all matches using a function
func (*RegExpObject) SetLastIndex ¶
func (r *RegExpObject) SetLastIndex(index int)
func (*RegExpObject) Split ¶
func (r *RegExpObject) Split(s string, n int) []string
Split splits the string by the regex pattern
func (*RegExpObject) UsesRegexp2 ¶
func (r *RegExpObject) UsesRegexp2() bool
UsesRegexp2 returns true if this regex uses the regexp2 fallback engine
type ScopeDescriptor ¶
type ScopeDescriptor struct {
// LocalNames maps register index to variable name.
// LocalNames[i] is the name of the variable in register i, or "" if not a named local.
LocalNames []string
// HasArgumentsBinding indicates if the caller's scope has an 'arguments' binding.
// This is true for functions (implicit arguments object) or when there's an 'arguments' parameter.
// Used for EvalDeclarationInstantiation to reject 'var arguments' that would conflict.
HasArgumentsBinding bool
// InDefaultParameterScope indicates if direct eval is called from a default parameter expression.
// In this context, var declarations in eval would hoist to the function's varEnv, which
// already contains the function's implicit 'arguments' binding, causing a conflict.
InDefaultParameterScope bool
// LexicalBindings contains names of let/const bindings in the caller's scope chain
// between the eval and the variable environment. Used to reject var declarations
// that would conflict with these lexical bindings (per 19.2.1.3 step 5.d).
LexicalBindings []string
// HasSuperBinding indicates if the caller context has a [[HomeObject]] binding,
// meaning super property access is valid. This is true when eval is called from
// within a method (class method or object method with concise syntax).
HasSuperBinding bool
// InClassFieldInitializer indicates if direct eval is called from a class field initializer.
// Per ECMAScript, accessing 'arguments' in eval inside a class field initializer is a SyntaxError
// ("Additional Early Error Rules for Eval Inside Initializer" - ContainsArguments rule).
InClassFieldInitializer bool
// PrivateBrandStack contains the private brand context from enclosing classes.
// This allows direct eval to access private fields from the enclosing class.
PrivateBrandStack []PrivateBrandInfoVM
// CurrentPrivateBrand is the brand ID of the innermost class containing the eval.
CurrentPrivateBrand int
// CurrentPrivateBrandInfo is the brand info for the current class.
CurrentPrivateBrandInfo *PrivateBrandInfoVM
}
ScopeDescriptor stores name-to-register mappings for functions that contain direct eval. This allows direct eval to resolve variable names to caller's registers at runtime. Only populated for functions marked as containing direct eval - nil otherwise for efficiency.
type SetObject ¶
type SetObject struct {
Object
Properties *PlainObject // User-defined properties on the Set object
// contains filtered or unexported fields
}
func (*SetObject) ForEach ¶
ForEach calls fn for each value in the set in insertion order. Skips tombstones (deleted values).
func (*SetObject) GetValueAt ¶ added in v0.9.8
GetValueAt returns the value at the given index in insertion order. Returns (value, true) if the entry exists, or (Undefined, false) if the index is out of bounds or the entry was deleted. Used by live iterators.
type SharedArrayBufferObject ¶ added in v0.9.9
type SharedArrayBufferObject struct {
// contains filtered or unexported fields
}
SharedArrayBufferObject represents a shared binary data buffer Unlike ArrayBuffer, SharedArrayBuffer cannot be detached and is designed for shared memory between workers (though in this implementation, we don't have multi-threading support yet)
func (*SharedArrayBufferObject) ByteLength ¶ added in v0.9.9
func (sab *SharedArrayBufferObject) ByteLength() int
ByteLength returns the length in bytes
func (*SharedArrayBufferObject) GetData ¶ added in v0.9.9
func (sab *SharedArrayBufferObject) GetData() []byte
GetData returns the underlying byte slice
func (*SharedArrayBufferObject) GetOwnProperty ¶ added in v0.9.9
func (sab *SharedArrayBufferObject) GetOwnProperty(name string) (Value, bool)
GetOwnProperty returns an own property value
func (*SharedArrayBufferObject) HasOwnProperty ¶ added in v0.9.9
func (sab *SharedArrayBufferObject) HasOwnProperty(name string) bool
HasOwnProperty checks if the buffer has an own property
func (*SharedArrayBufferObject) IsDetached ¶ added in v0.9.9
func (sab *SharedArrayBufferObject) IsDetached() bool
IsDetached always returns false for SharedArrayBuffer (cannot be detached)
func (*SharedArrayBufferObject) SetOwnProperty ¶ added in v0.9.9
func (sab *SharedArrayBufferObject) SetOwnProperty(name string, value Value)
SetOwnProperty sets an own property value
type StackFrame ¶
StackFrame represents a single frame in a stack trace
type StringObject ¶
type StringObject struct {
Object
// contains filtered or unexported fields
}
type SuspendedFrame ¶
type SuspendedFrame struct {
// contains filtered or unexported fields
}
GeneratorFrame stores the execution state of a suspended generator This allows the generator to resume execution from where it left off SuspendedFrame stores execution state when a function is suspended Used by both generators (yield) and async functions (await)
type SymbolObject ¶
type TypedArrayKind ¶
type TypedArrayKind uint8
TypedArrayKind represents the different typed array types
const ( TypedArrayInt8 TypedArrayKind = iota TypedArrayUint8 TypedArrayUint8Clamped TypedArrayInt16 TypedArrayUint16 TypedArrayInt32 TypedArrayUint32 TypedArrayFloat32 TypedArrayFloat64 TypedArrayBigInt64 TypedArrayBigUint64 )
func (TypedArrayKind) BytesPerElement ¶
func (kind TypedArrayKind) BytesPerElement() int
Helper to get bytes per element for each typed array kind
func (TypedArrayKind) Name ¶ added in v0.9.9
func (kind TypedArrayKind) Name() string
Name returns the ECMAScript constructor name for this TypedArray kind
type TypedArrayObject ¶
type TypedArrayObject struct {
Object
// contains filtered or unexported fields
}
TypedArrayObject represents a typed view into an ArrayBuffer or SharedArrayBuffer
func (*TypedArrayObject) GetBuffer ¶
func (ta *TypedArrayObject) GetBuffer() *ArrayBufferObject
GetBuffer returns the underlying buffer as an ArrayBufferObject (for backwards compatibility) Returns nil if the buffer is a SharedArrayBuffer
func (*TypedArrayObject) GetBufferData ¶ added in v0.9.9
func (ta *TypedArrayObject) GetBufferData() BufferData
GetBufferData returns the underlying buffer (ArrayBuffer or SharedArrayBuffer)
func (*TypedArrayObject) GetByteLength ¶
func (ta *TypedArrayObject) GetByteLength() int
func (*TypedArrayObject) GetByteOffset ¶
func (ta *TypedArrayObject) GetByteOffset() int
func (*TypedArrayObject) GetBytesPerElement ¶
func (ta *TypedArrayObject) GetBytesPerElement() int
func (*TypedArrayObject) GetElement ¶
func (ta *TypedArrayObject) GetElement(index int) Value
GetTypedArrayElement gets an element at the given index
func (*TypedArrayObject) GetElementType ¶
func (ta *TypedArrayObject) GetElementType() TypedArrayKind
func (*TypedArrayObject) GetLength ¶
func (ta *TypedArrayObject) GetLength() int
func (*TypedArrayObject) GetOwnProperty ¶ added in v0.9.9
func (ta *TypedArrayObject) GetOwnProperty(name string) (Value, bool)
GetOwnProperty returns an own property value (non-index properties)
func (*TypedArrayObject) GetSharedBuffer ¶ added in v0.9.9
func (ta *TypedArrayObject) GetSharedBuffer() *SharedArrayBufferObject
GetSharedBuffer returns the underlying SharedArrayBuffer, or nil if not shared
func (*TypedArrayObject) HasOwnProperty ¶ added in v0.9.9
func (ta *TypedArrayObject) HasOwnProperty(name string) bool
HasOwnProperty checks if the TypedArray has an own property
func (*TypedArrayObject) IsSharedBuffer ¶ added in v0.9.9
func (ta *TypedArrayObject) IsSharedBuffer() bool
IsSharedBuffer returns true if the underlying buffer is a SharedArrayBuffer
func (*TypedArrayObject) SetElement ¶
func (ta *TypedArrayObject) SetElement(index int, value Value)
SetTypedArrayElement sets an element at the given index
func (*TypedArrayObject) SetOwnProperty ¶ added in v0.9.9
func (ta *TypedArrayObject) SetOwnProperty(name string, value Value)
SetOwnProperty sets an own property value (non-index properties)
type VM ¶
type VM struct {
// Global object - the object that globalThis refers to
// Top-level var/function declarations become properties of this object
// This matches ECMAScript spec behavior
GlobalObject *PlainObject
// Built-in prototypes owned by this VM
ObjectPrototype Value
FunctionPrototype Value
ArrayPrototype Value
StringPrototype Value
NumberPrototype Value
BigIntPrototype Value
BooleanPrototype Value
RegExpPrototype Value
MapPrototype Value
SetPrototype Value
WeakMapPrototype Value
WeakSetPrototype Value
WeakRefPrototype Value
GeneratorPrototype Value
AsyncGeneratorPrototype Value
IteratorPrototype Value // %Iterator.prototype% - base for all iterators
IteratorHelperPrototype Value // %IteratorHelperPrototype% - for iterator helper objects (map, filter, etc.)
WrapForValidIteratorPrototype Value // For Iterator.from() wrapped iterators
ArrayIteratorPrototype Value // %ArrayIteratorPrototype% - for array iterators
MapIteratorPrototype Value // %MapIteratorPrototype% - for map iterators
SetIteratorPrototype Value // %SetIteratorPrototype% - for set iterators
StringIteratorPrototype Value // %StringIteratorPrototype% - for string iterators
RegExpStringIteratorPrototype Value // %RegExpStringIteratorPrototype% - for RegExp matchAll iterators
PromisePrototype Value
DatePrototype Value
ErrorPrototype Value
ErrorConstructor Value // For NativeError constructors to inherit from
TypeErrorPrototype Value
ReferenceErrorPrototype Value
SymbolPrototype Value
// Constructors and prototypes for non-global built-in types
AsyncFunctionConstructor Value
AsyncFunctionPrototype Value
GeneratorFunctionPrototype Value // %GeneratorFunction.prototype% - prototype of generator functions
AsyncGeneratorFunctionPrototype Value // %AsyncGeneratorFunction.prototype% - prototype of async generator functions
// Cached constructors for instanceof checks
ArrayConstructor Value
ObjectConstructor Value
FunctionConstructor Value
// Well-known symbols (stored as singletons)
SymbolIterator Value
SymbolToPrimitive Value
SymbolToStringTag Value
SymbolHasInstance Value
SymbolIsConcatSpreadable Value
SymbolSpecies Value
SymbolMatch Value
SymbolMatchAll Value
SymbolReplace Value
SymbolSearch Value
SymbolSplit Value
SymbolUnscopables Value
SymbolAsyncIterator Value
SymbolDispose Value
// %ThrowTypeError% intrinsic - singleton function used for strict mode arguments callee/caller
// Per ECMAScript spec, this function is NOT extensible (unlike normal functions)
ThrowTypeErrorFunc Value
// TypedArray prototypes
TypedArrayConstructor Value // Abstract %TypedArray% constructor - all typed arrays inherit from this
TypedArrayPrototype Value // Abstract %TypedArray%.prototype - all typed arrays inherit from this
Uint8ArrayPrototype Value
Uint8ClampedArrayPrototype Value
Int8ArrayPrototype Value
Int16ArrayPrototype Value
Uint16ArrayPrototype Value
Uint32ArrayPrototype Value
Int32ArrayPrototype Value
Float32ArrayPrototype Value
Float64ArrayPrototype Value
BigInt64ArrayPrototype Value
BigUint64ArrayPrototype Value
ArrayBufferPrototype Value
DataViewPrototype Value
// contains filtered or unexported fields
}
VM represents the virtual machine state.
func (*VM) AddPromiseReaction ¶
AddPromiseReaction adds a reaction to a promise (exported wrapper)
func (*VM) Call ¶
Call is a unified function calling interface that handles all function types properly This replaces the complex web of CallFunctionDirectly, CallUserFunction, etc.
func (*VM) CallFunctionDirectly ¶
CallFunctionDirectly executes a user-defined function directly without re-entrant execution This is specifically designed for Function.prototype.call to avoid infinite recursion
func (*VM) Cancel ¶
func (vm *VM) Cancel()
Cancel signals the VM to stop execution at the next safe point
func (*VM) CaptureStackTrace ¶
CaptureStackTrace captures the current call stack and returns it as a formatted string
func (*VM) ClearErrors ¶
func (vm *VM) ClearErrors()
ClearErrors clears all recorded errors from the VM. This is used by async generators which convert exceptions to rejected promises.
func (*VM) ClearHandlerFound ¶
func (vm *VM) ClearHandlerFound()
ClearHandlerFound clears the handler found flag.
func (*VM) ClearUnwindingState ¶
func (vm *VM) ClearUnwindingState()
ClearUnwindingState clears the exception unwinding state. This should be called when native code successfully handles an exception (e.g., by returning a rejected promise) so the VM knows the exception has been handled.
func (*VM) Construct ¶
Construct calls a constructor function with the given arguments, similar to 'new Constructor(args)' Per ECMAScript spec, Construct(F, args) defaults newTarget to F and delegates to [[Construct]].
func (*VM) ConstructWithNewTarget ¶ added in v0.9.3
func (vm *VM) ConstructWithNewTarget(constructor Value, args []Value, newTarget Value) (Value, error)
ConstructWithNewTarget calls a constructor function with a custom new.target value This is used by Reflect.construct to support the third argument
func (*VM) CreateRealm ¶ added in v0.9.9
CreateRealm creates a new isolated realm with initialized prototypes and symbols. Note: Builtins must be initialized separately by the driver using InitializeRealmBuiltins.
func (*VM) CurrentRealm ¶ added in v0.9.9
CurrentRealm returns the active realm for the current execution.
func (*VM) DebugPrintGlobals ¶
func (vm *VM) DebugPrintGlobals()
createModuleNamespace creates a namespace object containing all exports from a module DebugPrintGlobals prints all available global variables for debugging
func (*VM) DecrementCallDepth ¶
func (vm *VM) DecrementCallDepth()
DecrementCallDepth decrements the call depth counter
func (*VM) DefaultRealm ¶ added in v0.9.9
DefaultRealm returns the default/main realm.
func (*VM) DrainMicrotasks ¶
func (vm *VM) DrainMicrotasks()
DrainMicrotasks runs all pending microtasks until idle
func (*VM) EnterHelperCall ¶
func (vm *VM) EnterHelperCall()
EnterHelperCall increments the helper call depth counter. This should be called before native functions call helpers like ToPrimitive that might throw exceptions which need to be caught by try/catch blocks.
func (*VM) ExecuteGenerator ¶
func (vm *VM) ExecuteGenerator(genObj *GeneratorObject, sentValue Value) (Value, error)
ExecuteGenerator is the public interface for generator execution
func (*VM) ExecuteGeneratorWithException ¶
func (vm *VM) ExecuteGeneratorWithException(genObj *GeneratorObject, exception Value) (Value, error)
ExecuteGeneratorWithException is the public interface for generator execution with exception injection
func (*VM) ExecuteGeneratorWithReturn ¶
func (vm *VM) ExecuteGeneratorWithReturn(genObj *GeneratorObject, returnValue Value) (Value, error)
ExecuteGeneratorWithReturn is the public interface for generator execution with return completion
func (*VM) ExitHelperCall ¶
func (vm *VM) ExitHelperCall()
ExitHelperCall decrements the helper call depth counter. This should be called after native functions return from helpers like ToPrimitive.
func (*VM) GetAsyncRuntime ¶
func (vm *VM) GetAsyncRuntime() runtime.AsyncRuntime
GetAsyncRuntime returns the current async runtime (or default)
func (*VM) GetCacheStats ¶
func (vm *VM) GetCacheStats() ICacheStats
GetCacheStats returns the current inline cache statistics
func (*VM) GetCallDepth ¶
GetCallDepth returns the current call depth for Function.prototype.call recursion tracking
func (*VM) GetFrameCount ¶
GetFrameCount returns the current frame count for debugging
func (*VM) GetFunctionRealm ¶ added in v0.9.9
GetFunctionRealm returns the realm associated with a function. Per ECMAScript 7.3.22 GetFunctionRealm: - If function has [Realm], return it - If bound function, recursively get realm of target - If proxy, get realm of target (throws if revoked) - Otherwise return current realm
func (*VM) GetGlobalByIndex ¶
GetGlobalByIndex retrieves a global value by its index
func (*VM) GetNewTarget ¶ added in v0.9.9
GetNewTarget returns the current newTarget for native constructors. Used by native constructors that need to implement GetPrototypeFromConstructor.
func (*VM) GetProperty ¶
GetProperty gets a property from an object value, properly handling getters and prototype chain This is safe to call from native functions and will trigger property getters/throw exceptions
func (*VM) GetPrototypeFromConstructor ¶ added in v0.9.9
func (vm *VM) GetPrototypeFromConstructor(constructor Value, intrinsicDefault string) (Value, error)
GetPrototypeFromConstructor implements ECMAScript 9.1.14 GetPrototypeFromConstructor. Given a constructor (newTarget) and an intrinsic default prototype name, it returns the prototype to use for creating a new object. If the constructor's "prototype" property is an object, return it. Otherwise, get the constructor's realm and return that realm's intrinsic.
func (*VM) GetSymbolProperty ¶
GetSymbolProperty gets a symbol property from an object value, properly handling prototype chain This is safe to call from native functions
func (*VM) GetSymbolPropertyWithGetter ¶
GetSymbolPropertyWithGetter gets a symbol property from an object value, handling getters and prototype chain This is safe to call from native functions and will trigger property getters/throw exceptions
func (*VM) GetThis ¶
GetThis returns the current 'this' value for native function execution This allows native functions to access the 'this' context without it being passed as an argument
func (*VM) IncrementCallDepth ¶
func (vm *VM) IncrementCallDepth()
IncrementCallDepth increments the call depth counter
func (*VM) Interpret ¶
func (vm *VM) Interpret(chunk *Chunk) (Value, []errors.PaseratiError)
Interpret starts executing the given chunk of bytecode. It sets up a new top-level frame for the chunk's execution on top of the existing VM state. It does NOT reset the VM state; call Reset() explicitly if needed. Returns the final value produced by the chunk and any runtime errors.
func (*VM) InterpretWithCallerScope ¶
func (vm *VM) InterpretWithCallerScope(chunk *Chunk, callerRegs []Value, callerThis Value, callerHomeObject Value) (Value, []errors.PaseratiError)
InterpretWithCallerScope executes a chunk with access to the caller's local variables, 'this', and homeObject. This is used for direct eval to allow reading/writing caller's registers and inheriting 'this' and homeObject. callerRegs is the slice of caller's registers that can be accessed by OpGetCallerLocal/OpSetCallerLocal. callerThis is the 'this' value from the caller's execution context. callerHomeObject is the [[HomeObject]] for super property access.
func (*VM) IsConstructor ¶
IsConstructor checks if a value can be used as a constructor
func (*VM) IsConstructorCall ¶
IsConstructorCall returns true if currently executing a native function via 'new'
func (*VM) IsHandlerFound ¶
IsHandlerFound returns true if an exception handler was found during a helper call. After checking this, the caller should call ClearHandlerFound().
func (*VM) IsInStrictMode ¶
IsInStrictMode returns true if the current execution context is in strict mode This checks the current frame's chunk for the IsStrict flag Used by eval() to determine whether to compile eval'd code in strict mode
func (*VM) IsOriginalEval ¶
IsOriginalEval checks if a value is the original eval intrinsic
func (*VM) IsUnwinding ¶
IsUnwinding returns true if the VM is currently in an exception unwinding state
func (*VM) IterableToArray ¶
IterableToArray converts an iterable value to an array Supports arrays directly and any object with Symbol.iterator
func (*VM) NewArrayFromSlice ¶
NewArrayFromSlice creates a new array from a slice of values
func (*VM) NewBooleanObject ¶
NewBooleanObject creates a Boolean wrapper object with the given primitive value
func (*VM) NewExceptionError ¶
NewExceptionError creates an ExceptionError from a VM Value for use in builtins.
func (*VM) NewNumberObject ¶
NewNumberObject creates a Number wrapper object with the given primitive value
func (*VM) NewPendingPromise ¶
NewPendingPromise creates a new promise in pending state
func (*VM) NewPromiseFromExecutor ¶
NewPromiseFromExecutor creates a new Promise with an executor function executor receives (resolve, reject) functions
func (*VM) NewRangeError ¶
NewRangeError constructs a RangeError exception error for builtin helpers to return
func (*VM) NewReferenceError ¶
NewReferenceError constructs a ReferenceError exception error for builtin helpers to return
func (*VM) NewRegExpDeferred ¶ added in v0.9.8
NewRegExpDeferred creates a RegExp object, trying Go's fast RE2 engine first, then falling back to regexp2 for advanced features like lookahead/backreferences. The compiled regex engines are cached and shared across instances for performance, but each call returns a distinct RegExpObject (per ECMAScript spec requirement that each evaluation of a regex literal creates a new object).
func (*VM) NewRejectedPromise ¶
NewRejectedPromise creates a promise that is already rejected
func (*VM) NewResolvedPromise ¶
NewResolvedPromise creates a promise that is already fulfilled
func (*VM) NewStringObject ¶
NewStringObject creates a String wrapper object with the given primitive value
func (*VM) NewSymbolObject ¶ added in v0.9.9
NewSymbolObject creates a Symbol wrapper object with the given primitive value
func (*VM) NewSyntaxError ¶ added in v0.9.9
NewSyntaxError constructs a SyntaxError exception error for builtin helpers to return
func (*VM) NewTypeError ¶
NewTypeError constructs a TypeError exception error for builtin helpers to return
func (*VM) NewTypeErrorInRealm ¶ added in v0.9.10
NewTypeErrorInRealm constructs a TypeError from a specific realm's TypeError constructor. Per ECMAScript, built-in functions throw errors from their own realm (§10.3.1 step 5-6).
func (*VM) NewURIError ¶ added in v0.9.9
NewURIError constructs a URIError exception error for builtin helpers to return
func (*VM) PrintCacheStats ¶
func (vm *VM) PrintCacheStats()
PrintCacheStats prints detailed cache performance information for debugging
func (*VM) PromiseThen ¶
PromiseThen implements Promise.prototype.then()
func (*VM) RejectPromise ¶
func (vm *VM) RejectPromise(promise *PromiseObject, reason Value)
RejectPromise rejects a promise with a reason (exported wrapper)
func (*VM) ResizeHeapForGlobals ¶
ResizeHeapForGlobals resizes the heap to accommodate all global indices This must be called after compilation and before execution to ensure that OpGetGlobal can properly detect uninitialized/undefined variables
func (*VM) ResolvePromise ¶
func (vm *VM) ResolvePromise(promise *PromiseObject, value Value)
ResolvePromise fulfills a promise with a value (exported wrapper)
func (*VM) SetAsyncRuntime ¶
func (vm *VM) SetAsyncRuntime(rt runtime.AsyncRuntime)
SetAsyncRuntime sets the async execution runtime
func (*VM) SetBuiltinGlobals ¶
func (*VM) SetCurrentModulePath ¶
SetCurrentModulePath sets the current module path for module-specific features like import.meta
func (*VM) SetEvalDriver ¶
func (vm *VM) SetEvalDriver(driver EvalDriver)
SetEvalDriver sets the eval driver for this VM instance (used by OpDirectEval)
func (*VM) SetModuleLoader ¶
func (vm *VM) SetModuleLoader(loader ModuleLoader)
Reset clears the VM state, ready for new execution. SetBuiltinGlobals initializes the VM's global variables with builtin values SetModuleLoader sets the module loader for this VM instance
func (*VM) SetOriginalEval ¶
SetOriginalEval stores the original eval intrinsic for direct eval detection
func (*VM) SetProperty ¶ added in v0.9.6
SetProperty sets a property on an object value, properly handling setters This is safe to call from native functions and will trigger property setters/throw exceptions
func (*VM) SyncGlobalNames ¶
SyncGlobalNames syncs the compiler's global name mappings to the VM's heap This should be called after each compilation to ensure globalThis property access works
func (*VM) SyncHeapToGlobalObject ¶
func (vm *VM) SyncHeapToGlobalObject()
SyncHeapToGlobalObject copies heap variables to GlobalObject as properties This is called after indirect eval execution to make var declarations accessible via globalThis Only syncs user-defined globals (indices >= builtinCount)
func (*VM) SyncPrototypesToRealm ¶ added in v0.9.9
func (vm *VM) SyncPrototypesToRealm()
SyncPrototypesToRealm copies prototype and symbol values from VM's legacy fields to currentRealm. This is the reverse of syncPrototypesFromRealm and is used after builtins initialize to ensure the realm gets the real prototypes (not just the initial placeholders).
func (*VM) ThrowExceptionValue ¶
ThrowExceptionValue throws a JavaScript exception with the given value. This is used by native functions to propagate exceptions from vm.Call.
func (*VM) ThrowRangeError ¶
ThrowRangeError creates and throws a proper RangeError instance
func (*VM) ThrowReferenceError ¶
ThrowReferenceError creates and throws a proper ReferenceError instance
func (*VM) ThrowSyntaxError ¶
ThrowSyntaxError creates and throws a proper SyntaxError instance
func (*VM) ThrowTypeError ¶
func (*VM) ToInteger ¶
ToInteger implements ECMAScript ToInteger abstract operation. Returns an int after proper number conversion.
func (*VM) ToNumber ¶
ToNumber implements ECMAScript ToNumber abstract operation. It properly converts objects by first calling ToPrimitive with "number" hint.
func (*VM) ToObject ¶ added in v0.9.9
ToObject converts a value to an object per ECMAScript specification. Returns error for undefined and null, wraps primitives, passes objects through.
func (*VM) ToPrimitive ¶
ToPrimitive is the public wrapper for toPrimitive, allowing builtins to call it. It implements the ECMAScript ToPrimitive abstract operation. hint should be "string", "number", or "default".
func (*VM) WithRealm ¶ added in v0.9.9
WithRealm executes a function in a specific realm context. The current realm is temporarily switched to the given realm, then restored after fn returns. After fn() completes, the VM's prototype fields are synced BACK to the realm so that any changes made by builtins are preserved in the realm.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
var DefaultObjectPrototype Value
Define the shared default prototype for plain objects
func BooleanValue ¶
func CanonicalizeKeyedCollectionKey ¶ added in v0.9.9
CanonicalizeKeyedCollectionKey normalizes keys for Map/Set collections. Per ECMAScript spec, -0 is canonicalized to +0.
func IntegerValue ¶
func NewArrayBuffer ¶
func NewArrayBufferFromObject ¶ added in v0.9.9
func NewArrayBufferFromObject(buffer *ArrayBufferObject) Value
NewArrayBufferFromObject creates a Value from an existing ArrayBufferObject
func NewArrayWithArgs ¶
NewArrayWithArgs creates an array based on the Array constructor arguments: - No args: empty array - Single numeric arg: array with that length (filled with undefined) - Multiple args: array with those elements
func NewArrayWithLength ¶
NewArrayWithLength creates an array with the specified length
func NewAsyncGenerator ¶
func NewAsyncNativeFunction ¶
func NewBoundFunction ¶
func NewClosure ¶
func NewClosure(fn *FunctionObject, upvalues []*Upvalue) Value
func NewConstructorWithProps ¶
func NewConstructorWithProps(arity int, variadic bool, name string, fn func(args []Value) (Value, error)) Value
NewConstructorWithProps creates a native function with properties that can be used as a constructor. This is the same as NewNativeFunctionWithProps but with IsConstructor set to true.
func NewDataView ¶ added in v0.9.9
func NewDataView(buffer BufferData, byteOffset, byteLength int) Value
NewDataView creates a new DataView value
func NewDictObject ¶
func NewFunction ¶
func NewGenerator ¶
NewGenerator creates a new generator object with the given generator function
func NewNativeConstructor ¶
func NewNativeConstructor(arity int, variadic bool, name string, fn func(args []Value) (Value, error)) Value
NewNativeConstructor creates a native function that can be used as a constructor. This is the same as NewNativeFunction but with IsConstructor set to true.
func NewNativeFunction ¶
func NewRegisteredSymbol ¶ added in v0.9.9
func NewSharedArrayBuffer ¶ added in v0.9.9
NewSharedArrayBuffer creates a new SharedArrayBuffer with the given size
func NewSharedArrayBufferFromObject ¶ added in v0.9.9
func NewSharedArrayBufferFromObject(buffer *SharedArrayBufferObject) Value
NewSharedArrayBufferFromObject creates a Value from an existing SharedArrayBufferObject
func NewSymbolNoDescription ¶ added in v0.9.10
func NewSymbolNoDescription() Value
NewSymbolNoDescription creates a symbol with no description (Symbol() with no args)
func NewTypedArray ¶
func NewTypedArray(kind TypedArrayKind, lengthOrBuffer interface{}, byteOffset, length int) Value
func NewValueFromPlainObject ¶
func NewValueFromPlainObject(plainObj *PlainObject) Value
NewValueFromPlainObject creates a Value from a PlainObject pointer This is useful for returning prototype objects from built-in functions
func NewWeakMapWithPrototype ¶ added in v0.9.9
NewWeakMapWithPrototype creates a new WeakMap object with a specific prototype
func NewWeakRef ¶ added in v0.9.9
NewWeakRef creates a new WeakRef object holding a weak reference to target
func NewWeakRefWithPrototype ¶ added in v0.9.9
NewWeakRefWithPrototype creates a new WeakRef object with a specific prototype
func NumberValue ¶
func RegExpValue ¶
func RegExpValue(r *RegExpObject) Value
RegExpValue creates a Value from a RegExpObject
func (Value) AsArguments ¶
func (v Value) AsArguments() *ArgumentsObject
func (Value) AsArray ¶
func (v Value) AsArray() *ArrayObject
func (Value) AsArrayBuffer ¶
func (v Value) AsArrayBuffer() *ArrayBufferObject
func (Value) AsAsyncGenerator ¶
func (v Value) AsAsyncGenerator() *AsyncGeneratorObject
func (Value) AsAsyncNativeFunction ¶
func (v Value) AsAsyncNativeFunction() *AsyncNativeFunctionObject
func (Value) AsBoundFunction ¶
func (v Value) AsBoundFunction() *BoundFunctionObject
func (Value) AsClosure ¶
func (v Value) AsClosure() *ClosureObject
func (Value) AsDataView ¶ added in v0.9.9
func (v Value) AsDataView() *DataViewObject
AsDataView returns the DataViewObject if the value is a DataView, nil otherwise
func (Value) AsDictObject ¶
func (v Value) AsDictObject() *DictObject
func (Value) AsFunction ¶
func (v Value) AsFunction() *FunctionObject
func (Value) AsGenerator ¶
func (v Value) AsGenerator() *GeneratorObject
func (Value) AsNativeFunction ¶
func (v Value) AsNativeFunction() *NativeFunctionObject
func (Value) AsNativeFunctionWithProps ¶
func (v Value) AsNativeFunctionWithProps() *NativeFunctionObjectWithProps
func (Value) AsPlainObject ¶
func (v Value) AsPlainObject() *PlainObject
func (Value) AsPromise ¶
func (v Value) AsPromise() *PromiseObject
func (Value) AsProxy ¶
func (v Value) AsProxy() *ProxyObject
func (Value) AsRegExpObject ¶
func (v Value) AsRegExpObject() *RegExpObject
AsRegExpObject safely converts a Value to a RegExpObject, returns nil if not a regex
func (Value) AsSharedArrayBuffer ¶ added in v0.9.9
func (v Value) AsSharedArrayBuffer() *SharedArrayBufferObject
func (Value) AsSymbolObject ¶ added in v0.9.6
func (v Value) AsSymbolObject() *SymbolObject
AsSymbolObject returns the underlying SymbolObject pointer for symbol values
func (Value) AsTypedArray ¶
func (v Value) AsTypedArray() *TypedArrayObject
func (Value) AsWeakMap ¶ added in v0.9.3
func (v Value) AsWeakMap() *WeakMapObject
func (Value) AsWeakRef ¶ added in v0.9.9
func (v Value) AsWeakRef() *WeakRefObject
func (Value) AsWeakSet ¶ added in v0.9.3
func (v Value) AsWeakSet() *WeakSetObject
func (Value) CanBeHeldWeakly ¶ added in v0.9.9
CanBeHeldWeakly returns true if this value can be used as a WeakMap/WeakSet key. Per ECMAScript spec: objects and non-registered symbols can be held weakly.
func (Value) Equals ¶
Equals compares two values using the ECMAScript Abstract Equality Comparison (`==`). Handles type coercion according to the spec (simplified version). See: https://tc39.es/ecma262/multipage/abstract-operations.html#sec-abstract-equality-comparison
func (Value) Inspect ¶
Inspect returns a developer-friendly representation of Value, similar to a REPL.
func (Value) InspectNested ¶
InspectNested is used for nested contexts where strings should be quoted
func (Value) Is ¶
Is compares two values for equality based on the ECMAScript SameValueZero algorithm. NaN === NaN is true, +0 === -0 is true. Useful for collections.
func (Value) IsArguments ¶
func (Value) IsCallable ¶
func (Value) IsDictObject ¶
func (Value) IsFalsey ¶
IsFalsey checks if the value is considered falsey according to ECMAScript rules. null, undefined, false, +0, -0, NaN, 0n, "" are falsey. Everything else is truthy.
func (Value) IsFloatNumber ¶
func (Value) IsFunction ¶
func (Value) IsGenerator ¶
func (Value) IsIntegerNumber ¶
func (Value) IsNativeFunction ¶
func (Value) IsUndefined ¶
IsUndefined checks if the value is undefined
func (Value) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface for vm.Value This allows direct JSON marshaling without intermediate conversions
func (Value) StrictlyEquals ¶
StrictlyEquals compares two values using the ECMAScript Strict Equality Comparison (`===`). Types must match, no coercion. NaN !== NaN. +0 === -0.
func (Value) ToPrimitive ¶
ToPrimitive converts a value to a primitive type following ECMAScript specification hint can be "number", "string", or "default"
func (*Value) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface for vm.Value This allows direct JSON unmarshaling without intermediate conversions
type ValueType ¶
type ValueType uint8
const ( TypeUndefined ValueType = iota TypeNull TypeString TypeSymbol TypeFloatNumber TypeIntegerNumber TypeBigInt TypeBoolean TypeFunction TypeNativeFunction TypeNativeFunctionWithProps TypeAsyncNativeFunction TypeClosure TypeBoundFunction TypeObject TypeDictObject TypeArray TypeArguments TypeGenerator TypeAsyncGenerator TypePromise TypeRegExp TypeMap TypeSet TypeWeakMap TypeWeakSet TypeWeakRef TypeArrayBuffer TypeTypedArray TypeDataView TypeProxy TypeHole // Internal marker for array holes (sparse arrays) TypeUninitialized // TDZ marker for let/const before initialization )
type WeakMapEntry ¶ added in v0.9.3
type WeakMapEntry struct {
// contains filtered or unexported fields
}
WeakMapEntry holds a weak reference to the key and a strong reference to the value
type WeakMapObject ¶ added in v0.9.3
type WeakMapObject struct {
Object
// contains filtered or unexported fields
}
WeakMapObject implements ECMAScript WeakMap using Go's weak package. Keys must be objects (not primitives) and are held weakly, allowing GC.
func (*WeakMapObject) Delete ¶ added in v0.9.3
func (wm *WeakMapObject) Delete(key Value) bool
Delete removes a key-value pair from the WeakMap Returns true if the key was found and deleted
func (*WeakMapObject) Get ¶ added in v0.9.3
func (wm *WeakMapObject) Get(key Value) (Value, bool)
Get retrieves a value from the WeakMap by key Returns (Undefined, false) if key not found or key has been GC'd
func (*WeakMapObject) GetPrototype ¶ added in v0.9.9
func (wm *WeakMapObject) GetPrototype() Value
GetPrototype returns the WeakMap's [[Prototype]]
func (*WeakMapObject) Has ¶ added in v0.9.3
func (wm *WeakMapObject) Has(key Value) bool
Has checks if a key exists in the WeakMap
func (*WeakMapObject) Set ¶ added in v0.9.3
func (wm *WeakMapObject) Set(key, value Value) bool
Set adds or updates a key-value pair in the WeakMap Returns false if the key cannot be held weakly
type WeakRefObject ¶ added in v0.9.9
type WeakRefObject struct {
Object
// contains filtered or unexported fields
}
WeakRefObject implements ECMAScript WeakRef using Go's weak package. A WeakRef holds a weak reference to a target object.
func (*WeakRefObject) Deref ¶ added in v0.9.9
func (wr *WeakRefObject) Deref() Value
Deref returns the target object if it's still alive, or undefined if collected
func (*WeakRefObject) GetPrototype ¶ added in v0.9.9
func (wr *WeakRefObject) GetPrototype() Value
GetPrototype returns the WeakRef's [[Prototype]]
type WeakSetEntry ¶ added in v0.9.3
type WeakSetEntry struct {
// contains filtered or unexported fields
}
WeakSetEntry holds a weak reference to a value
type WeakSetObject ¶ added in v0.9.3
type WeakSetObject struct {
Object
// contains filtered or unexported fields
}
WeakSetObject implements ECMAScript WeakSet using Go's weak package. Values must be objects and are held weakly, allowing GC.
func (*WeakSetObject) Add ¶ added in v0.9.3
func (ws *WeakSetObject) Add(value Value) bool
Add adds a value to the WeakSet Returns false if the value cannot be held weakly
func (*WeakSetObject) Delete ¶ added in v0.9.3
func (ws *WeakSetObject) Delete(value Value) bool
Delete removes a value from the WeakSet Returns true if the value was found and deleted
func (*WeakSetObject) Has ¶ added in v0.9.3
func (ws *WeakSetObject) Has(value Value) bool
Has checks if a value exists in the WeakSet
Source Files
¶
- async.go
- async_runtime.go
- bytecode.go
- cache.go
- cache_prototype.go
- call.go
- dataview.go
- exceptions.go
- function.go
- heap.go
- ic_site_cache.go
- json_marshal.go
- object.go
- op_definedataproperty.go
- op_definemethod.go
- op_definemethodcomputed.go
- op_definemethodcomputedenumerable.go
- op_definemethodenumerable.go
- op_getprop.go
- op_setindex_function.go
- op_setprop.go
- op_spreadnew.go
- op_typeguard.go
- promise.go
- property_helpers.go
- prototypes.go
- realm.go
- regex.go
- typed_array.go
- value.go
- vm.go
- vm_init.go