storage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storage holds the values, the objects and the shapes of JavaScript, and the operations on them that run no code.

Index

Constants

View Source
const (
	// BufferAfter is the number of concatenations in a row after which the next one makes its
	// result the tail or the head of a builder.
	BufferAfter ConcatCount = 3

	// MinBufferedLength is the smallest length in bytes of a string that is the tail or the head
	// of a builder.
	MinBufferedLength = 32

	// MaxStackConcatBytes bounds scratch space for multi-part concatenation.
	MaxStackConcatBytes = 64

	PrependShift = 2
)
View Source
const (
	CacheNone uint8 = iota

	// CacheOwn: the property is in Slot of the receiver.
	CacheOwn

	// CacheProto: Ref points to an inherited data slot or the undefined slot for a cached miss.
	CacheProto

	// CacheGetter and CacheSetter: Holder is the function to call.
	CacheGetter
	CacheSetter

	// CacheOwnGetter: the property is an accessor in Slot of the receiver, whose getter is called.
	CacheOwnGetter

	// CacheAdd: a store adds the property and moves the receiver to the shape Next.
	CacheAdd
)

Kinds of inline cache entries.

View Source
const (
	// ObjInterned marks a string that is the unique representative of its contents,
	// so that it can serve as a property key compared by identity.
	ObjInterned uint8 = 1 << iota

	// ObjASCIIKnown says that ObjASCII is valid.
	ObjASCIIKnown
	ObjASCII

	// ObjNotExtensible marks an object that refuses new properties.
	ObjNotExtensible

	// ObjIsProto marks an object that is the prototype of some shape. Changing the properties
	// of such an object invalidates the inline caches that looked through it.
	ObjIsProto

	// ObjFrozenLength marks an array whose length is not writable.
	ObjFrozenLength

	// ObjSparse marks an object that has properties with array index keys outside elems:
	// they are in the shape under their canonical string keys. elems only ever holds
	// data properties that are writable, enumerable and configurable.
	ObjSparse

	// ObjExotic marks an object whose named properties cannot be found by looking at its shape alone.
	ObjExotic
)

Object flags.

View Source
const (
	// PinnedSlots and PinnedElems mark slots and elements that may be in the object's allocation.
	PinnedSlots uint8 = 1 << iota
	PinnedElems

	// PinnedGlobalSlots marks the slots of a global object or of the global lexical bindings,
	// which the inline caches of global variables point into.
	PinnedGlobalSlots
)

Object pinned bits, which mark storage that stays reachable after the slots or the elements of the object move out of it.

View Source
const (
	ClassObject class = iota
	ClassArray
	ClassFunction
	ClassError
	ClassBoolean
	ClassNumber
	ClassString
	ClassSymbol
	ClassBigInt
	ClassArguments
	ClassDate
	ClassRegExp
	ClassMap
	ClassSet
	ClassWeakMap
	ClassWeakSet
	ClassWeakRef
	ClassFinalizationRegistry
	ClassArrayBuffer
	ClassTypedArray
	ClassDataView
	ClassPromise
	ClassGenerator
	ClassProxy
	ClassGlobalProxyHandler
	ClassIterator
	ClassForIn
	ClassPrivateName
	ClassModuleNamespace
	ClassRawJSON
	ClassDisposableStack
	ClassAsyncDisposableStack
	ClassTemporal
	ClassIntl
	ClassShadowRealm
	ClassModuleSource
	// ClassLazy is an ordinary object whose properties are not defined yet.
	ClassLazy

	// ClassEvalScope is the scope of OpEvalScope, whose properties are the variables that
	// direct evals declare in a function.
	ClassEvalScope
)
View Source
const (
	HasValue uint8 = 1 << iota
	HasWritable
	HasGet
	HasSet
	HasEnumerable
	HasConfigurable
)

Fields of a property descriptor that are present.

View Source
const (
	FlagEnumerable uint8 = 1 << iota
	FlagWritable
	FlagConfigurable
	FlagAccessor

	FlagsData   = FlagEnumerable | FlagWritable | FlagConfigurable
	FlagsHidden = FlagWritable | FlagConfigurable
)

Property attributes.

View Source
const (
	LookupAbsent      namedLookupKind = iota // The chain ended. A miss or property addition can be cached.
	LookupSlot                               // A slot supplies the value or accessor.
	LookupLength                             // The implicit length of an array or string has no slot.
	LookupNumericMiss                        // A typed array answers undefined on reads and handles stores itself.
	LookupDelegate                           // The holder must perform each operation.
)
View Source
const (
	OrdinaryRoot shapeFamily = iota
	ArrayRoot
	TypedArrayRoot
	LazyFunctionRoot
	// These families start a separate tree for each request.
	DelegatedRoot
	PrimitiveStringRoot
)
View Source
const (
	TypeofUndefined = iota
	TypeofNumber
	TypeofBoolean
	TypeofString
	TypeofSymbol
	TypeofBigInt
	TypeofFunction
	TypeofObject
	TypeofCount
)

The results of the typeof operator.

View Source
const KindFirstObject = KindHTMLDDA

Every kind from KindFirstObject on is an object in the JavaScript sense.

View Source
const MaxArrayIndex = 1<<32 - 2

MaxArrayIndex is the largest array index, 2**32 - 2.

View Source
const MaxInlineObjectValues = 16
View Source
const MaxPresizedElems = 1024

MaxPresizedElems is the largest length for which ArrayCreate allocates the storage of the elements upfront.

View Source
const MaxStringLength = 1<<(27+3*(strconv.IntSize/64)) - 1

MaxStringLength is the largest length a string may have, in bytes. It is smaller where an int has 32 bits.

View Source
const MinElems = 4

MinElems is the number of elements that the storage of an array has room for when it is first allocated to add an element.

View Source
const MissingKey = 1

MissingKey is the Idx of a query key whose Key has the contents of no property key.

View Source
const ObjExclusive = ObjSparse

ObjExclusive marks a string that is the tail of its builder and that nothing refers to but the register of the variable whose append made it, so that the next append to the variable can extend it in place. Its bit is that of ObjSparse, which only objects use.

View Source
const ObjReversed = ObjFrozenLength

ObjReversed marks a string whose Text holds its contents with the bytes in reverse order. Its bit is that of ObjFrozenLength, which only arrays and private names use. The byte length, the ASCII-ness and the UTF-16 length of Text are those of the contents, so only a read of the contents themselves needs Object.Str.

View Source
const PollChunk = 1 << 20

PollChunk is the number of elements that a bulk copy moves between two checks for an interruption.

View Source
const PollInterval = 1 << 16

PollInterval is the number of steps of a loop that runs no JavaScript, such as reading, comparing or storing an element, between two checks for an interruption.

View Source
const PrivateShapeThreshold = 128

PrivateShapeThreshold is the number of properties above which an object stops sharing its shape.

View Source
const SharedElems = PinnedGlobalSlots << 1

SharedElems is the bit of Object.Pinned that marks elements which are the constants of an array literal, shared by the arrays that it made. They have no holes and no room for more elements.

View Source
const ValidateExec = false

ValidateExec says whether the interpreter checks the code that it runs, as validate_on.go describes.

Variables

View Source
var BigInt64Object = &Object{Kind: KindBigInt, objectTail: &zeroTail}

BigInt64Object is the O of every BigInt that fits in an int64. Every other BigInt is an object of its own holding a *big.Int, so each BigInt has exactly one representation.

View Source
var False = Value{O: FalseObject}

False is the value false.

View Source
var FalseObject = &Object{Kind: KindFalse, objectTail: &zeroTail}
View Source
var Hole = Value{O: HoleObject}
View Source
var HoleObject = &Object{Kind: KindHole, objectTail: &zeroTail}
View Source
var Null = Value{O: NullObject}

Null is the value null.

View Source
var NullObject = &Object{Kind: KindNull, objectTail: &zeroTail}
View Source
var NumberObject = &Object{Kind: KindNumber, objectTail: &zeroTail}
View Source
var True = Value{O: TrueObject}

True is the value true.

View Source
var TrueObject = &Object{Kind: KindTrue, objectTail: &zeroTail}

Functions

func Add64

func Add64(x, y int64) (int64, bool)

Add64 returns x + y, and reports whether it does not overflow.

func CheckValue

func CheckValue(v Value)

func Clip

func Clip[S ~string](s S, max int, suffix S) S

Clip returns s, or its longest prefix that ends at a character boundary and leaves room for the suffix within max bytes, followed by the suffix.

func CompareStrings

func CompareStrings(a, b Value) int

CompareStrings orders a and b by UTF-16 code units and returns -1, 0, or 1. Both values must be strings.

func CopyBufferBytes

func CopyBufferBytes(dst *ArrayBuffer, dstOffset int, src *ArrayBuffer, srcOffset, n int)

CopyBufferBytes copies n bytes from src at srcOffset to dst at dstOffset, as copy does when the two have the same data block. Both ranges must be within the buffers, which are not detached.

func CopyPolled

func CopyPolled[T any](p *Poller, dst, src []T) int

CopyPolled is copy for slices that do not overlap, checking for an interruption while it copies many elements.

func DisplayString

func DisplayString(v Value) string

DisplayString is agent.DisplayString.

func DisposableStackState

func DisposableStackState(v Value, async bool) any

DisposableStackState returns the state of v when it is a DisposableStack object, or an AsyncDisposableStack object when async is set, and nil otherwise.

func ElementBits

func ElementBits(t element.Type, v Value) uint64

ElementBits returns the encoding of the numeric value v as an element of the type t. v must be a BigInt for a BigInt type and a number otherwise.

func ElementCount

func ElementCount(v Value) int

ElementCount returns how many elements the array v holds in memory, holes included, or 0 when v is not an array.

func ErrorStack

func ErrorStack(v Value) (wtf8.String, bool)

ErrorStack returns the stack trace that agent.RecordStack recorded for the error object v. It reports false when v has no [ErrorData] internal slot or no recorded stack trace.

func GoError

func GoError(v Value) error

GoError returns the Go error that v was made from by ExecutionContext.NewGoError, or nil when it was not.

func IntlData

func IntlData(v Value) any

IntlData returns the internal slots of the Intl object v, or nil when v is not one.

func IsASCII

func IsASCII(v Value, s wtf8.String) bool

IsASCII reports whether s, which is the Value.RawString of v when v is a string, consists of ASCII characters only.

func IsCanonicalNumericString

func IsCanonicalNumericString(key *Object) bool

IsCanonicalNumericString reports whether CanonicalNumericIndexString returns a number for the string key. The array indices are not named keys, so they are not considered.

func IsCompatiblePropertyDescriptor

func IsCompatiblePropertyDescriptor(extensible bool, d, cur *PropDesc, hasCur bool) bool

IsCompatiblePropertyDescriptor implements IsCompatiblePropertyDescriptor. hasCur reports whether the property described by cur exists.

func IsError

func IsError(v Value) bool

IsError reports whether v is an object with an [ErrorData] internal slot.

func IsStrictlyEqual

func IsStrictlyEqual(a, b Value) bool

IsStrictlyEqual implements IsStrictlyEqual.

func IteratorState

func IteratorState(v Value) any

IteratorState returns the state of the built-in iterator object v, or nil when v is not such an object.

func JoinsPair

func JoinsPair(x wtf8.String, xr bool, y wtf8.String, yr bool) bool

JoinsPair reports whether the contents of two strings form a surrogate pair where they meet, so that their bytes do not simply concatenate. x and y are the Value.RawString of the strings, and xr and yr report whether they are reversed.

func NewClosure

func NewClosure(p *FuncProto) (*Object, []Upvalue)

NewClosure returns an object with the function state of a new closure of p, whose upvalues are nil, and the storage for its copied upvalues. The object is zero otherwise.

func NewObjectWithStorage

func NewObjectWithStorage(n int) (*Object, []Value)

NewObjectWithStorage returns an object without a tail of its own and storage for n values. The object is zero but for its pinned bits. For a small n, both are a single allocation, and the storage may have room for more values.

func NewTailObjectWithStorage added in v0.2.0

func NewTailObjectWithStorage(n int) (*Object, []Value)

NewTailObjectWithStorage is NewObjectWithStorage for an object with a tail of its own, such as an array.

func NonConfigurableCompatible

func NonConfigurableCompatible(cur, d *PropDesc) bool

NonConfigurableCompatible reports whether ValidateAndApplyPropertyDescriptor accepts d for the existing property described by cur, which is not configurable.

func NumberIndex

func NumberIndex(n float64) (uint32, bool)

NumberIndex returns the array index that the number n stands for as a property key.

func SameValue

func SameValue(a, b Value) bool

SameValue implements SameValue.

func SameValueZero

func SameValueZero(a, b Value) bool

SameValueZero implements SameValueZero.

func SetDateValue

func SetDateValue(v Value, tv float64)

SetDateValue sets the [[DateValue]] of the Date object v to tv.

func SetNumber

func SetNumber(r *Value, n float64)

SetNumber stores the number n in the register r.

func SetValueInBuffer

func SetValueInBuffer(b []byte, t element.Type, v Value, littleEndian bool)

SetValueInBuffer implements SetValueInBuffer for the bytes b, which hold at least one element of the type t. v must be a BigInt for a BigInt type and a number otherwise.

func ShortStringsJoinPair

func ShortStringsJoinPair(a Value, aN int, b Value, bN int) bool

ShortStringsJoinPair reports whether the unreversed strings form a surrogate pair at their join.

func StringIndex

func StringIndex(s wtf8.String) (uint32, bool)

StringIndex returns the array index whose canonical string form is s.

func SymbolDescription

func SymbolDescription(sym *Object) (wtf8.String, bool)

SymbolDescription returns the description of the symbol sym and whether it has one.

func TailBuilder

func TailBuilder(o *Object) *strings.Builder

TailBuilder returns the builder whose tail the string o is, or nil.

func TemporalData

func TemporalData(v Value) any

TemporalData returns the internal slots of the Temporal object v, or nil when v is not one.

func ThisBooleanValue

func ThisBooleanValue(v Value) (bool, bool)

ThisBooleanValue implements ThisBooleanValue. It reports false when the specification throws.

func ThisNumberValue

func ThisNumberValue(v Value) (float64, bool)

ThisNumberValue implements ThisNumberValue. It reports false when the specification throws.

func ThisTimeValue

func ThisTimeValue(v Value) (float64, bool)

ThisTimeValue implements thisTimeValue. It reports false when the specification throws.

func ToBoolean

func ToBoolean(v Value) bool

ToBoolean implements ToBoolean.

func Truncated

func Truncated[T any](s []T, n int) []T

Truncated returns the first n values of s, and clears the others.

func TypedArrayFlags

func TypedArrayFlags(o *Object) uint8

TypedArrayFlags returns the attributes of the elements of the typed array o.

func TypedArrayHas

func TypedArrayHas(o *Object, i uint32) bool

TypedArrayHas implements IsValidIntegerIndex for an array index.

func TypedArrayImmutable

func TypedArrayImmutable(o *Object) bool

TypedArrayImmutable reports whether the buffer of the typed array o is immutable.

func TypedArrayLength

func TypedArrayLength(o *Object) int

TypedArrayLength returns the length of o, or 0 when o is out of bounds.

func WithoutLast

func WithoutLast[T any](s []T) []T

WithoutLast returns s without its last value, which it clears.

func WriteReversed

func WriteReversed(sb *strings.Builder, s wtf8.String)

WriteReversed appends the bytes of s to sb in reverse order.

Types

type ArrayBuffer

type ArrayBuffer struct {
	// Data is the data block of a buffer that is not shared, and nil for a shared buffer.
	Data []byte

	Immutable bool
	// contains filtered or unexported fields
}

ArrayBuffer is the data block of an ArrayBuffer or SharedArrayBuffer object.

func ArrayBufferData

func ArrayBufferData(v Value) *ArrayBuffer

ArrayBufferData returns the [ArrayBufferData] of v, or nil when v is neither an ArrayBuffer nor a SharedArrayBuffer object.

func (*ArrayBuffer) ByteLength

func (b *ArrayBuffer) ByteLength() int

ByteLength returns the length of b in bytes, which is 0 when b is detached.

func (*ArrayBuffer) Bytes

func (b *ArrayBuffer) Bytes() []byte

Bytes returns the contents of b, or nil when b is shared or detached. The slice stays valid until b is resized or detached, and must not be modified when b is immutable. The bytes of a shared buffer are reached with ArrayBuffer.Lock.

func (*ArrayBuffer) Detach

func (b *ArrayBuffer) Detach()

Detach implements the steps of DetachArrayBuffer that follow its checks: b has no data block afterwards. b must be neither shared nor immutable. Detaching a detached b does nothing.

func (*ArrayBuffer) Grow

func (b *ArrayBuffer) Grow(n int) bool

Grow implements the growing of the growable SharedArrayBuffer b to n bytes, which must not exceed ArrayBuffer.MaxByteLength. It reports false, without changing b, when n is smaller than the length, which another agent may have grown.

func (*ArrayBuffer) HasDetachKey

func (b *ArrayBuffer) HasDetachKey() bool

HasDetachKey reports whether [[ArrayBufferDetachKey]] of b is not empty.

func (*ArrayBuffer) IsDetached

func (b *ArrayBuffer) IsDetached() bool

IsDetached implements IsDetachedBuffer.

func (*ArrayBuffer) IsImmutable

func (b *ArrayBuffer) IsImmutable() bool

IsImmutable implements IsImmutableBuffer.

func (*ArrayBuffer) IsResizable

func (b *ArrayBuffer) IsResizable() bool

IsResizable reports whether b is a resizable ArrayBuffer or a growable SharedArrayBuffer.

func (*ArrayBuffer) IsShared

func (b *ArrayBuffer) IsShared() bool

IsShared implements IsSharedArrayBuffer.

func (*ArrayBuffer) Lock

func (b *ArrayBuffer) Lock() []byte

Lock returns the contents of b. For a shared b, it also keeps the other agents from accessing the data block until ArrayBuffer.Unlock is called. No JavaScript may run and no other shared data block may be locked in between. The slice is valid until then.

func (*ArrayBuffer) MaxByteLength

func (b *ArrayBuffer) MaxByteLength() int

MaxByteLength returns [[ArrayBufferMaxByteLength]] of a resizable or growable b, and its length otherwise.

func (*ArrayBuffer) Resize

func (b *ArrayBuffer) Resize(n int)

Resize changes the length of the resizable b, which is not shared, to n, which must not exceed ArrayBuffer.MaxByteLength. New bytes are zero.

func (*ArrayBuffer) SameDataBlock

func (b *ArrayBuffer) SameDataBlock(c *ArrayBuffer) bool

SameDataBlock reports whether b and c have the same data block.

func (*ArrayBuffer) SharedDataBlock

func (b *ArrayBuffer) SharedDataBlock() *SharedDataBlock

SharedDataBlock returns the data block of the shared buffer b, or nil when b is not shared. Another agent, which may run on another goroutine, creates a SharedArrayBuffer over the block with RealmPart.NewSharedArrayBufferObject.

func (*ArrayBuffer) Unlock

func (b *ArrayBuffer) Unlock()

Unlock ends the access of ArrayBuffer.Lock.

type AtomicOp

type AtomicOp uint8

AtomicOp is the operation of TypedArray.AtomicReadModifyWrite.

const (
	AtomicAdd AtomicOp = iota
	AtomicAnd
	AtomicExchange
	AtomicOr
	AtomicSub
	AtomicXor

	// AtomicCompareExchange stores the replacement when the element equals the operand.
	AtomicCompareExchange
)

type BigIntObject

type BigIntObject struct {
	PropertyObject
	Integer big.Int
}

BigIntObject holds a BigInt and its integer header in one allocation.

func (*BigIntObject) InitBigInt added in v0.2.0

func (o *BigIntObject) InitBigInt(i *big.Int) Value

InitBigInt makes o, which must be zero, the BigInt i, which must not fit in an int64.

type BoundFunc

type BoundFunc struct {
	Target *Object
	This   Value
	Args   []Value
}

type CacheEntry

type CacheEntry struct {
	// Shape is the shape of the receiver the entry is valid for.
	Shape *Shape
	Kind  uint8
	Slot  int32

	Holder *Object

	// Epoch is the value of [Space.ProtoEpoch] the entry was filled at.
	Epoch uint32

	Next *Shape

	Ref *Value
}

CacheEntry is what an inline cache remembers about one receiver shape.

func (*CacheEntry) AddTo

func (e *CacheEntry) AddTo(o *Object, v Value)

AddTo adds the property that e, an entry that adds one, remembers to o, whose shape is that of e, with the value v.

func (*CacheEntry) OwnValue

func (e *CacheEntry) OwnValue(o *Object) Value

OwnValue returns the value or the accessors that e, an entry for an own property, remembers of o, whose shape is that of e.

func (*CacheEntry) SetInherited

func (e *CacheEntry) SetInherited(s *Shape, kind uint8, epoch uint32)

SetInherited records a lookup that depends on the receiver having no own property of that name.

type ClassElement

type ClassElement struct {
	Kind int
	Key  Value
	Val  *Object

	// Init is the initial value of a field without an initializer function.
	Init Value

	// Dec is what the decorators of a field add to it, or nil.
	Dec *FieldDecoration

	// Cache is the shape transition that defining a public field takes.
	Cache PropCache
}

ClassElement is an element that the constructor of a class adds to every instance.

type CmpResult

type CmpResult uint8
const (
	CmpLess CmpResult = iota
	CmpEqual
	CmpGreater
	CmpUndefined
)

func CompareInt64Number

func CompareInt64Number(x int64, f float64) CmpResult

CompareInt64Number compares the integer x with the number f.

func CompareInt64s

func CompareInt64s(x, y int64) CmpResult

func CompareNumbers

func CompareNumbers(x, y float64) CmpResult

func (CmpResult) Reverse

func (c CmpResult) Reverse() CmpResult

Reverse returns the result of comparing b with a, given that of comparing a with b.

type CommonKey

type CommonKey uint8

CommonKey identifies a string property key that the engine provides.

const (
	KeyLength CommonKey = iota
	KeyPrototype
	KeyConstructor
	KeyName
	KeyMessage
	KeyStack
	KeyCause
	KeyErrors
	KeyError
	KeySuppressed
	KeyToString
	KeyValueOf
	KeyToJSON
	KeyCall
	KeyApply
	KeyBind
	KeyGet
	KeySet
	KeyValue
	KeyWritable
	KeyEnumerable
	KeyConfigurable
	KeyNext
	KeyDone
	KeyReturn
	KeyThrow
	KeyThen
	KeyCallee
	KeyCaller
	KeyArguments
	KeyIndex
	KeyInput
	KeyGroups
	KeyLastIndex
	KeyRaw
	KeySource
	KeyFlags
	KeyDefault
	KeyGetPrototypeOf
	KeySetPrototypeOf
	KeyIsExtensible
	KeyPreventExtensions
	KeyGetOwnPropertyDescriptor
	KeyDefineProperty
	KeyHas
	KeyDeleteProperty
	KeyOwnKeys
	KeyConstruct
	KeyAdd
	KeyKeys
	KeySize
	KeyStatus
	KeyReason
	KeyMode
	KeyPadding
	KeyToLocaleString
	KeyToISOString
	KeyHasIndices
	KeyGlobal
	KeyIgnoreCase
	KeyMultiline
	KeyDotAll
	KeyUnicode
	KeyUnicodeSets
	KeySticky
	KeyExec
	CommonKeyCount
)

type ConcatCount

type ConcatCount uint8

ConcatCount counts the concatenations in a row that made a string, each up to BufferAfter: in its low bits those whose left operand was the result of the one before, and from PrependShift on those whose right operand was.

func NextCount

func NextCount(ca, cb ConcatCount) ConcatCount

NextCount returns the ConcatCount of the result of a concatenation without a builder whose left and right operands have the counts ca and cb.

func (ConcatCount) Appends

func (c ConcatCount) Appends() ConcatCount

Appends returns the number of concatenations in a row each onto the result of the one before as its left operand.

func (ConcatCount) Prepends

func (c ConcatCount) Prepends() ConcatCount

Prepends returns the number of concatenations in a row each onto the result of the one before as its right operand.

type DataView

type DataView struct {
	// contains filtered or unexported fields
}

DataView is the state of a DataView object.

func DataViewData

func DataViewData(v Value) *DataView

DataViewData returns the state of the DataView v, or nil when v is not a DataView.

func (*DataView) Buffer

func (d *DataView) Buffer() *Object

Buffer returns [[ViewedArrayBuffer]] of d.

func (*DataView) ByteLength

func (d *DataView) ByteLength() (int, bool)

ByteLength implements GetViewByteLength. It reports false when the view is out of bounds, which includes a detached buffer.

func (*DataView) ByteOffset

func (d *DataView) ByteOffset() int

ByteOffset returns [[ByteOffset]] of d.

func (*DataView) Lock

func (d *DataView) Lock() ([]byte, bool)

Lock locks the buffer as ArrayBuffer.Lock does and returns the bytes that d views. It reports false when the buffer is detached or d is out of bounds. Always pair Lock with DataView.Unlock. The slice must not be modified when the buffer is immutable.

func (*DataView) Unlock

func (d *DataView) Unlock()

Unlock ends the access of DataView.Lock.

type Error

type Error struct {
	// Value is the thrown value.
	Value Value
	// contains filtered or unexported fields
}

Error is a JavaScript exception that reached Go.

func (*Error) Error

func (e *Error) Error() string

type ErrorData

type ErrorData struct {

	// Pending is set until stack is formatted from Name, Msg and Calls.
	Pending bool

	// Name in WTF-8 and Msg in UTF-8 begin the stack trace, and Calls are its lines.
	Name  wtf8.String
	Msg   string
	Calls []StackCall

	// GoErr is the Go error that the error object was made from, or nil.
	GoErr error
	// contains filtered or unexported fields
}

ErrorData is the internal state of an error object that has a recorded stack trace.

type Extremum

type Extremum uint8

Extremum identifies Math.min or Math.max for agent.SetExtremum.

type FieldDecoration

type FieldDecoration struct {
	// Initializers are the initializers that the decorators returned, in the order they were applied.
	Initializers []*Object
	// Extra are the initializers that the decorators added with addInitializer.
	Extra []*Object
}

FieldDecoration is what the decorators of a field or an auto-accessor add to it.

type FuncProto

type FuncProto struct {
	*bytecode.Func

	Name   wtf8.String
	Code   []bytecode.Instr
	Consts []Value
	Keys   []*Object

	// Caches holds the inline caches, and is nil until a frame of the function is pushed.
	Caches []PropCache
	Protos []*FuncProto

	Templates []TemplateSite
	RegExps   []RegExpSite

	// Ncopied is the number of the upvalues that are copies of the variables, by
	// [bytecode.UpvalDesc.ByValue].
	Ncopied int

	Length  int
	Nparams int
	Nclear  int
	Nregs   int

	// ClearFrom is the first register from Nparams on that a new frame clears. The first
	// instructions write the registers between Nparams and ClearFrom before anything reads them.
	ClearFrom int

	Strict             bool
	IsGenerator        bool
	IsAsync            bool
	IsConstructor      bool
	IsClassConstructor bool
	IsDerived          bool
	NeedsExtra         bool

	// LegacyCallerArguments says whether the functions have the own properties caller and arguments
	// that implementations add to non-strict ordinary functions.
	LegacyCallerArguments bool

	// Script is the [[ScriptOrModule]] of the functions. Only scriptOrModuleOf reads it.
	Script any

	// Realm is the [[Realm]] of the functions. Each frame enters the context of the realm of its
	// linked code, including a replacement tail frame.
	Realm *RealmPart

	// ThisReg is the register that the first instruction loads this into, or -1 when the
	// first instruction does not load this. ThisSloppy says whether it converts this the way
	// a non-strict function sees it.
	ThisReg    int32
	ThisSloppy bool

	// HeapRegs says whether the frames of the functions keep their registers in their
	// generator instead of on the stack.
	HeapRegs bool

	// InlineFrames says whether the fast paths of the interpreter loop may push frames of the
	// functions: the inline caches exist, and the functions are neither generators, async
	// functions nor class constructors.
	InlineFrames bool

	// ReturnedProperty is the cache for x when the function starts with return this.x.
	ReturnedProperty *PropCache

	// Globals holds the inline caches of global variables, which Prepare allocates with
	// Caches. It comes after the fields that calls read.
	Globals []GlobalCache
	// contains filtered or unexported fields
}

FuncProto is the compiled code of a function in the form the interpreter runs, shared by all closures made from it.

func (*FuncProto) ClosurePrototype

func (p *FuncProto) ClosurePrototype() *Object

ClosurePrototype returns the prototype of the closures of p, which is a generator or async function.

func (*FuncProto) FirstCleared

func (p *FuncProto) FirstCleared(argc int) int

FirstCleared returns the first register that a new frame of p for argc arguments clears.

func (*FuncProto) Prepare

func (p *FuncProto) Prepare()

Prepare allocates the inline caches of p, which a frame of p needs.

type Function

type Function struct {
	// Code is the compiled code of a function written in JavaScript.
	Code *FuncProto

	// Upvals are the variables of enclosing functions that Code refers to.
	Upvals []*Upvalue

	// Info describes a native function. It is nil for any other function.
	Info *NativeInfo

	Bound *BoundFunc

	// Home is the object that super property accesses in a method start from.
	Home *Object

	// Fields are the elements that a class constructor adds to every instance, or nil when
	// there are none.
	Fields *[]ClassElement

	// Materialized is set once the initial properties, such as length and name, exist as slots.
	Materialized bool

	// Constructor says whether the function can be called with new.
	Constructor bool

	// Derived marks the constructor of a class with an extends clause.
	Derived bool

	// ClassConstructor marks a function that throws when called without new.
	ClassConstructor bool

	// Scopes points to the dynamic scopes that were open where the function was created,
	// innermost last, or is nil when none were.
	Scopes *[]*Object
	// contains filtered or unexported fields
}

Function is the state of a callable object.

func (*Function) CapturedScopes

func (f *Function) CapturedScopes() []*Object

CapturedScopes returns the dynamic scopes that were open where f was created, innermost last.

func (*Function) ChangeableInfo

func (f *Function) ChangeableInfo() *NativeInfo

ChangeableInfo returns the description of the native function f, which must not be a proxy, for changing it.

func (*Function) Frameless

func (f *Function) Frameless() bool

Frameless reports whether f, which may be nil, is a native function whose calls show no frame.

func (*Function) NativeName

func (f *Function) NativeName() wtf8.String

NativeName returns the initial value of the property name of the native function f.

type GlobalCache

type GlobalCache struct {
	Shape  *Shape
	Ref    *Value
	Holder *Object
}

GlobalCache is the inline cache of an instruction that accesses a global variable. Holder is the global object of the realm, or nil. While its shape matches, the binding exists. A resolution caches existence alone. Reads and writes also cache the initialized slot in Ref, and writes only cache writable bindings.

Declaring a global lexical binding or invalidating a cached global slot changes the global object's shape.

func (*GlobalCache) Remember

func (c *GlobalCache) Remember(global, holder *Object, p Prop)

Remember records that a binding of the realm with the global object global is p of holder, which is global or the global lexical bindings.

type InterruptSignal

type InterruptSignal struct {
	// Cause is the cause of the interruption.
	Cause error
}

InterruptSignal is what an interruption unwinds Go frames with. No JavaScript code can catch it.

type Intrinsic

type Intrinsic uint8

Intrinsic identifies an intrinsic object.

const (
	IntrinsicObjectPrototype Intrinsic = iota
	IntrinsicFunctionPrototype
	IntrinsicArrayPrototype
	IntrinsicStringPrototype
	IntrinsicNumberPrototype
	IntrinsicBooleanPrototype
	IntrinsicSymbolPrototype
	IntrinsicBigIntPrototype
	IntrinsicIteratorPrototype
	IntrinsicAsyncIteratorPrototype
	IntrinsicArrayIteratorPrototype
	IntrinsicStringIteratorPrototype
	IntrinsicMapIteratorPrototype
	IntrinsicSetIteratorPrototype
	IntrinsicRegExpStringIteratorPrototype
	IntrinsicIteratorHelperPrototype
	IntrinsicWrapForValidIteratorPrototype
	IntrinsicGeneratorPrototype
	IntrinsicAsyncGeneratorPrototype
	IntrinsicGeneratorFunctionPrototype
	IntrinsicAsyncFunctionPrototype
	IntrinsicAsyncGeneratorFunctionPrototype
	IntrinsicRegExpPrototype
	IntrinsicPromisePrototype
	IntrinsicMapPrototype
	IntrinsicSetPrototype
	IntrinsicDatePrototype
	IntrinsicSharedArrayBufferPrototype
	IntrinsicArrayBufferPrototype
	IntrinsicDataViewPrototype
	IntrinsicWeakMapPrototype
	IntrinsicWeakSetPrototype
	IntrinsicWeakRefPrototype
	IntrinsicFinalizationRegistryPrototype
	IntrinsicDisposableStackPrototype
	IntrinsicAsyncDisposableStackPrototype
	IntrinsicShadowRealmPrototype
	IntrinsicAbstractModuleSourcePrototype
	IntrinsicPromise
	IntrinsicArray
	IntrinsicObject
	IntrinsicFunction
	IntrinsicRegExp
	IntrinsicIterator
	IntrinsicArrayBuffer
	IntrinsicSharedArrayBuffer
	IntrinsicAbstractModuleSource

	IntrinsicTemporal

	IntrinsicIntl
	IntrinsicIntlDateTimeFormat
	IntrinsicIntlNumberFormat
	IntrinsicIntlSegmentsPrototype
	IntrinsicIntlSegmentIteratorPrototype

	// The Temporal namespace initializes this range of prototypes.
	IntrinsicTemporalInstantPrototype
	IntrinsicTemporalDurationPrototype
	IntrinsicTemporalPlainDatePrototype
	IntrinsicTemporalPlainTimePrototype
	IntrinsicTemporalPlainDateTimePrototype
	IntrinsicTemporalPlainYearMonthPrototype
	IntrinsicTemporalPlainMonthDayPrototype
	IntrinsicTemporalZonedDateTimePrototype

	// The Intl namespace initializes this range of prototypes.
	IntrinsicIntlCollatorPrototype
	IntrinsicIntlDateTimeFormatPrototype
	IntrinsicIntlDisplayNamesPrototype
	IntrinsicIntlDurationFormatPrototype
	IntrinsicIntlListFormatPrototype
	IntrinsicIntlLocalePrototype
	IntrinsicIntlNumberFormatPrototype
	IntrinsicIntlPluralRulesPrototype
	IntrinsicIntlRelativeTimeFormatPrototype
	IntrinsicIntlSegmenterPrototype

	// The prototypes of the native error types are in the order of engine.ErrorKind.
	IntrinsicErrorPrototype
	IntrinsicTypeErrorPrototype
	IntrinsicRangeErrorPrototype
	IntrinsicReferenceErrorPrototype
	IntrinsicSyntaxErrorPrototype
	IntrinsicEvalErrorPrototype
	IntrinsicURIErrorPrototype
	IntrinsicAggregateErrorPrototype
	IntrinsicSuppressedErrorPrototype

	IntrinsicThrowTypeError

	// The getters of the caller and arguments properties of non-strict ordinary functions.
	IntrinsicFunctionCallerGetter
	IntrinsicFunctionArgumentsGetter

	// The typed array constructors are in the order of [element.Type].
	IntrinsicInt8Array
	IntrinsicUint8Array
	IntrinsicUint8ClampedArray
	IntrinsicInt16Array
	IntrinsicUint16Array
	IntrinsicInt32Array
	IntrinsicUint32Array
	IntrinsicFloat16Array
	IntrinsicFloat32Array
	IntrinsicFloat64Array
	IntrinsicBigInt64Array
	IntrinsicBigUint64Array

	// The prototypes of the typed array constructors are in the order of [element.Type].
	IntrinsicInt8ArrayPrototype
	IntrinsicUint8ArrayPrototype
	IntrinsicUint8ClampedArrayPrototype
	IntrinsicInt16ArrayPrototype
	IntrinsicUint16ArrayPrototype
	IntrinsicInt32ArrayPrototype
	IntrinsicUint32ArrayPrototype
	IntrinsicFloat16ArrayPrototype
	IntrinsicFloat32ArrayPrototype
	IntrinsicFloat64ArrayPrototype
	IntrinsicBigInt64ArrayPrototype
	IntrinsicBigUint64ArrayPrototype

	// The initial values of these functions are what the engine treats specially.
	IntrinsicFunctionPrototypeCall
	IntrinsicFunctionPrototypeApply
	IntrinsicEval
	IntrinsicFunctionPrototypeHasInstance
	IntrinsicArrayPrototypeValues
	IntrinsicArrayIteratorPrototypeNext
	IntrinsicArraySpeciesGetter
	IntrinsicTypedArrayPrototypeLengthGetter
	IntrinsicGeneratorPrototypeNext

	// The initial values of these functions are what the built-ins treat specially.
	IntrinsicRegExpPrototypeExec
	IntrinsicMapPrototypeSet
	IntrinsicMapPrototypeEntries
	IntrinsicMapIteratorPrototypeNext
	IntrinsicSetPrototypeAdd
	IntrinsicSetPrototypeHas
	IntrinsicSetPrototypeValues
	IntrinsicSetIteratorPrototypeNext
	IntrinsicWeakMapPrototypeSet
	IntrinsicWeakSetPrototypeAdd

	// The functions that the engine calls.
	IntrinsicJSONParse
)

type Kind

type Kind uint8
const (
	KindUndefined Kind = iota
	KindNumber
	KindNull
	KindFalse
	KindTrue
	KindString
	KindSymbol
	KindBigInt

	// KindHole is the content of an array element that does not exist. It never reaches JavaScript.
	KindHole

	// KindAccessor is the content of the slot of an accessor property. It never reaches JavaScript.
	KindAccessor

	// KindHTMLDDA is an object with the [[IsHTMLDDA]] internal slot (B.3.6).
	// It comes before KindObject, so that a check for KindObject or above excludes it.
	KindHTMLDDA
	KindObject
	KindArray
	KindFunction
)

type NamedLookup

type NamedLookup struct {
	Kind   namedLookupKind
	Holder *Object
	Prop   Prop
}

func (NamedLookup) Length

func (r NamedLookup) Length(receiver Value) Value

type Native

type Native struct {
	Index uint16

	// FastIndex is the index of what callers use instead of calling the function, or 0.
	FastIndex uint8
}

Native identifies a registered native function. The zero value identifies none.

func (Native) HasFast

func (n Native) HasFast() bool

HasFast reports whether there is something that callers use instead of calling the function.

type NativeInfo

type NativeInfo struct {
	// Native is the native function.
	Native Native

	// Name and Length are the initial values of the properties name and length.
	Name   wtf8.String
	Length int32

	// Extremum says that the function is Math.min or Math.max, which the interpreter computes
	// for two numbers.
	Extremum Extremum

	// Frameless says that calls of the function show no frame, as agent.SetFrameless describes.
	Frameless bool

	// Prototype is the intrinsic of Realm that the property prototype of the function holds,
	// when FixedPrototype is set. The property can then be neither changed nor deleted.
	Prototype      Intrinsic
	FixedPrototype bool

	// Realm is the [[Realm]] of the function, or nil for a proxy.
	Realm *RealmPart
}

NativeInfo is the description of a native function.

var ProxyInfo NativeInfo

ProxyInfo describes every callable proxy. It must not be modified.

type Object

type Object struct {
	Kind  Kind
	Class class

	// Pinned holds the pinned bits of the storage of slots and elems, and [SharedElems]. A string,
	// which has neither, holds its [ConcatCount] there instead.
	Pinned uint8
	// contains filtered or unexported fields
}

Object is every heap value: plain objects, arrays, functions, strings, symbols, and the singletons.

func NewArray

func NewArray(s *Shape, elems []Value) *Object

NewArray returns a new array with the shape s and the given elements, which it keeps.

func NewExoticObject

func NewExoticObject(s *Shape, c class, state any) *Object

NewExoticObject is NewObjectWithState for an object whose named properties cannot be found by looking at its shape alone.

func NewFunctionObject

func NewFunctionObject(s *Shape, fn *Function) *Object

NewFunctionObject returns a new function object with the shape s and the function state fn, whose initial properties are implicit (see RealmPart.FunctionShapeFor).

func NewGlobalObject

func NewGlobalObject(s *Shape, n int) *Object

NewGlobalObject returns a new object for global bindings with the shape s and room for n properties. The inline caches of global variables point into its slots.

func NewInstance

func NewInstance(s *Shape) *Object

NewInstance returns a new empty ordinary object with the shape s, with room for the properties that the objects with s have been given one after another so far, and for some more when they went on with different properties.

func NewMarker

func NewMarker(state any) *Object

NewMarker returns a new value with the internal state state that never reaches JavaScript.

func NewNamespaceObject

func NewNamespaceObject(s *Shape, state any) *Object

NewNamespaceObject is NewExoticObject for a module namespace object, which is not extensible.

func NewObject

func NewObject(s *Shape) *Object

func NewObjectWithState

func NewObjectWithState(s *Shape, c class, state any) *Object

NewObjectWithState returns a new object with the shape s, the class c and the internal state state, and no properties.

func NewPrivateName

func NewPrivateName(desc wtf8.String) *Object

NewPrivateName returns a new private name whose description is desc.

func NewProxyObject

func NewProxyObject(s *Shape, state *ProxyState, fn *Function) *Object

NewProxyObject is NewExoticObject for a proxy, whose [[Call]] and [[Construct]] are fn. fn is nil for a proxy that is not callable.

func NewRegExpObject

func NewRegExpObject(s *Shape, state *RegExpState) *Object

NewRegExpObject returns a new RegExp object with the shape s, whose only property is lastIndex, and the internal state state.

func ThisSymbolValue

func ThisSymbolValue(v Value) (*Object, bool)

ThisSymbolValue implements ThisSymbolValue. It reports false when the specification throws.

func (*Object) AppendElem

func (o *Object) AppendElem(v Value)

AppendElem appends v to the elements of o.

func (*Object) AppendSlot

func (o *Object) AppendSlot(v Value)

AppendSlot appends v to the slots of o.

func (*Object) ArrayIndex

func (o *Object) ArrayIndex() (uint32, bool)

ArrayIndex returns the array index whose canonical string form is the string o.

func (*Object) ClearBuilder added in v0.2.0

func (o *Object) ClearBuilder()

ClearBuilder records that the string o is no longer the tail or the head of a builder.

func (*Object) CodePointAt

func (o *Object) CodePointAt(i int) rune

CodePointAt returns the code point starting at UTF-16 index i. i must be in range.

func (*Object) CreationRealm

func (o *Object) CreationRealm() *RealmPart

func (*Object) DelegatesPropertyAccess

func (o *Object) DelegatesPropertyAccess() bool

DelegatesPropertyAccess reports whether a lookup must use the object's property operations even when its storage has no matching key.

func (*Object) ElemCount

func (o *Object) ElemCount() int

ElemCount returns how many elements o holds in memory, holes included.

func (*Object) ElemRoom

func (o *Object) ElemRoom() int

ElemRoom returns how many elements the storage of the elements of o has room for.

func (*Object) ElementAt

func (o *Object) ElementAt(i uint32) (Value, bool)

ElementAt returns the element i of o, and reports whether o holds it.

func (*Object) ElementList

func (o *Object) ElementList() ([]Value, bool)

ElementList returns a copy of the elements of the array o when reading them cannot run any JavaScript.

func (*Object) ElemsResizable

func (o *Object) ElemsResizable() bool

ElemsResizable is elemsComplete and elemsChangeable.

func (*Object) ElemsStorage

func (o *Object) ElemsStorage() int

ElemsStorage returns the number of values that the storage of the elements of o has room for, counting those before the elements that removing the first elements left unused.

func (*Object) ExtConcatCount

func (o *Object) ExtConcatCount() ConcatCount

ExtConcatCount returns the concatenation count of the string o, or 0.

func (*Object) ExtObject

func (o *Object) ExtObject() (*Object, bool)

ExtObject returns the object in the internal state of o, and reports whether there is one.

func (*Object) ExtState

func (o *Object) ExtState() any

ExtState returns the internal state of o.

func (*Object) ExtendExclusive added in v0.2.0

func (o *Object) ExtendExclusive(sb *strings.Builder, ascii bool)

ExtendExclusive makes the string o, which is marked ObjExclusive and was the tail of sb, hold the contents of sb after strings were appended to them. ascii reports whether the appended strings are ASCII.

func (*Object) Flags

func (o *Object) Flags() uint8

Flags returns the flags of o.

func (*Object) FreezeLength

func (o *Object) FreezeLength()

FreezeLength makes the length of the array o read-only.

func (*Object) GrowLength

func (o *Object) GrowLength(n uint32)

GrowLength makes the length of the array o n, which is greater.

func (*Object) HasElement

func (o *Object) HasElement() bool

HasElement reports whether o holds an element, checking for an interruption while it looks at many.

func (*Object) HasElementAt

func (o *Object) HasElementAt(i uint32) bool

HasElementAt reports whether o, which must have property storage, holds the element i.

func (*Object) HasHole

func (o *Object) HasHole() bool

HasHole reports whether one of the elements of o is a hole.

func (*Object) HasOwnMethod

func (o *Object) HasOwnMethod(key, method *Object) bool

HasOwnMethod is quiet.Context.HasOwnMethod.

func (*Object) HasProperties

func (o *Object) HasProperties() bool

HasProperties reports whether o has property storage, which primitive values lack.

func (*Object) HolesAreAbsent

func (o *Object) HolesAreAbsent() bool

HolesAreAbsent reports whether o is an array, and an array index that it does not store is absent from it and its prototypes, and finding that out runs no JavaScript. An array marked ObjSparse stores some indices in its shape.

func (*Object) HostDefined

func (o *Object) HostDefined() any

HostDefined returns the host-defined value of the agent that owns o, or nil for shared values.

func (*Object) IndicesInElements

func (o *Object) IndicesInElements() bool

IndicesInElements reports whether elems accounts for all own indexed properties.

func (*Object) InheritsMethod

func (o *Object) InheritsMethod(proto, key, method *Object) bool

InheritsMethod is quiet.Context.InheritsMethod.

func (*Object) InheritsNoIndex

func (o *Object) InheritsNoIndex() bool

InheritsNoIndex reports whether no prototype of o has a property with an array index, and looking for one runs no JavaScript. It says nothing about o itself.

func (*Object) InitBinding

func (o *Object) InitBinding(key *Object, v Value)

InitBinding sets the value of the binding key of the global lexical bindings o.

func (*Object) InitElems

func (o *Object) InitElems(storage []Value)

InitElems makes storage the elements of an object that has none.

func (*Object) InitSlots

func (o *Object) InitSlots(storage []Value)

InitSlots makes storage the slots of an object that has none.

func (*Object) IsASCII

func (o *Object) IsASCII() bool

IsASCII reports whether the string o consists of ASCII characters only.

func (*Object) IsRawJSON

func (o *Object) IsRawJSON() bool

IsRawJSON reports whether o has the internal slot [[IsRawJSON]].

func (*Object) IsRegExpObject

func (o *Object) IsRegExpObject() bool

IsRegExpObject reports whether o is a RegExp object.

func (*Object) KnownArrayIndex

func (o *Object) KnownArrayIndex() (uint32, bool)

KnownArrayIndex returns the array index that the string o stands for, if it is known already. It reports false otherwise, even when o is an array index.

func (*Object) Length

func (o *Object) Length() uint32

Length returns the length of the array o.

func (*Object) MakeHTMLDDA

func (o *Object) MakeHTMLDDA()

MakeHTMLDDA gives the function object o the internal slot [[IsHTMLDDA]].

func (*Object) MakeNonExtensible

func (o *Object) MakeNonExtensible()

MakeNonExtensible makes o refuse new properties.

func (*Object) MakePrivate

func (o *Object) MakePrivate()

MakePrivate gives o a shape of its own, so that no inline cache filled for another object applies to it.

func (*Object) MarkExclusive added in v0.2.0

func (o *Object) MarkExclusive()

MarkExclusive marks the string o, a new tail that only the register of a variable refers to, ObjExclusive.

func (*Object) Meta

func (o *Object) Meta() *ObjectMeta

Meta returns the side data of o, or nil when it has none.

func (*Object) MoveElemsTo

func (o *Object) MoveElemsTo(room int)

MoveElemsTo moves the elements of o to new storage with room for room elements in all.

func (*Object) OwnFunction

func (o *Object) OwnFunction() *Function

OwnFunction gives o its own function state before an instance-specific change.

func (*Object) PlainElems

func (o *Object) PlainElems() ([]Value, bool)

PlainElems returns the elements of o, which the caller must not modify, when o is an array whose elements can be read without running any JavaScript. o may be nil.

func (*Object) PushElement

func (o *Object) PushElement(v Value)

PushElement appends v to the elements of the array o and sets its length.

func (*Object) Raw

func (o *Object) Raw() Raw

Raw returns the raw access to o.

func (*Object) RegExpLegacyFeaturesEnabled

func (o *Object) RegExpLegacyFeaturesEnabled() bool

RegExpLegacyFeaturesEnabled implements the [[LegacyFeaturesEnabled]] slot of the RegExp object o: whether o was created for the RegExp constructor itself.

func (*Object) RegExpMatcher

func (o *Object) RegExpMatcher() *regexp.Regexp

RegExpMatcher returns the compiled pattern of the RegExp object o, or nil when o is not a RegExp object.

func (*Object) RegExpOriginal

func (o *Object) RegExpOriginal() (source, flags wtf8.String)

RegExpOriginal returns the original source and flags of the RegExp object o.

func (*Object) RemoveFirstElement

func (o *Object) RemoveFirstElement() (Value, bool)

RemoveFirstElement removes the first element of the array o and returns it. It reports false and does nothing when o is empty or needs the generic algorithm.

func (*Object) RemoveLastElement

func (o *Object) RemoveLastElement() (Value, bool)

RemoveLastElement removes the last element of the array o and returns it. It reports false and does nothing when o is empty or needs the generic algorithm.

func (*Object) RenewRegExp

func (o *Object) RenewRegExp(s *Shape)

RenewRegExp makes the RegExp object o like a new one whose shape is s.

func (*Object) RenewShape

func (o *Object) RenewShape()

RenewShape gives o a private shape with the properties of its shape, which no inline cache has seen.

func (*Object) ReserveElems

func (o *Object) ReserveElems(n int)

ReserveElems gives the elements of o room for n more elements.

func (*Object) ReserveSlots

func (o *Object) ReserveSlots(n int)

ReserveSlots gives the slots of o room for n more values.

func (*Object) SetArrayIndex

func (o *Object) SetArrayIndex(i uint32)

SetArrayIndex records that the string o stands for the array index i.

func (*Object) SetElement

func (o *Object) SetElement(i int64, v Value) bool

SetElement stores v as the own property of o with the integer index i when Element returns that property, o is not a typed array and its elements are not shared (see SharedElems), and reports whether it did.

func (*Object) SetExtState

func (o *Object) SetExtState(v any)

SetExtState sets the internal state of o to v.

func (*Object) SetText added in v0.2.0

func (o *Object) SetText(s wtf8.String)

SetText makes s the text of the string or the symbol o.

func (*Object) Shape

func (o *Object) Shape() *Shape

Shape returns the layout of the slots of o, or nil for the singletons and internal values.

func (*Object) Share added in v0.2.0

func (o *Object) Share()

Share clears ObjExclusive of the string o.

func (*Object) SlotCount

func (o *Object) SlotCount() int

SlotCount returns the number of slots of o.

func (*Object) SlotValue

func (o *Object) SlotValue(p Prop) Value

SlotValue returns the value or the accessors of p, an own property of o.

func (*Object) SourceText

func (f *Object) SourceText() wtf8.String

SourceText returns the result of Function.prototype.toString for the function f.

func (*Object) StartMaterialized

func (o *Object) StartMaterialized(s *Shape) *Function

StartMaterialized makes the function o, which has no properties, one with the shape s and no implicit properties, and returns its state.

func (*Object) StoreData

func (o *Object) StoreData(p Prop, v Value) bool

StoreData stores v in p, an own property of o, and reports whether p is a writable data property.

func (*Object) StoreElement

func (o *Object) StoreElement(i uint32, v Value)

StoreElement stores v, which can be a hole, as the element i of o. HasElementAt must report true for i.

func (*Object) StoreMapped

func (o *Object) StoreMapped(p Prop, v Value)

StoreMapped stores v in p, an index property of the arguments object o that maps to a parameter.

func (*Object) Str

func (o *Object) Str() wtf8.String

Str returns the content of the string o in WTF-8.

func (*Object) StringLength

func (o *Object) StringLength() int

StringLength returns the length of the string o in UTF-16 code units.

func (*Object) Substring

func (o *Object) Substring(start, end int) wtf8.String

Substring returns the code units from start up to end of the string o. The indices must be in range and in order.

func (*Object) TakeDataProperties

func (dst *Object) TakeDataProperties(from *Object) bool

TakeDataProperties gives the empty ordinary object dst the properties of from and reports true when creating them on dst one by one would give dst the shape and the elements of from. Otherwise it does nothing and reports false.

func (*Object) Text

func (o *Object) Text() wtf8.String

Text returns the content of a string or the description of a symbol. A string marked ObjReversed holds its bytes in reverse order. Packed-string sentinels use zero bytes to carry only the byte length. Text is empty for the other primitive values, and o must not be an object.

func (*Object) UnitAt

func (o *Object) UnitAt(i int) uint16

UnitAt returns the code unit i of the string o. i must be in range.

func (*Object) UnitIndexOf

func (o *Object) UnitIndexOf(sub wtf8.String, from int, poll func()) int

UnitIndexOf returns the index in code units of the first occurrence of sub in the string o at or after from, or -1. poll, which may be nil, is called now and then during a long search.

func (*Object) UnitLastIndexOf

func (o *Object) UnitLastIndexOf(sub wtf8.String, from int, poll func()) int

UnitLastIndexOf returns the index in code units of the last occurrence of sub in the string o that starts at or before from, or -1. poll is as for Object.UnitIndexOf.

func (*Object) Unreverse

func (o *Object) Unreverse()

Unreverse makes the reversed string o hold its contents in order.

type ObjectMeta

type ObjectMeta struct {
	// Length and Cursor are the cached UTF-16 view of a string that is not ASCII:
	// its length, or 0 before it is known, and the position of the most recent access.
	// Only a string of at most MaxStringLength bytes has them, so they fit in 32 bits.
	Length int32
	Cursor stringPos

	// Ext is the internal state of the object that has this side data.
	Ext any
	// contains filtered or unexported fields
}

ObjectMeta is the side data that few objects need: what indexing a non-ASCII string needs, the entries in weak collections of an object or a symbol, the empty shapes of the objects whose prototype is this object, and the room that removing the first elements of an array left.

type Poller

type Poller struct {
	InterruptFlag interruptFlag

	// InterruptCause is the cause of the pending interruption.
	InterruptCause atomic.Pointer[error]

	// Raised is the interruption that is unwinding to the outermost call from Go.
	Raised *InterruptSignal
}

Poller is what a long operation needs to stop at an interruption.

func (*Poller) CopyDenseElements

func (p *Poller) CopyDenseElements(o *Object) ([]Value, bool)

CopyDenseElements returns a copy of the elements of the array o when none of them is missing.

func (*Poller) Poll

func (p *Poller) Poll()

Poll is agent.Poll without taking notifications. It leaves the flag set, so that the next Poll of the agent takes them.

func (*Poller) PollYield

func (p *Poller) PollYield()

PollYield does nothing, as the other goroutines run without waiting for a yield.

func (*Poller) Raise

func (p *Poller) Raise()

Raise panics with the pending interruption, if there is one.

func (*Poller) ResumeInterruption

func (p *Poller) ResumeInterruption()

ResumeInterruption panics again with an interruption that a host callback recovered before the interruption reached the outermost call from Go.

func (*Poller) TruncateElements

func (p *Poller) TruncateElements(o *Object, n uint32)

TruncateElements removes the elements of the array o from n on and sets its length to n.

type Prop

type Prop struct {
	Slot  int32
	Flags uint8
}

type PropCache

type PropCache struct {
	CacheEntry
	Second CacheEntry
	Reads  *namedReads
}

PropCache holds two inline entries for a property access site and records additional receiver shapes for named reads.

func (*PropCache) Entry

func (c *PropCache) Entry(s *Shape) *CacheEntry

Entry returns the inline entry for s, or nil on a miss.

func (*PropCache) Keep

func (c *PropCache) Keep(shape *Shape) bool

Keep saves the current entry before c is filled for shape. It reports whether this displaces an entry for a third distinct shape.

func (*PropCache) RememberAbsent

func (c *PropCache) RememberAbsent(sp *Space, s *Shape)

RememberAbsent records that a receiver with the shape s has no property of the name.

func (*PropCache) RememberRead

func (c *PropCache) RememberRead(sp *Space, start, holder *Object, p Prop)

RememberRead records the location of p for subsequent reads from start's shape.

type PropDesc

type PropDesc struct {
	// contains filtered or unexported fields
}

PropDesc is a property descriptor.

func AccessorDesc

func AccessorDesc(a *accessorPair, flags uint8) PropDesc

AccessorDesc returns the descriptor of an accessor property with the content a of its slot and the attributes flags, which include FlagAccessor.

func DataDesc

func DataDesc(v Value, flags uint8) PropDesc

func ValueDesc

func ValueDesc(v Value) PropDesc

ValueDesc returns a descriptor with the [Value] field v and no others.

func (*PropDesc) Complete

func (d *PropDesc) Complete()

Complete implements CompletePropertyDescriptor. It also marks an accessor descriptor with FlagAccessor, as the descriptors of existing properties are.

func (*PropDesc) Configurable

func (d *PropDesc) Configurable() bool

Configurable reports the [[Configurable]] field of d, which is false when absent.

func (*PropDesc) Enumerable

func (d *PropDesc) Enumerable() bool

Enumerable reports the [[Enumerable]] field of d, which is false when absent.

func (*PropDesc) FieldCount

func (d *PropDesc) FieldCount() int

FieldCount returns the number of fields of d that are present.

func (*PropDesc) Getter

func (d *PropDesc) Getter() *Object

Getter returns the [[Get]] field of the accessor descriptor d, or nil when it is undefined.

func (*PropDesc) HasFalse

func (d *PropDesc) HasFalse(has, flag uint8) bool

HasFalse reports whether the field has of d, for the attribute flag, is present and false.

func (*PropDesc) HasField

func (d *PropDesc) HasField(has uint8) bool

HasField reports whether the field has of d is present.

func (*PropDesc) HasTrue

func (d *PropDesc) HasTrue(has, flag uint8) bool

HasTrue reports whether the field has of d, for the attribute flag, is present and true.

func (*PropDesc) IsAccessor

func (d *PropDesc) IsAccessor() bool

IsAccessor implements IsAccessorDescriptor.

func (*PropDesc) IsData

func (d *PropDesc) IsData() bool

IsData implements IsDataDescriptor.

func (*PropDesc) KeepsData

func (d *PropDesc) KeepsData(cur *PropDesc) bool

KeepsData reports whether d redefines the existing data property described by cur as a data property.

func (*PropDesc) NewAccessorProperty

func (d *PropDesc) NewAccessorProperty() (Value, uint8)

NewAccessorProperty returns the content of the slot and the attributes of the new accessor property that d, which is an accessor descriptor, defines.

func (*PropDesc) NewData

func (d *PropDesc) NewData() (Value, uint8)

NewData returns the value and the attributes of the new data property that d, which is no accessor descriptor, defines.

func (*PropDesc) RedefinedData

func (d *PropDesc) RedefinedData(cur *PropDesc) (Value, uint8)

RedefinedData returns the value and the attributes that the existing data property described by cur has once d, for which KeepsData holds, redefined it.

func (*PropDesc) RedefinedProperty

func (d *PropDesc) RedefinedProperty(cur *PropDesc) (Value, uint8)

RedefinedProperty returns the content of the slot and the attributes that the existing property described by cur has once d, for which KeepsData does not hold, redefined it.

func (*PropDesc) SetConfigurable

func (d *PropDesc) SetConfigurable(b bool)

SetConfigurable sets the [[Configurable]] field of d to b.

func (*PropDesc) SetEnumerable

func (d *PropDesc) SetEnumerable(b bool)

SetEnumerable sets the [[Enumerable]] field of d to b.

func (*PropDesc) SetGetter

func (d *PropDesc) SetGetter(f *Object)

SetGetter sets the [[Get]] field of d to f, where nil stands for undefined.

func (*PropDesc) SetSetter

func (d *PropDesc) SetSetter(f *Object)

SetSetter sets the [[Set]] field of d to f, where nil stands for undefined.

func (*PropDesc) SetValue

func (d *PropDesc) SetValue(v Value)

SetValue sets the [Value] field of d to v.

func (*PropDesc) SetWritable

func (d *PropDesc) SetWritable(b bool)

SetWritable sets the [[Writable]] field of d to b.

func (*PropDesc) Setter

func (d *PropDesc) Setter() *Object

Setter returns the [[Set]] field of the accessor descriptor d, or nil when it is undefined.

func (*PropDesc) Value

func (d *PropDesc) Value() Value

Value returns the [Value] field of the data descriptor d.

func (*PropDesc) Writable

func (d *PropDesc) Writable() bool

Writable reports the [[Writable]] field of d, which is false when absent.

type PropKey

type PropKey struct {
	Key *Object
	Idx uint32
}

PropKey is a property key: an array index when Key is nil, otherwise an interned string or a symbol.

func AppendElemRun

func AppendElemRun(keys []PropKey, o *Object, start, end int) []PropKey

AppendElemRun appends the keys of the elements of o from start to end to keys.

func AppendEnumerableNames

func AppendEnumerableNames(keys []PropKey, s *Shape, names []*Object) []PropKey

AppendEnumerableNames appends the enumerable string keys among names, which are keys of the private shape s, to keys.

func AppendIndexRun

func AppendIndexRun(keys []PropKey, i, j int) []PropKey

AppendIndexRun appends the keys of the indices from i up to j to keys.

func EnumerableKey

func EnumerableKey(key *Object, flags uint8) PropKey

EnumerableKey returns key as a property key when it is a string and flags make it enumerable, and the zero PropKey otherwise.

func IndexKey

func IndexKey(i uint32) PropKey

IndexKey returns the property key for the array index i.

func NamedKey

func NamedKey(key *Object) PropKey

NamedKey returns the property key for key, which is an interned string or a symbol.

func (PropKey) IsIndex

func (k PropKey) IsIndex() bool

func (PropKey) IsSymbol

func (k PropKey) IsSymbol() bool

IsSymbol reports whether k is a symbol.

type PropertyObject

type PropertyObject struct {
	Object
	// contains filtered or unexported fields
}

PropertyObject keeps an object's header and its tail in one allocation, for the objects that have elements, function state or internal state.

func (*PropertyObject) Init

func (o *PropertyObject) Init() *Object

func (*PropertyObject) InitExotic

func (o *PropertyObject) InitExotic(s *Shape, c class, state any) *Object

InitExotic makes o, which must be zero, what NewExoticObject returns.

func (*PropertyObject) InitFunction

func (o *PropertyObject) InitFunction(s *Shape, fn *Function, state any) *Object

InitFunction makes o, which must be zero, what NewFunctionObject returns, with the internal state state.

func (*PropertyObject) InitMaterializedFunction

func (o *PropertyObject) InitMaterializedFunction(s *Shape, fn *Function, room []Value) *Object

InitMaterializedFunction makes o, which must be zero, a function object with the shape s and the function state fn, none of whose properties are implicit. room, which is in the allocation of o, is the storage of its properties.

func (*PropertyObject) InitWithState

func (o *PropertyObject) InitWithState(s *Shape, c class, state any) *Object

InitWithState makes o, which must be zero, what NewObjectWithState returns.

type ProxyState

type ProxyState struct {
	Target  *Object
	Handler *Object
}

ProxyState holds the internal slots of a proxy object. A detached global proxy has a nil target. A revoked proxy has both slots nil.

func (*ProxyState) AllowsGlobalAccess

func (s *ProxyState) AllowsGlobalAccess(group *Object) bool

func (*ProxyState) IsGlobal

func (s *ProxyState) IsGlobal() bool

type QueryKey

type QueryKey struct {
	// Key and Idx are as in [PropKey], except that Key is not interned when Idx is MissingKey.
	Key *Object
	Idx uint32
}

QueryKey is a property key for an operation that only reads properties. It may be a string that no property key has.

func (QueryKey) Missing

func (k QueryKey) Missing() bool

type Raw

type Raw struct {
	// contains filtered or unexported fields
}

Raw gives access to the property storage of an object without the checks of the property operations. Only the interpreter loop uses it.

func (Raw) Elem

func (r Raw) Elem(i int) Value

Elem returns the element i, which can be a hole.

func (Raw) ElemCount

func (r Raw) ElemCount() int

ElemCount returns the number of elements, which is 0 for a primitive value.

func (Raw) ElemRoom

func (r Raw) ElemRoom() int

ElemRoom returns how many elements the storage of the elements has room for.

func (Raw) Elems

func (r Raw) Elems() []Value

Elems returns the elements, which the caller must not change.

func (Raw) ElemsShared added in v0.2.0

func (r Raw) ElemsShared() bool

ElemsShared reports whether the elements are shared with other arrays, so that storing one needs the property operations.

func (Raw) ExtendElems

func (r Raw) ExtendElems(n int)

ExtendElems makes the first n values of the storage of the elements the elements. The storage must have room for them, and the caller must store each new element before reading it.

func (Raw) ExtendSlots

func (r Raw) ExtendSlots(n int)

ExtendSlots makes the first n values of the storage of the slots the slots. The storage must have room for them.

func (Raw) SetElem

func (r Raw) SetElem(i int, v Value)

SetElem makes v the element i.

func (Raw) SetFlags

func (r Raw) SetFlags(flags uint8)

SetFlags makes flags the flags.

func (Raw) SetLength

func (r Raw) SetLength(n uint32)

SetLength makes n the length of an array.

func (Raw) SetShape

func (r Raw) SetShape(s *Shape)

SetShape makes s the shape.

func (Raw) SetSlot

func (r Raw) SetSlot(i int, v Value)

SetSlot makes v the value of the slot i.

func (Raw) Slot

func (r Raw) Slot(i int) Value

Slot returns the value of the slot i.

func (Raw) SlotCount

func (r Raw) SlotCount() int

SlotCount returns the number of slots.

func (Raw) SlotRef

func (r Raw) SlotRef(i int) *Value

SlotRef returns a pointer to the slot i, which the caller must not store to.

func (Raw) SlotRoom

func (r Raw) SlotRoom() int

SlotRoom returns how many slots the storage of the slots has room for.

type RealmPart

type RealmPart struct {
	Intrinsics [intrinsicCount]*Object

	Shapes shapeTable

	ArrayIter arrayIterCache

	Global *Object

	// GlobalThis is the global this value, which a host can set to a global proxy.
	GlobalThis *Object

	// GlobalLex holds the top-level let, const and class declarations.
	GlobalLex *Object

	// ObjectTagStrings are results of Object.prototype.toString, by tag.
	ObjectTagStrings map[wtf8.String]Value

	// StrictCallee is the callee property of unmapped arguments objects, or the zero value
	// until it is needed.
	StrictCallee Value

	// RegExpFlagStrings holds the value of the flags getter for each set of the 8 flags, once
	// computed. It is nil until it is needed.
	RegExpFlagStrings *[1 << 8]Value

	// AsyncFromSyncProto is %AsyncFromSyncIteratorPrototype%, or nil until it is needed.
	AsyncFromSyncProto *Object

	LegacyRegExp legacyRegExpStatics

	// Space is the space of the agent of the realm.
	*Space

	// Owner is the execution context of the realm. Only executionContextOf and the
	// interpreter loop read it.
	Owner any
	// contains filtered or unexported fields
}

RealmPart is the storage state of a realm, which the realm embeds.

func (*RealmPart) AddIndex

func (r *RealmPart) AddIndex(o *Object, i uint32, val Value, flags uint8) bool

AddIndex creates the data property with the array index i on o, which has no such own property. It reports false when o does not allow it.

func (*RealmPart) AddMappedElement

func (r *RealmPart) AddMappedElement(o *Object, i uint32)

AddMappedElement adds the element i of the arguments object o, which it holds, as an index property that maps to a parameter.

func (*RealmPart) AppendElements

func (r *RealmPart) AppendElements(o *Object, vals []Value) (uint32, bool)

AppendElements is quiet.Context.AppendElements.

func (*RealmPart) AppendElementsOf

func (r *RealmPart) AppendElementsOf(dst *Object, n int64, src *Object) bool

AppendElementsOf is quiet.Context.AppendElementsOf.

func (*RealmPart) ArrayCreate

func (r *RealmPart) ArrayCreate(length uint32, proto *Object) *Object

ArrayCreate implements ArrayCreate.

func (*RealmPart) ArrayCtorPlain

func (r *RealmPart) ArrayCtorPlain(o *Object) bool

ArrayCtorPlain reports whether creating the result of a method for the array o makes a plain array, because o has the original constructor.

func (*RealmPart) ArrayIterationPlain

func (r *RealmPart) ArrayIterationPlain(o *Object) bool

ArrayIterationPlain reports whether o uses the original array values and next methods. Reading an element can still invoke a getter.

func (*RealmPart) ArrayProtoPlain

func (r *RealmPart) ArrayProtoPlain() bool

ArrayProtoPlain is Object.InheritsNoIndex for the objects whose prototype is %Array.prototype%, except that it also reports false when %Object.prototype% does not follow in the prototype chain.

%Array.prototype% is an array and %Object.prototype% an ordinary object from the start, neither of which can become exotic later.

func (*RealmPart) AssignDataProperties

func (r *RealmPart) AssignDataProperties(to, from *Object) bool

AssignDataProperties is quiet.Context.AssignDataProperties.

func (*RealmPart) CheckNoIteratorReturn

func (r *RealmPart) CheckNoIteratorReturn()

func (*RealmPart) CodePointsToString

func (r *RealmPart) CodePointsToString(points []rune) Value

CodePointsToString returns the string value of points, code points that may be surrogates.

func (*RealmPart) CopyElementRange

func (r *RealmPart) CopyElementRange(o *Object, start, end int64) (*Object, bool)

CopyElementRange is quiet.Context.CopyElementRange.

func (*RealmPart) CreateIterResultObject

func (r *RealmPart) CreateIterResultObject(v Value, done bool) Value

CreateIterResultObject creates an iterator result in the realm r.

func (*RealmPart) Define

func (r *RealmPart) Define(o *Object, key *Object, val Value, flags uint8)

Define creates or replaces the own named property key of o with the given attributes, without any of the checks of the JavaScript operations. An object of ExecutionContext.NewLazyObject must be initialized already.

func (*RealmPart) DefineAccessor

func (r *RealmPart) DefineAccessor(o *Object, key *Object, getter, setter *Object, flags uint8)

DefineAccessor creates or replaces the own accessor property key of o with the given attributes. getter and setter may be nil.

func (*RealmPart) DefineMatchResultProperties

func (r *RealmPart) DefineMatchResultProperties(a *Object, index, input, groups Value)

DefineMatchResultProperties creates the data properties index, input and groups of a match result on a, in that order, as CreateDataPropertyOrThrow does. a must be an array from RealmPart.NewArrayWithRoom that has no named properties.

func (*RealmPart) DefineMatchResultPropertiesWithIndices

func (r *RealmPart) DefineMatchResultPropertiesWithIndices(a *Object, index, input, groups, indices Value)

DefineMatchResultPropertiesWithIndices is like RealmPart.DefineMatchResultProperties and creates the data property indices after groups.

func (*RealmPart) FillElements

func (r *RealmPart) FillElements(o *Object, n, start, end int64, v Value) bool

FillElements is quiet.Context.FillElements.

func (*RealmPart) FunctionShapeFor

func (r *RealmPart) FunctionShapeFor(proto *Object) *Shape

FunctionShapeFor returns the root for functions whose initial named properties are still implicit.

func (*RealmPart) GetVWithoutCall

func (r *RealmPart) GetVWithoutCall(v Value, key *Object, c *PropCache) (val Value, ok bool)

GetVWithoutCall is quiet.Context.GetVWithoutCall. It fills c, which may be nil, when the lookup can be repeated from the cache.

func (*RealmPart) HasOwnPropertyPlain

func (r *RealmPart) HasOwnPropertyPlain(o *Object, k Value) (has, ok bool)

HasOwnPropertyPlain is HasOwnProperty of o and the key k when finding out neither throws nor runs code, and takes a short time. It reports false as ok otherwise.

func (*RealmPart) IndexName

func (r *RealmPart) IndexName(i uint32) *Object

IndexName returns the key under which the array index i is stored in a shape.

func (*RealmPart) InheritsHasInstance

func (r *RealmPart) InheritsHasInstance(c *Object) bool

InheritsHasInstance reports whether the @@hasInstance property of c is the one that it inherits from %Function.prototype% of r. A false result does not mean the opposite.

func (*RealmPart) InitShortStrings

func (r *RealmPart) InitShortStrings()

InitShortStrings creates the sentinels of short strings with the shape of strings.

func (*RealmPart) Intern

func (r *RealmPart) Intern(s wtf8.String) *Object

Intern returns the string s as a property key.

func (*RealmPart) Intrinsic

func (r *RealmPart) Intrinsic(id Intrinsic) *Object

Intrinsic returns the intrinsic object id of r, or nil before it is set.

func (*RealmPart) JoinStrings

func (r *RealmPart) JoinStrings(o *Object, length int64, sep wtf8.String) (Value, bool)

JoinStrings is quiet.Context.JoinStrings.

func (*RealmPart) KeyOfString

func (r *RealmPart) KeyOfString(s wtf8.String) PropKey

KeyOfString returns the property key for the string s. It does not keep s.

func (*RealmPart) Lookup

func (r *RealmPart) Lookup(o *Object, key *Object) NamedLookup

Lookup finds the named property key on o and its prototype chain.

func (*RealmPart) LookupDataSlot

func (r *RealmPart) LookupDataSlot(o, key *Object) dataSlot

LookupDataSlot returns the named data slot on o or its prototypes, or a zero slot if the lookup cannot establish one without running code.

func (*RealmPart) Materialize

func (r *RealmPart) Materialize(o *Object)

Materialize creates the properties that a function has from the start but that are only stored once something looks at them.

func (*RealmPart) NewArgumentsObject

func (r *RealmPart) NewArgumentsObject(args, extra []Value) *Object

NewArgumentsObject returns an arguments object of args followed by extra, without its callee.

func (*RealmPart) NewArray

func (r *RealmPart) NewArray(elems []Value) *Object

NewArray returns a new array with the given elements, which it keeps.

func (*RealmPart) NewArrayBufferFromBytes

func (r *RealmPart) NewArrayBufferFromBytes(proto *Object, b []byte, maxByteLength int) *Object

NewArrayBufferFromBytes returns an ArrayBuffer with the prototype proto whose data is b, which it keeps. maxByteLength is -1 for a buffer whose length is fixed and must not be smaller than len(b) otherwise.

func (*RealmPart) NewArrayCopy

func (r *RealmPart) NewArrayCopy(elems []Value) *Object

NewArrayCopy returns a new array with a copy of elems as its elements.

func (*RealmPart) NewArrayOfConstants added in v0.2.0

func (r *RealmPart) NewArrayOfConstants(run []Value) *Object

NewArrayOfConstants returns a new array of the constants in run, the linked constants of an array literal, which no other code uses. The first call stores an array of them in run[0] and clears the rest of run. The returned arrays share its elements until their own change.

func (*RealmPart) NewArrayPair

func (r *RealmPart) NewArrayPair(a, b Value) *Object

NewArrayPair returns a new array with the elements a and b.

func (*RealmPart) NewArrayWithRoom

func (r *RealmPart) NewArrayWithRoom(length, n int) *Object

NewArrayWithRoom returns an array of length undefined elements with room for n named properties.

func (*RealmPart) NewBufferedString

func (r *RealmPart) NewBufferedString(s wtf8.String, flags uint8, builder any, meta *ObjectMeta) Value

NewBufferedString returns a string with its builder, a *strings.Builder or, for a string marked ObjReversed, a *ReversedBuilder, and optional UTF-16 metadata.

func (*RealmPart) NewConcatenatedString

func (r *RealmPart) NewConcatenatedString(s wtf8.String, count ConcatCount) Value

NewConcatenatedString returns the string s, which is longer than a short string, with the concatenation count count.

func (*RealmPart) NewDataViewObject

func (r *RealmPart) NewDataViewObject(proto *Object, buffer *Object, byteOffset, byteLength int) *Object

NewDataViewObject returns a DataView with the prototype proto on the buffer object buffer from byteOffset on. byteLength is -1 for a view whose length tracks the length of the buffer.

func (*RealmPart) NewElementsPlain

func (r *RealmPart) NewElementsPlain(o *Object) bool

NewElementsPlain reports whether storing a new element in the array o defines it as an own data property without consulting a prototype, when o accepts it.

func (*RealmPart) NewEmptyArrayWithRoom

func (r *RealmPart) NewEmptyArrayWithRoom(n int) *Object

NewEmptyArrayWithRoom returns a new empty array with room for n elements.

func (*RealmPart) NewEmptyObjectWithRoom

func (r *RealmPart) NewEmptyObjectWithRoom(n int) *Object

NewEmptyObjectWithRoom returns a new empty ordinary object whose prototype is %Object.prototype%, with room for n properties.

func (*RealmPart) NewHostArrayBufferObject

func (r *RealmPart) NewHostArrayBufferObject(proto *Object, b []byte) *Object

NewHostArrayBufferObject returns an ArrayBuffer of fixed length with the prototype proto whose data block is b, which it keeps. Its [[ArrayBufferDetachKey]] is set, so that only the host detaches it. len(b) must not exceed the largest length of a buffer.

func (*RealmPart) NewImmutableArrayBufferFromBytes

func (r *RealmPart) NewImmutableArrayBufferFromBytes(proto *Object, b []byte) *Object

NewImmutableArrayBufferFromBytes returns an immutable ArrayBuffer with the prototype proto whose data is b, which it keeps. b must not be modified afterwards.

func (*RealmPart) NewObject

func (r *RealmPart) NewObject(proto *Object) *Object

NewObject returns a new empty object with the prototype proto, which may be nil.

func (*RealmPart) NewObjectFromProperties

func (r *RealmPart) NewObjectFromProperties(keys []PropKey, vals []Value) *Object

NewObjectFromProperties returns a new ordinary object whose prototype is Object.prototype, with the data properties keys[i]: vals[i] created in order as CreateDataProperty creates them. A repeated key keeps its first position and takes the last value. It does not keep the slices.

func (*RealmPart) NewSharedArrayBufferObject

func (r *RealmPart) NewSharedArrayBufferObject(proto *Object, blk *SharedDataBlock) *Object

NewSharedArrayBufferObject returns a SharedArrayBuffer with the prototype proto over the data block blk, which may come from another agent.

func (*RealmPart) NewString

func (r *RealmPart) NewString(s wtf8.String) Value

NewString returns the string s as a value.

func (*RealmPart) NewTemplateArray

func (r *RealmPart) NewTemplateArray(vals []Value) *Object

NewTemplateArray returns a new frozen array with the elements vals, which still can be given named properties by Space.Add.

func (*RealmPart) NewTypedArrayObject

func (r *RealmPart) NewTypedArrayObject(proto *Object, t element.Type, buffer *Object, byteOffset, length int) *Object

NewTypedArrayObject returns a typed array with the prototype proto whose elements of the type t are stored in the buffer object buffer from byteOffset on. length is the number of elements, or -1 for a typed array whose length tracks the length of the buffer.

func (*RealmPart) NumberToString

func (r *RealmPart) NumberToString(n float64) Value

NumberToString is quiet.Context.NumberToString.

func (*RealmPart) OwnFunctionPrototypeSlot

func (r *RealmPart) OwnFunctionPrototypeSlot(ctor *Object, site *PropCache) *Value

OwnFunctionPrototypeSlot returns the own prototype slot of an ordinary function, or nil.

func (*RealmPart) PollAtIndex

func (r *RealmPart) PollAtIndex(i int64)

PollAtIndex is agent.PollAt with Poller.Poll.

func (*RealmPart) PrependElements

func (r *RealmPart) PrependElements(o *Object, vals []Value) (uint32, bool)

PrependElements is quiet.Context.PrependElements.

func (*RealmPart) RecordRegExpOriginals

func (r *RealmPart) RecordRegExpOriginals(protoKeys, ctorKeys []*Object)

RecordRegExpOriginals records the current own properties protoKeys of %RegExp.prototype% and ctorKeys of %RegExp%, which quiet.Context.UnmodifiedRegExpMatcher requires to stay unchanged. Every key must name an existing property whose value, if it is a data property, is an object.

func (*RealmPart) RegExpLastIndex

func (r *RealmPart) RegExpLastIndex(o *Object) (Value, bool)

RegExpLastIndex is quiet.Context.RegExpLastIndex.

func (*RealmPart) RegExpShape

func (r *RealmPart) RegExpShape() *Shape

RegExpShape returns the shape of a new RegExp object whose prototype is %RegExp.prototype%.

func (*RealmPart) ReplaceOwn

func (r *RealmPart) ReplaceOwn(o *Object, k PropKey, val Value, flags uint8)

ReplaceOwn stores the value and attributes of the existing own property k of o.

func (*RealmPart) ReverseElements

func (r *RealmPart) ReverseElements(o *Object) bool

ReverseElements is quiet.Context.ReverseElements.

func (*RealmPart) SearchElements

func (r *RealmPart) SearchElements(o *Object, i, end int64, target Value, sameValueZero bool) (found, next int64)

SearchElements is quiet.Context.SearchElements.

func (*RealmPart) SetIntrinsic

func (r *RealmPart) SetIntrinsic(id Intrinsic, o *Object)

SetIntrinsic makes o the intrinsic object id.

func (*RealmPart) SetRegExpLastIndex

func (r *RealmPart) SetRegExpLastIndex(o *Object, v Value) bool

SetRegExpLastIndex is quiet.Context.SetRegExpLastIndex.

func (*RealmPart) ShapeFor

func (r *RealmPart) ShapeFor(proto *Object) *Shape

ShapeFor returns the ordinary root shape in r for prototype proto, which may be nil.

func (*RealmPart) SharedString

func (r *RealmPart) SharedString(s wtf8.String) Value

SharedString returns the string s as a value that may be the same object as a property key with the same contents.

func (*RealmPart) ShortString

func (r *RealmPart) ShortString(s wtf8.String) Value

func (*RealmPart) SkipHoles

func (r *RealmPart) SkipHoles(o *Object, i, end int64) int64

SkipHoles is quiet.Context.SkipHoles.

func (*RealmPart) SkipHolesBackward

func (r *RealmPart) SkipHolesBackward(o *Object, i, end int64) int64

SkipHolesBackward is quiet.Context.SkipHolesBackward.

func (*RealmPart) SpliceElements

func (r *RealmPart) SpliceElements(o *Object, length, start, del int64, items []Value) (*Object, bool)

SpliceElements is quiet.Context.SpliceElements.

func (*RealmPart) StringFromCodeUnits

func (r *RealmPart) StringFromCodeUnits(units []uint16) Value

StringFromCodeUnits returns the string value whose code units are units.

func (*RealmPart) Substring

func (r *RealmPart) Substring(s Value, start, end int) Value

Substring returns the code units of s from start up to end, which must be in range and in order.

func (*RealmPart) UnitString

func (r *RealmPart) UnitString(u uint16) Value

UnitString returns the string that consists of the code unit u.

func (*RealmPart) UnmodifiedRegExpMatcher

func (r *RealmPart) UnmodifiedRegExpMatcher(o *Object) *regexp.Regexp

UnmodifiedRegExpMatcher is quiet.Context.UnmodifiedRegExpMatcher.

type RegExpSite

type RegExpSite struct {
	Literal bytecode.RegExp

	// State is the internal state that the RegExp objects of the literal share, once the
	// pattern is compiled.
	State *RegExpState

	// Lent is the RegExp object that ExecutionContext.LendRegExpLiterals lends for the literal, once made.
	Lent *Object
}

RegExpSite is a regular expression literal of a function.

type RegExpState

type RegExpState struct {
	Matcher *regexp.Regexp
	Source  wtf8.String
	Flags   wtf8.String
	Legacy  bool
	// Lent marks the state of a RegExp object that ExecutionContext.LendRegExpLiterals lends.
	Lent bool

	// Realm is the [[Realm]] of the object.
	Realm *RealmPart
}

RegExpState holds the internal slots of a RegExp object. It does not change once it is set, so objects can share it.

type ReversedBuilder

type ReversedBuilder struct {
	Sb strings.Builder
}

ReversedBuilder holds the reversed contents of the reversed strings made from it.

func HeadBuilder

func HeadBuilder(o *Object) *ReversedBuilder

HeadBuilder returns the builder whose head the string o is, or nil.

type Shape

type Shape struct {
	// Space and Realm identify where the objects with this shape were created.
	Space *Space
	Realm *RealmPart

	Proto  *Object
	Parent *Shape

	// Key is the property this shape adds to Parent, stored in slot Count-1.
	// It is an interned string or a symbol.
	Key    *Object
	Flags  uint8
	Family shapeFamily

	Count int32

	// Table maps every property of the shape to its slot. A private shape always has one.
	// A shared shape with more than smallShapeSize properties builds it on first lookup,
	// or takes it over from its parent.
	Table map[*Object]Prop

	// Transitions maps a property to the shared shape that adds it to this one.
	Transitions transitionTable

	// Small lists the properties of a shared shape with at most smallShapeSize properties,
	// by slot. It is nil for any other shape.
	Small []ShapeEntry

	Private bool

	// ReadID identifies this shape in its agent's megamorphic read caches. Zero is unassigned.
	ReadID uint32

	// Order lists the keys of a private shape in insertion order, at the indices of their
	// slots. A deleted key leaves nil behind until the shape is compacted, so Count is the number
	// of keys and len(Order) the number of slots.
	Order []*Object
	// contains filtered or unexported fields
}

Shape describes the layout of an object: which property lives in which slot, and the prototype.

The root fixes the creation realm, prototype, and behavior of named properties. Objects built from that root by adding the same properties in the same order share a shape, until one gets a private shape, which is changed in place.

A shared shape never changes, so an inline cache that remembers one stays valid for as long as the prototypes it looked through keep their properties.

func (*Shape) HasEnumerableString

func (s *Shape) HasEnumerableString() bool

HasEnumerableString reports whether s has an enumerable property whose key is a string, checking for an interruption while it looks at many.

func (*Shape) Keys

func (s *Shape) Keys() []*Object

Keys returns the property keys in insertion order. The result must not be modified.

func (*Shape) Lookup

func (s *Shape) Lookup(key *Object) (Prop, bool)

func (*Shape) StringKeys

func (s *Shape) StringKeys() []PropKey

StringKeys returns the property keys of s that are strings, in insertion order.

func (*Shape) With

func (s *Shape) With(key *Object, flags uint8) *Shape

With returns the shared shape that has key in addition to the properties of s.

func (*Shape) Without

func (s *Shape) Without(key *Object) *Shape

Without returns the shared shape with the properties of the shared shape s other than key, in the same order and with the same attributes. It returns nil when the chain of s does not add key or adds more than maxReadded properties after it.

type ShapeEntry

type ShapeEntry struct {
	Key *Object
	Prop
}

ShapeEntry is a property of a shape and where it is.

type ShapeKey

type ShapeKey struct {
	Key   *Object
	Flags uint8
}

type SharedDataBlock

type SharedDataBlock struct {

	// WaiterLists are the waiter lists of the block, or nil until there is a waiter. They belong
	// to the engine. Only its waiterListsOf and compareAndAdd use the field, between Lock and
	// Unlock.
	WaiterLists any
	// contains filtered or unexported fields
}

SharedDataBlock is a Shared Data Block: the bytes of a SharedArrayBuffer, which the agents of an agent cluster share. Its methods may be called from any goroutine.

func NewSharedDataBlock

func NewSharedDataBlock(byteLength, maxByteLength int64) *SharedDataBlock

NewSharedDataBlock returns a block of byteLength zero bytes. maxByteLength is -1 for a block whose length is fixed.

func (*SharedDataBlock) Lock

func (blk *SharedDataBlock) Lock() []byte

Lock returns the bytes of blk and keeps the other agents from accessing them and the waiter lists until SharedDataBlock.Unlock is called.

func (*SharedDataBlock) Unlock

func (blk *SharedDataBlock) Unlock()

Unlock ends the access of SharedDataBlock.Lock.

type Space

type Space struct {
	// Poller comes first, as the interpreter loop reads its flag often.
	Poller

	Keys keys

	Strings stringTable

	// MissHolder holds undefined in its one slot, where the cache entries of properties that
	// were not found point.
	MissHolder *Object

	// ProtoEpoch changes whenever the properties or the prototype of a prototype object change,
	// or its slots move.
	ProtoEpoch uint32

	// IndexStrings holds the strings of the smallest array indices that were made, by index,
	// and nil for the others.
	IndexStrings []*Object

	// SymbolShape is the shape of the symbols of the agent. It records the space that they belong
	// to, and no lookup starts from it.
	SymbolShape *Shape

	// Typeofs are the interned results of the typeof operator, indexed by the typeof constants.
	Typeofs [TypeofCount]Value

	Builtins builtinLayout

	// MaxBigIntResultBits is the bit limit for checked BigInt arithmetic results.
	// Tests lower it to exercise overflow with small operands.
	MaxBigIntResultBits int64

	// SymbolRegistry is the GlobalSymbolRegistry List, by key.
	SymbolRegistry map[wtf8.String]*Object

	// HasHostClock is set if a host function gives the current time.
	HasHostClock bool

	// RegExpMatcher matches regular expressions. Nothing that a match runs starts another one.
	RegExpMatcher regexp.Matcher

	// HostDefinedValue is the value that [Space.HostDefined] returns.
	HostDefinedValue any
	// contains filtered or unexported fields
}

Space is the state of an agent that its objects and values need: the property keys and the strings, the symbols, the shapes that belong to no realm, the epoch and the IDs that the inline caches rely on, and the objects that WeakRefs keep alive. The objects of an agent lead to its space through their shapes. It also holds what operations on them need besides: the state of polling, whether there is a host clock, and the RegExp matcher.

It must not refer to the agent, a realm, a frame or an execution context, except that a shape records its realm. HostDefinedValue belongs to the host and is opaque to the engine.

func (*Space) Add

func (sp *Space) Add(o *Object, key *Object, val Value, flags uint8)

Add gives o the new own property key. The caller has checked that o has no such property.

func (*Space) AddToKeptObjects

func (sp *Space) AddToKeptObjects(o *Object)

AddToKeptObjects implements AddToKeptObjects: o stays alive until the current job ends.

func (*Space) ArrayIterationUnmodified

func (sp *Space) ArrayIterationUnmodified(r *RealmPart) bool

ArrayIterationUnmodified reports whether %Array.prototype%[@@iterator] and %ArrayIteratorPrototype%.next are the original functions.

func (*Space) CanBeHeldWeakly

func (sp *Space) CanBeHeldWeakly(v Value) bool

CanBeHeldWeakly implements CanBeHeldWeakly.

func (*Space) ClearKeptObjects

func (sp *Space) ClearKeptObjects()

ClearKeptObjects implements ClearKeptObjects. It must be called when a job ends: after each promise job, and when the outermost call into the engine returns.

func (*Space) EndLazy

func (sp *Space) EndLazy(o *Object)

EndLazy makes the lazy object o an ordinary object without properties.

func (*Space) ErrorOf

func (sp *Space) ErrorOf(v Value) *Error

ErrorOf returns the Go error for the thrown value v.

func (*Space) FinishBuiltins

func (sp *Space) FinishBuiltins()

FinishBuiltins ends the creation of the built-in objects.

func (*Space) HostDefined

func (sp *Space) HostDefined() any

HostDefined returns the host-defined value of the agent.

func (*Space) IndexKey

func (sp *Space) IndexKey(i uint32) *Object

IndexKey returns the interned key for the index i, or nil when the key is not interned, in which case no object has a property with that key.

func (*Space) InitMissHolder

func (sp *Space) InitMissHolder(s *Shape)

InitMissHolder creates the object that MissHolder describes, with the shape s.

func (*Space) IsLazyKey

func (sp *Space) IsLazyKey(key *Object) bool

IsLazyKey reports whether key names a property that RealmPart.Materialize creates.

func (*Space) Key

func (sp *Space) Key(k CommonKey) *Object

Key returns the string property key k.

func (*Space) KeyForSymbol

func (sp *Space) KeyForSymbol(sym *Object) (wtf8.String, bool)

KeyForSymbol implements KeyForSymbol: it returns the key of the symbol sym in the GlobalSymbolRegistry List, and reports whether sym is in it.

func (*Space) NewShape

func (sp *Space) NewShape(proto *Object, r *RealmPart, family shapeFamily) *Shape

NewShape returns a new empty shared shape for objects whose prototype is proto.

func (*Space) NewSymbol

func (sp *Space) NewSymbol(desc wtf8.String, hasDesc bool) *Object

NewSymbol returns a new symbol. desc is its description when hasDesc is set.

func (*Space) NoArrayIteratorReturn

func (sp *Space) NoArrayIteratorReturn(proto *Object) bool

NoArrayIteratorReturn reports whether array iterators have no return method, which closing one calls. The prototypes that it looks at count as prototypes from then on, so that adding a property to one moves ProtoEpoch.

func (*Space) Owns

func (sp *Space) Owns(o *Object) bool

Owns reports whether o belongs to the agent of sp or is shared by all agents.

func (*Space) PairDestructuringPlain

func (sp *Space) PairDestructuringPlain(r *RealmPart) bool

PairDestructuringPlain reports whether destructuring a new array of two elements into two bindings runs nothing that JavaScript could observe.

func (*Space) QueryStringKey

func (sp *Space) QueryStringKey(o *Object) QueryKey

QueryStringKey returns the query key for the string o.

func (*Space) ReadNamedSlot

func (sp *Space) ReadNamedSlot(start, holder *Object, p Prop, c *PropCache) (val Value, getter *Object)

ReadNamedSlot reads p and returns its getter separately for the caller to invoke.

func (*Space) RegisteredSymbol

func (sp *Space) RegisteredSymbol(key wtf8.String) *Object

RegisteredSymbol returns the symbol of the GlobalSymbolRegistry List with the key key, which it adds when there is none.

func (*Space) Remove

func (sp *Space) Remove(o, key *Object)

Remove deletes the own named property key of o, which must exist.

func (*Space) RootShape

func (sp *Space) RootShape(proto *Object, r *RealmPart, family shapeFamily) *Shape

RootShape selects the tree of layouts shared by receivers of this family, prototype and realm.

func (*Space) SetProto

func (sp *Space) SetProto(o *Object, proto *Object)

SetProto changes the prototype of o. It stays out of line to keep ArrayCreate small.

func (*Space) ShapeForRealm

func (sp *Space) ShapeForRealm(proto *Object, r *RealmPart) *Shape

ShapeForRealm returns the ordinary root shape in r for prototype proto, which may be nil.

func (*Space) ShortQueryKey

func (sp *Space) ShortQueryKey(v Value) QueryKey

ShortQueryKey returns the query key for the short string v, which is not interned.

func (*Space) StartBuiltins

func (sp *Space) StartBuiltins()

StartBuiltins starts the creation of the built-in objects, which Space.FinishBuiltins ends. In between, objects should only get their initial properties.

func (*Space) TouchProto

func (sp *Space) TouchProto(o *Object)

TouchProto records that the named properties of o changed, if o is a prototype: one was added, removed or defined, or its attributes changed. Whatever moves the slots of a prototype calls it too, because CacheProto entries point into them.

A change of elements, of the length of an array or of the value of a data property does not need it. The caches of property lookups and the records of original built-in properties hold named properties in slots only. The operations in array.go that depend on the elements of prototypes read them each time.

func (*Space) TypeofValue

func (sp *Space) TypeofValue(v Value) Value

func (*Space) WeakRefDeref

func (sp *Space) WeakRefDeref(v Value) (Value, bool)

WeakRefDeref implements WeakRefDeref for the WeakRef object v. It reports false when v is not a WeakRef object.

func (*Space) WellKnownSymbol

func (sp *Space) WellKnownSymbol(s WellKnownSymbol) *Object

WellKnownSymbol returns the well-known symbol s.

type StackCall

type StackCall struct {
	// Fp is the function that runs, or nil for a native function.
	Fp *FuncProto

	// Name is the name of the function.
	Name wtf8.String

	// Recv is the type name of the receiver of a method call, or empty.
	Recv wtf8.String

	// Pc is past the instruction of Fp that is running.
	Pc int

	IsNew bool
}

StackCall is a line of a stack trace.

type TemplateSite

type TemplateSite struct {
	Cooked []Value
	Raw    []Value
	Object *Object
}

type TypedArray

type TypedArray struct {
	Data *ArrayBuffer

	Offset int

	// FixedLength is [[ArrayLength]] in elements, unless Tracking is set: then the length follows
	// the buffer.
	FixedLength int
	Tracking    bool

	Type element.Type

	// NumberStore reports whether the elements are numbers and the buffer is mutable and not
	// shared, so that a number is stored without a conversion.
	NumberStore bool
	// contains filtered or unexported fields
}

TypedArray is the state of a typed array object.

func TypedArrayData

func TypedArrayData(v Value) *TypedArray

TypedArrayData returns the state of the typed array v, or nil when v is not a typed array.

func (*TypedArray) ArrayBuffer

func (t *TypedArray) ArrayBuffer() *ArrayBuffer

ArrayBuffer returns the data block of [[ViewedArrayBuffer]] of t.

func (*TypedArray) AtomicLoad

func (t *TypedArray) AtomicLoad(i int) uint64

AtomicLoad returns the encoding of the element i of t, which must be a valid integer index, as a sequentially consistent read.

func (*TypedArray) AtomicReadModifyWrite

func (t *TypedArray) AtomicReadModifyWrite(i int, op AtomicOp, v, replacement uint64) uint64

AtomicReadModifyWrite implements the steps of AtomicReadModifyWrite and Atomics.compareExchange that follow RevalidateAtomicAccess: it applies op with the encoding v to the element i of t, which must be a valid integer index, and returns the encoding that the element had. replacement is the encoding that AtomicCompareExchange stores.

func (*TypedArray) AtomicStore

func (t *TypedArray) AtomicStore(i int, x uint64)

AtomicStore stores the encoding x as the element i of t, which must be a valid integer index, as a sequentially consistent write.

func (*TypedArray) Buffer

func (t *TypedArray) Buffer() *Object

Buffer returns [[ViewedArrayBuffer]] of t.

func (*TypedArray) ByteOffset

func (t *TypedArray) ByteOffset() int

ByteOffset returns [[ByteOffset]] of t.

func (*TypedArray) ElementBytes

func (t *TypedArray) ElementBytes(i uint32) ([]byte, bool)

ElementBytes returns the bytes of the element i of t. It reports false when i is not a valid integer index or the buffer is shared.

func (*TypedArray) ElementType

func (t *TypedArray) ElementType() element.Type

ElementType returns [[TypedArrayName]] of t as an element type.

func (*TypedArray) IsLengthTracking

func (t *TypedArray) IsLengthTracking() bool

IsLengthTracking reports whether [[ArrayLength]] of t is auto.

func (*TypedArray) IsTypedArrayFixedLength

func (t *TypedArray) IsTypedArrayFixedLength() bool

IsTypedArrayFixedLength implements IsTypedArrayFixedLength.

func (*TypedArray) Length

func (t *TypedArray) Length() (int, bool)

Length implements TypedArrayLength. It reports false when the typed array is out of bounds, which includes a detached buffer.

func (*TypedArray) LoadElement

func (t *TypedArray) LoadElement(i int) (uint64, bool)

LoadElement returns the encoding of the element i of t, or reports false when i is not a valid integer index.

func (*TypedArray) Lock

func (t *TypedArray) Lock() []byte

Lock returns the bytes of the elements of t, or nil when t is out of bounds, as ArrayBuffer.Lock does for the buffer. It must be paired with TypedArray.Unlock. The slice must not be modified when the buffer is immutable.

func (*TypedArray) StoreElement

func (t *TypedArray) StoreElement(i int, x uint64)

StoreElement stores the encoding x as the element i of t, which is mutable, when i is a valid integer index.

func (*TypedArray) Unlock

func (t *TypedArray) Unlock()

Unlock ends the access of TypedArray.Lock.

type Upvalue

type Upvalue struct {
	P *Value

	// Index is the stack index or, for a generator, the register that P points to while the upvalue is open.
	Index int
	Val   Value
}

Upvalue is a variable of an enclosing function. P points to the variable: into the registers of that function while it is running, and to Val afterwards.

type Value

type Value struct {
	N float64

	// O is nil for undefined, NumberObject for the number N, BigInt64Object for the BigInt
	// whose two's complement bits N holds, and the object for anything else.
	// Every string of at most shortstrings.MaxBytes bytes holds its bytes in N.
	// Its object carries the byte length and realm, and may also be an interned key.
	O *Object
	// contains filtered or unexported fields
}

Value is a JavaScript value. The zero value is undefined. Values cannot be compared with ==; use IsStrictlyEqual, SameValue, or SameValueZero.

var Undefined Value

Undefined is the value undefined.

func ArithBigInt64

func ArithBigInt64(op bytecode.Opcode, x, y int64) (Value, bool)

ArithBigInt64 is ExecutionContext.arith for two BigInts that fit in an int64. It reports false when the result does not fit in an int64 or the operation throws.

func BigIntFromInt64

func BigIntFromInt64(i int64) Value

BigIntFromInt64 returns the BigInt i.

func Bool

func Bool(b bool) Value

Bool returns the boolean b as a value.

func DiagnosticDataProperty

func DiagnosticDataProperty(o, key *Object) (Value, bool)

DiagnosticDataProperty reads stored properties for stack traces and exception descriptions. It skips the property operations of exotic objects.

func Element

func Element(o *Object, i int64) (Value, bool)

Element returns the own property of o with the integer index i when reading it cannot run any JavaScript. It reports false when that is not known.

func ElementFromBits

func ElementFromBits(t element.Type, x uint64) Value

ElementFromBits returns the value that the encoding x of an element of the type t stands for.

func ElementFromBytes

func ElementFromBytes(t element.Type, b []byte) Value

ElementFromBytes returns the element of the type t at the start of b.

func GetValueFromBuffer

func GetValueFromBuffer(b []byte, t element.Type, littleEndian bool) Value

GetValueFromBuffer implements GetValueFromBuffer for the bytes b, which hold at least one element of the type t.

func NewAccessor

func NewAccessor(getter, setter *Object) Value

NewAccessor returns the content of the slot of an accessor property with the given getter and setter.

func NewBigInt

func NewBigInt(i *big.Int) Value

NewBigInt returns the BigInt i, which must not be modified afterward.

func Number

func Number(n float64) Value

Number returns the number n as a value.

func ObjectValue

func ObjectValue(o *Object) Value

ObjectValue returns o as a value.

func ThisBigIntValue

func ThisBigIntValue(v Value) (Value, bool)

ThisBigIntValue implements ThisBigIntValue. It reports false when the specification throws.

func ThisStringValue

func ThisStringValue(v Value) (Value, bool)

ThisStringValue implements ThisStringValue. It reports false when the specification throws.

func TypedArrayGet

func TypedArrayGet(o *Object, i uint32) Value

TypedArrayGet implements TypedArrayGetElement. It returns undefined when i is not a valid integer index.

func (Value) Accessor

func (v Value) Accessor() *accessorPair

func (Value) AppendStringBytes

func (v Value) AppendStringBytes(dst []byte) []byte

AppendStringBytes appends the string value's canonical WTF-8 bytes to dst.

func (Value) BigInt

func (v Value) BigInt() *big.Int

BigInt returns the BigInt v, which must not be modified.

func (Value) BigInt64

func (v Value) BigInt64() (int64, bool)

BigInt64 returns the BigInt v as an int64, and reports whether v is a BigInt that fits in one.

func (Value) CodePointAt

func (v Value) CodePointAt(i int) rune

CodePointAt returns the code point starting at UTF-16 index i. i must be in range.

func (Value) IsASCII

func (s Value) IsASCII() bool

IsASCII reports whether s contains only ASCII code units. s must be a string.

func (Value) IsBigInt

func (v Value) IsBigInt() bool

IsBigInt reports whether v is a BigInt.

func (Value) IsBool

func (v Value) IsBool() bool

IsBool reports whether v is a boolean.

func (Value) IsCallable

func (v Value) IsCallable() bool

IsCallable implements IsCallable.

func (Value) IsHTMLDDA

func (v Value) IsHTMLDDA() bool

func (Value) IsHole

func (v Value) IsHole() bool

func (Value) IsNull

func (v Value) IsNull() bool

IsNull reports whether v is null.

func (Value) IsNullish

func (v Value) IsNullish() bool

IsNullish reports whether v is undefined or null.

func (Value) IsNumber

func (v Value) IsNumber() bool

IsNumber reports whether v is a number.

func (Value) IsObject

func (v Value) IsObject() bool

IsObject reports whether v is an object, which includes functions and arrays.

func (Value) IsShortString

func (v Value) IsShortString() bool

func (Value) IsString

func (v Value) IsString() bool

IsString reports whether v is a string.

func (Value) IsSymbol

func (v Value) IsSymbol() bool

IsSymbol reports whether v is a symbol.

func (Value) IsUndefined

func (v Value) IsUndefined() bool

IsUndefined reports whether v is undefined.

func (Value) IsWellFormed

func (v Value) IsWellFormed() bool

IsWellFormed reports whether the string value contains no lone surrogates.

func (Value) Number

func (v Value) Number() float64

Number returns the number v. v must be a number.

func (Value) Object

func (v Value) Object() *Object

Object returns the object, string, symbol or BigInt that v is. It returns nil for a number or undefined, and one shared object for null, for each boolean, and for every BigInt that fits in an int64. For primitive strings, the returned object's identity is not guaranteed.

func (Value) RawString

func (v Value) RawString() wtf8.String

func (Value) ShortText

func (v Value) ShortText() wtf8.String

func (Value) Str

func (v Value) Str() wtf8.String

Str returns the content of the string value.

func (Value) StringByteLength

func (v Value) StringByteLength() int

StringByteLength returns the byte length of the string's canonical WTF-8 encoding.

func (Value) StringLength

func (v Value) StringLength() int

StringLength returns the number of UTF-16 code units in the string value.

func (Value) StringObject

func (v Value) StringObject() *Object

func (Value) Substring

func (v Value) Substring(start, end int) wtf8.String

Substring returns the string's code units from start up to end, which must be in range and in order.

func (Value) SubstringEquals

func (v Value) SubstringEquals(start, end int, other Value) bool

SubstringEquals reports whether the substring from start up to end equals other. Both values must be strings, and the UTF-16 indices must be in range and in order.

func (Value) UnitAt

func (v Value) UnitAt(i int) uint16

UnitAt returns the code unit at i in the string value. i must be in range.

func (Value) UnitIndexOf

func (v Value) UnitIndexOf(sub Value, from int, poll func()) int

UnitIndexOf returns the first UTF-16 index of sub at or after from, or -1. Both values must be strings, and from must be nonnegative. poll, which may be nil, is called now and then during a long search.

func (Value) UnitLastIndexOf

func (v Value) UnitLastIndexOf(sub Value, from int, poll func()) int

UnitLastIndexOf returns the last UTF-16 index of sub at or before from, or -1. Both values must be strings, and from must be nonnegative. poll is as for Value.UnitIndexOf.

func (Value) WriteShortString

func (v Value) WriteShortString(b *strings.Builder)

func (Value) WriteStringTo

func (v Value) WriteStringTo(b *wtf8.Buffer)

WriteStringTo appends the string value to b.

type WeakTable

type WeakTable struct {
	// contains filtered or unexported fields
}

WeakTable is the [[WeakMapData]] of a WeakMap or the [[WeakSetData]] of a WeakSet. Every key must be a value for which CanBeHeldWeakly holds.

func NewWeakTable

func NewWeakTable() *WeakTable

func (*WeakTable) Delete

func (t *WeakTable) Delete(k Value) bool

Delete deletes the entry with the key k and reports whether there was one.

func (*WeakTable) Get

func (t *WeakTable) Get(k Value) (Value, bool)

Get returns the value of the entry with the key k.

func (*WeakTable) Has

func (t *WeakTable) Has(k Value) bool

Has reports whether t has an entry with the key k.

func (*WeakTable) Set

func (t *WeakTable) Set(k, v Value)

Set sets the value of the entry with the key k.

type WellKnownSymbol

type WellKnownSymbol uint8

WellKnownSymbol identifies a well-known symbol.

const (
	SymbolIterator WellKnownSymbol = iota
	SymbolAsyncIterator
	SymbolHasInstance
	SymbolToPrimitive
	SymbolToStringTag
	SymbolSpecies
	SymbolIsConcatSpreadable
	SymbolUnscopables
	SymbolMatch
	SymbolMatchAll
	SymbolReplace
	SymbolSearch
	SymbolSplit
	SymbolDispose
	SymbolAsyncDispose
	SymbolMetadata
	WellKnownSymbolCount
)

Jump to

Keyboard shortcuts

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