ScriptObject

General Object class. Similar to JavaScript, this class works as a dictionary but the keys must be strings. Native D objects can be stored in any ScriptObject or derived class by assigning it to its nativeObject field. This is also the base class for arrays, strings, and functions so that those script values can have dictionary entries assigned to them as well.

Constructors

this
this(string typename, ScriptObject proto, Object native)

Constructs a new ScriptObject that can be stored inside ScriptValue.

this
this(string typename)

Empty constructor that leaves prototype, and nativeObject as null.

Members

Functions

addGetterProperty
void addGetterProperty(string propName, ScriptFunction getter)

Add a getter. Getters should be added to a constructor function's "prototype" field

addSetterProperty
void addSetterProperty(string propName, ScriptFunction setter)

Add a setter. Setters should be added to a constructor function's "prototype" field

assignField
ScriptAny assignField(string name, ScriptAny value)

Assigns a field to the current object. This does not call any setters.

dictionary
auto dictionary()

This property provides direct access to the dictionary

findGetter
ScriptFunction findGetter(string propName)

Find a getter in the prototype chain

findSetter
ScriptFunction findSetter(string propName)

Find a setter in the prototype chain

getOwnFieldOrPropertyDescriptors
ScriptObject getOwnFieldOrPropertyDescriptors()
Undocumented in source. Be warned that the author may not have intended to support it.
getOwnPropertyOrFieldDescriptor
ScriptObject getOwnPropertyOrFieldDescriptor(string propName)

Returns a property descriptor without searching the prototype chain. The object returned is an object possibly containing get, set, or value fields.

getters
auto getters()

getters property

hasGetter
bool hasGetter(string propName)

Determines if there is a getter for a given property

hasOwnFieldOrProperty
bool hasOwnFieldOrProperty(string propOrFieldName)

Tests whether or not a property or field exists in this object without searching the __proto__ chain.

hasSetter
bool hasSetter(string propName)

Determines if there is a setter for a given property

lookupField
ScriptAny lookupField(string name)

Looks up a field through the prototype chain. Note that this does not call any getters because it is not possible to pass an Environment to opIndex.

name
string name()

name property

nativeObject
T nativeObject()

If a native object was stored inside this ScriptObject, it can be retrieved with this function. Note that one must always check that the return value isn't null because all functions can be called with invalid "this" objects using functionName.call.

nativeObject
T nativeObject(T obj)

Native object can also be written because this is how binding works. Constructors receive a premade ScriptObject as the "this" with the name and prototype already set. Native D constructor functions have to set this property.

opCmp
int opCmp(ScriptObject other)

Comparison operator

opEquals
bool opEquals(ScriptObject other)

opEquals

opIndex
ScriptAny opIndex(string index)

Shorthand for lookupField.

opIndexAssign
ScriptAny opIndexAssign(T value, string index)

Shorthand for assignField

prototype
auto prototype()

prototype property

prototype
auto prototype(ScriptObject proto)

prototype property (setter)

setters
auto setters()

setters property

toHash
size_t toHash()

toHash

toString
string toString()

Returns a string with JSON like formatting representing the object's key-value pairs as well as any nested objects. In the future this will be replaced and an explicit function call will be required to print this detailed information.

Variables

_dictionary
ScriptAny[string] _dictionary;

The dictionary of key-value pairs

_getters
ScriptFunction[string] _getters;

The lookup table for getters

_setters
ScriptFunction[string] _setters;

The lookup table for setters

Meta