public static (ScriptFunctionObject RegExp, ScriptObject RegExpPrototype) Initialise([NotNull] Agent agent, [NotNull] Realm realm)
        {
            var regExp = Intrinsics.CreateBuiltinFunction(realm, RegExp, realm.FunctionPrototype, 2, "RegExp", ConstructorKind.Base);

            var regExpPrototype = agent.ObjectCreate(realm.ObjectPrototype);

            Intrinsics.DefineDataProperty(regExpPrototype, "constructor", regExp);
            Intrinsics.DefineFunction(regExpPrototype, "exec", 1, realm, Exec);
            Intrinsics.DefineAccessorProperty(regExpPrototype, "flags", Intrinsics.CreateBuiltinFunction(realm, GetFlags, realm.FunctionPrototype, 0, "get flags"), null);
            Intrinsics.DefineAccessorProperty(regExpPrototype, "global", Intrinsics.CreateBuiltinFunction(realm, GetGlobal, realm.FunctionPrototype, 0, "get global"), null);
            Intrinsics.DefineAccessorProperty(regExpPrototype, "ignoreCase", Intrinsics.CreateBuiltinFunction(realm, GetIgnoreCase, realm.FunctionPrototype, 0, "get ignoreCase"), null);
            Intrinsics.DefineDataProperty(regExpPrototype, Symbol.Match, Intrinsics.CreateBuiltinFunction(realm, Match, realm.FunctionPrototype, 1, "[Symbol.match]"));
            Intrinsics.DefineAccessorProperty(regExpPrototype, "multiline", Intrinsics.CreateBuiltinFunction(realm, GetMultiline, realm.FunctionPrototype, 0, "get multiline"), null);
            Intrinsics.DefineDataProperty(regExpPrototype, Symbol.Replace, Intrinsics.CreateBuiltinFunction(realm, Replace, realm.FunctionPrototype, 2, "[Symbol.replace]"));
            Intrinsics.DefineDataProperty(regExpPrototype, Symbol.Search, Intrinsics.CreateBuiltinFunction(realm, Search, realm.FunctionPrototype, 1, "[Symbol.search]"));
            Intrinsics.DefineAccessorProperty(regExpPrototype, "source", Intrinsics.CreateBuiltinFunction(realm, GetSource, realm.FunctionPrototype, 0, "get source"), null);
            Intrinsics.DefineDataProperty(regExpPrototype, Symbol.Split, Intrinsics.CreateBuiltinFunction(realm, Split, realm.FunctionPrototype, 2, "[Symbol.split]"));
            Intrinsics.DefineAccessorProperty(regExpPrototype, "sticky", Intrinsics.CreateBuiltinFunction(realm, GetSticky, realm.FunctionPrototype, 0, "get sticky"), null);
            Intrinsics.DefineFunction(regExpPrototype, "test", 1, realm, Test);
            Intrinsics.DefineFunction(regExpPrototype, "toString", 0, realm, ToString);
            Intrinsics.DefineAccessorProperty(regExpPrototype, "unicode", Intrinsics.CreateBuiltinFunction(realm, GetUnicode, realm.FunctionPrototype, 0, "get unicode"), null);

            Intrinsics.DefineDataProperty(regExp, "prototype", regExpPrototype, false, false, false);
            Intrinsics.DefineAccessorProperty(regExp, Symbol.Species, Intrinsics.CreateBuiltinFunction(realm, GetSpecies, realm.FunctionPrototype, 0, "get [Symbol.species]"), null);

            return(regExp, regExpPrototype);
        }
        public static (ScriptFunctionObject Set, ScriptObject SetPrototype, ScriptObject SetIteratorPrototype) Initialise([NotNull] Agent agent, [NotNull] Realm realm)
        {
            var set = Intrinsics.CreateBuiltinFunction(realm, Set, realm.FunctionPrototype, 0, "Set", ConstructorKind.Base);

            Intrinsics.DefineAccessorProperty(set, Symbol.Species, Intrinsics.CreateBuiltinFunction(realm, GetSpecies, realm.FunctionPrototype, 0, "get [Symbol.species]"), null);

            var setPrototype = agent.ObjectCreate(realm.ObjectPrototype);

            Intrinsics.DefineFunction(setPrototype, "add", 1, realm, Add);
            Intrinsics.DefineFunction(setPrototype, "clear", 0, realm, Clear);
            Intrinsics.DefineDataProperty(setPrototype, "constructor", set);
            Intrinsics.DefineFunction(setPrototype, "delete", 1, realm, Delete);
            var setEntries = Intrinsics.DefineFunction(setPrototype, "entries", 0, realm, Entries);

            Intrinsics.DefineFunction(setPrototype, "forEach", 1, realm, ForEach);
            Intrinsics.DefineFunction(setPrototype, "has", 1, realm, Has);
            Intrinsics.DefineFunction(setPrototype, "keys", 0, realm, Keys);
            Intrinsics.DefineAccessorProperty(setPrototype, "size", Intrinsics.CreateBuiltinFunction(realm, GetSize, realm.FunctionPrototype, 0, "get size"), null);
            Intrinsics.DefineFunction(setPrototype, "values", 0, realm, Values);
            Intrinsics.DefineDataProperty(setPrototype, Symbol.Iterator, setEntries);
            Intrinsics.DefineDataProperty(setPrototype, Symbol.ToStringTag, "Set", false);

            Intrinsics.DefineDataProperty(set, "prototype", setPrototype, false, false, false);

            var setIteratorPrototype = agent.ObjectCreate(realm.IteratorPrototype);

            Intrinsics.DefineFunction(setIteratorPrototype, "next", 0, realm, Next);
            Intrinsics.DefineDataProperty(setIteratorPrototype, Symbol.ToStringTag, "Set Iterator", false);

            return(set, setPrototype, setIteratorPrototype);
        }
Exemple #3
0
        public static (ScriptFunctionObject DataView, ScriptObject DataViewPrototype) Initialise([NotNull] Agent agent, [NotNull] Realm realm)
        {
            var dataView = Intrinsics.CreateBuiltinFunction(realm, DataView, realm.FunctionPrototype, 1, "DataView", ConstructorKind.Base);

            var dataViewPrototype = agent.ObjectCreate(realm.ObjectPrototype);

            Intrinsics.DefineAccessorProperty(dataViewPrototype, "buffer", Intrinsics.CreateBuiltinFunction(realm, GetBuffer, realm.FunctionPrototype, 0, "get buffer"), null);
            Intrinsics.DefineAccessorProperty(dataViewPrototype, "byteLength", Intrinsics.CreateBuiltinFunction(realm, GetByteLength, realm.FunctionPrototype, 0, "get byteLength"), null);
            Intrinsics.DefineAccessorProperty(dataViewPrototype, "byteOffset", Intrinsics.CreateBuiltinFunction(realm, GetByteOffset, realm.FunctionPrototype, 0, "get byteOffset"), null);
            Intrinsics.DefineDataProperty(dataViewPrototype, "constructor", dataView);
            Intrinsics.DefineFunction(dataViewPrototype, "getFloat32", 1, realm, GetFloat32);
            Intrinsics.DefineFunction(dataViewPrototype, "getFloat64", 1, realm, GetFloat64);
            Intrinsics.DefineFunction(dataViewPrototype, "getInt8", 1, realm, GetInt8);
            Intrinsics.DefineFunction(dataViewPrototype, "getInt16", 1, realm, GetInt16);
            Intrinsics.DefineFunction(dataViewPrototype, "getInt32", 1, realm, GetInt32);
            Intrinsics.DefineFunction(dataViewPrototype, "getUint8", 1, realm, GetUint8);
            Intrinsics.DefineFunction(dataViewPrototype, "getUint16", 1, realm, GetUint16);
            Intrinsics.DefineFunction(dataViewPrototype, "getUint32", 1, realm, GetUint32);
            Intrinsics.DefineFunction(dataViewPrototype, "setFloat32", 2, realm, SetFloat32);
            Intrinsics.DefineFunction(dataViewPrototype, "setFloat64", 2, realm, SetFloat64);
            Intrinsics.DefineFunction(dataViewPrototype, "setInt8", 2, realm, SetInt8);
            Intrinsics.DefineFunction(dataViewPrototype, "setInt16", 2, realm, SetInt16);
            Intrinsics.DefineFunction(dataViewPrototype, "setInt32", 2, realm, SetInt32);
            Intrinsics.DefineFunction(dataViewPrototype, "setUint8", 2, realm, SetUint8);
            Intrinsics.DefineFunction(dataViewPrototype, "setUint16", 2, realm, SetUint16);
            Intrinsics.DefineFunction(dataViewPrototype, "setUint32", 2, realm, SetUint32);
            Intrinsics.DefineDataProperty(dataViewPrototype, Symbol.ToStringTag, "DataView", false);

            Intrinsics.DefineDataProperty(dataView, "prototype", dataViewPrototype, false, false, false);

            return(dataView, dataViewPrototype);
        }
        public static (ScriptFunctionObject SharedArrayBuffer, ScriptObject SharedArrayBufferPrototype) Initialise([NotNull] Agent agent, [NotNull] Realm realm)
        {
            var sharedArrayBuffer = Intrinsics.CreateBuiltinFunction(realm, SharedArrayBuffer, realm.FunctionPrototype, 1, "SharedArrayBuffer", ConstructorKind.Base);

            Intrinsics.DefineAccessorProperty(sharedArrayBuffer, Symbol.Species, Intrinsics.CreateBuiltinFunction(realm, GetSpecies, realm.FunctionPrototype, 0, "get [Symbol.species]"), null);

            var sharedArrayBufferPrototype = agent.ObjectCreate(realm.ObjectPrototype);

            Intrinsics.DefineAccessorProperty(sharedArrayBufferPrototype, "byteLength", Intrinsics.CreateBuiltinFunction(realm, GetByteLength, realm.FunctionPrototype, 0, "get byteLength"), null);
            Intrinsics.DefineDataProperty(sharedArrayBufferPrototype, "constructor", sharedArrayBuffer);
            Intrinsics.DefineFunction(sharedArrayBufferPrototype, "slice", 2, realm, Slice);
            Intrinsics.DefineDataProperty(sharedArrayBufferPrototype, Symbol.ToStringTag, "SharedArrayBuffer", false);

            Intrinsics.DefineDataProperty(sharedArrayBuffer, "prototype", sharedArrayBufferPrototype, false, false, false);

            return(sharedArrayBuffer, sharedArrayBufferPrototype);
        }
Exemple #5
0
        public static (ScriptFunctionObject TypedArray, ScriptObject TypedArrayPrototype) Initialise([NotNull] Agent agent, [NotNull] Realm realm)
        {
            var typedArray = Intrinsics.CreateBuiltinFunction(realm, TypedArray, realm.FunctionPrototype, 0, "TypedArray", ConstructorKind.Base);

            Intrinsics.DefineFunction(typedArray, "from", 1, realm, From);
            Intrinsics.DefineFunction(typedArray, "of", 1, realm, Of);
            Intrinsics.DefineAccessorProperty(typedArray, Symbol.Species, Intrinsics.CreateBuiltinFunction(realm, GetSpecies, realm.FunctionPrototype, 0, "get [Symbol.species]"), null);

            var typedArrayPrototype = agent.ObjectCreate(realm.ObjectPrototype);

            Intrinsics.DefineAccessorProperty(typedArrayPrototype, "buffer", Intrinsics.CreateBuiltinFunction(realm, GetBuffer, realm.FunctionPrototype, 0, "get buffer"), null);
            Intrinsics.DefineAccessorProperty(typedArrayPrototype, "byteLength", Intrinsics.CreateBuiltinFunction(realm, GetByteLength, realm.FunctionPrototype, 0, "get byteLength"), null);
            Intrinsics.DefineAccessorProperty(typedArrayPrototype, "byteOffset", Intrinsics.CreateBuiltinFunction(realm, GetByteOffset, realm.FunctionPrototype, 0, "get byteOffset"), null);
            Intrinsics.DefineDataProperty(typedArrayPrototype, "constructor", typedArray);
            Intrinsics.DefineFunction(typedArrayPrototype, "copyWithin", 2, realm, CopyWithin);
            Intrinsics.DefineFunction(typedArrayPrototype, "entries", 0, realm, Entries);
            Intrinsics.DefineFunction(typedArrayPrototype, "every", 1, realm, Every);
            Intrinsics.DefineFunction(typedArrayPrototype, "fill", 1, realm, Fill);
            Intrinsics.DefineFunction(typedArrayPrototype, "findIndex", 1, realm, FindIndex);
            Intrinsics.DefineFunction(typedArrayPrototype, "forEach", 1, realm, ForEach);
            Intrinsics.DefineFunction(typedArrayPrototype, "includes", 1, realm, Includes);
            Intrinsics.DefineFunction(typedArrayPrototype, "indexOf", 1, realm, IndexOf);
            Intrinsics.DefineFunction(typedArrayPrototype, "join", 1, realm, Join);
            Intrinsics.DefineFunction(typedArrayPrototype, "keys", 0, realm, Keys);
            Intrinsics.DefineFunction(typedArrayPrototype, "lastIndexOf", 1, realm, LastIndexOf);
            Intrinsics.DefineAccessorProperty(typedArrayPrototype, "length", Intrinsics.CreateBuiltinFunction(realm, GetLength, realm.FunctionPrototype, 0, "get length"), null);
            Intrinsics.DefineFunction(typedArrayPrototype, "map", 1, realm, Map);
            Intrinsics.DefineFunction(typedArrayPrototype, "reduce", 1, realm, Reduce);
            Intrinsics.DefineFunction(typedArrayPrototype, "reduceRight", 1, realm, ReduceRight);
            Intrinsics.DefineFunction(typedArrayPrototype, "reverse", 0, realm, Reverse);
            Intrinsics.DefineFunction(typedArrayPrototype, "set", 1, realm, Set);
            Intrinsics.DefineFunction(typedArrayPrototype, "slice", 2, realm, Slice);
            Intrinsics.DefineFunction(typedArrayPrototype, "some", 1, realm, Some);
            Intrinsics.DefineFunction(typedArrayPrototype, "sort", 1, realm, Sort);
            Intrinsics.DefineFunction(typedArrayPrototype, "subarray", 2, realm, Subarray);
            Intrinsics.DefineFunction(typedArrayPrototype, "toLocaleString", 0, realm, ToLocaleString);
            Intrinsics.DefineFunction(typedArrayPrototype, "toString", 0, realm, ToString);
            var values = Intrinsics.DefineFunction(typedArrayPrototype, "values", 0, realm, Values);

            Intrinsics.DefineDataProperty(typedArrayPrototype, Symbol.Iterator, values);
            Intrinsics.DefineAccessorProperty(typedArrayPrototype, Symbol.ToStringTag, Intrinsics.CreateBuiltinFunction(realm, GetToStringTag, realm.FunctionPrototype, 0, "get [Symbol.toStringTag]"), null);

            Intrinsics.DefineDataProperty(typedArray, "prototype", typedArrayPrototype, false, false, false);

            return(typedArray, typedArrayPrototype);
        }
Exemple #6
0
                       ScriptFunctionObject PromiseResolve) Initialise([NotNull] Agent agent, [NotNull] Realm realm)
        {
            var promise    = Intrinsics.CreateBuiltinFunction(realm, Promise, realm.FunctionPrototype, 1, "Promise", ConstructorKind.Base);
            var promiseAll = Intrinsics.DefineFunction(promise, "all", 1, realm, All);

            Intrinsics.DefineFunction(promise, "race", 1, realm, Race);
            var promiseReject  = Intrinsics.DefineFunction(promise, "reject", 1, realm, Reject);
            var promiseResolve = Intrinsics.DefineFunction(promise, "resolve", 1, realm, Resolve);

            Intrinsics.DefineAccessorProperty(promise, Symbol.Species, Intrinsics.CreateBuiltinFunction(realm, GetSpecies, realm.FunctionPrototype, 0, "get [Symbol.species]"), null);

            var promisePrototype = agent.ObjectCreate(realm.ObjectPrototype);

            Intrinsics.DefineFunction(promisePrototype, "catch", 1, realm, Catch);
            var promiseProtoThen = Intrinsics.DefineFunction(promisePrototype, "then", 2, realm, Then);

            Intrinsics.DefineDataProperty(promisePrototype, "constructor", promise);
            Intrinsics.DefineDataProperty(promisePrototype, Symbol.ToStringTag, "Promise", false);

            Intrinsics.DefineDataProperty(promise, "prototype", promisePrototype, false, false, false);

            return(promise, promisePrototype, promiseProtoThen, promiseAll, promiseReject, promiseResolve);
        }
                       ScriptFunctionObject ArrayProtoValues) Initialise([NotNull] Agent agent, [NotNull] Realm realm, ScriptObject objectPrototype, ScriptObject functionPrototype)
        {
            var array = Intrinsics.CreateBuiltinFunction(realm, Array, functionPrototype, 1, "Array", ConstructorKind.Base);

            Intrinsics.DefineFunction(array, "from", 1, realm, From);
            Intrinsics.DefineFunction(array, "isArray", 1, realm, IsArray);
            Intrinsics.DefineFunction(array, "of", 0, realm, Of);
            Intrinsics.DefineAccessorProperty(array, Symbol.Species, Intrinsics.CreateBuiltinFunction(realm, arguments => arguments.ThisValue, functionPrototype, 0, "get [Symbol.species]"), null);

            var arrayPrototype = new ScriptArrayObject(realm, objectPrototype, true, 0);

            Intrinsics.DefineFunction(arrayPrototype, "concat", 1, realm, Concat);
            Intrinsics.DefineDataProperty(arrayPrototype, "constructor", array);
            Intrinsics.DefineFunction(arrayPrototype, "copyWithin", 2, realm, CopyWithin);
            var arrayProtoEntries = Intrinsics.DefineFunction(arrayPrototype, "entries", 0, realm, Entries);

            Intrinsics.DefineFunction(arrayPrototype, "every", 1, realm, Every);
            Intrinsics.DefineFunction(arrayPrototype, "fill", 1, realm, Fill);
            Intrinsics.DefineFunction(arrayPrototype, "filter", 1, realm, Filter);
            Intrinsics.DefineFunction(arrayPrototype, "find", 1, realm, Find);
            Intrinsics.DefineFunction(arrayPrototype, "findIndex", 1, realm, FindIndex);
            var arrayProtoForEach = Intrinsics.DefineFunction(arrayPrototype, "forEach", 1, realm, ForEach);

            Intrinsics.DefineFunction(arrayPrototype, "includes", 1, realm, Includes);
            Intrinsics.DefineFunction(arrayPrototype, "indexOf", 1, realm, IndexOf);
            Intrinsics.DefineFunction(arrayPrototype, "join", 1, realm, Join);
            var arrayProtoKeys = Intrinsics.DefineFunction(arrayPrototype, "keys", 0, realm, Keys);

            Intrinsics.DefineFunction(arrayPrototype, "lastIndexOf", 1, realm, LastIndexOf);
            Intrinsics.DefineFunction(arrayPrototype, "map", 1, realm, Map);
            Intrinsics.DefineFunction(arrayPrototype, "pop", 0, realm, Pop);
            Intrinsics.DefineFunction(arrayPrototype, "push", 1, realm, Push);
            Intrinsics.DefineFunction(arrayPrototype, "reduce", 1, realm, Reduce);
            Intrinsics.DefineFunction(arrayPrototype, "reduceRight", 1, realm, ReduceRight);
            Intrinsics.DefineFunction(arrayPrototype, "reverse", 0, realm, Reverse);
            Intrinsics.DefineFunction(arrayPrototype, "shift", 0, realm, Shift);
            Intrinsics.DefineFunction(arrayPrototype, "slice", 2, realm, Slice);
            Intrinsics.DefineFunction(arrayPrototype, "some", 1, realm, Some);
            Intrinsics.DefineFunction(arrayPrototype, "sort", 1, realm, Sort);
            Intrinsics.DefineFunction(arrayPrototype, "splice", 2, realm, Splice);
            Intrinsics.DefineFunction(arrayPrototype, "toLocaleString", 0, realm, ToLocaleString);
            Intrinsics.DefineFunction(arrayPrototype, "toString", 0, realm, ToString);
            Intrinsics.DefineFunction(arrayPrototype, "unshift", 1, realm, Unshift);
            var arrayProtoValues = Intrinsics.DefineFunction(arrayPrototype, "values", 0, realm, Values);

            Intrinsics.DefineDataProperty(arrayPrototype, Symbol.Iterator, arrayProtoValues);

            var unscopableList = Agent.ObjectCreate(realm, null);

            unscopableList.CreateDataProperty("copyWithin", true);
            unscopableList.CreateDataProperty("entries", true);
            unscopableList.CreateDataProperty("fill", true);
            unscopableList.CreateDataProperty("find", true);
            unscopableList.CreateDataProperty("findIndex", true);
            unscopableList.CreateDataProperty("includes", true);
            unscopableList.CreateDataProperty("keys", true);
            unscopableList.CreateDataProperty("values", true);
            Intrinsics.DefineDataProperty(arrayPrototype, Symbol.Unscopables, unscopableList, false);

            var arrayIteratorPrototype = agent.ObjectCreate(realm.IteratorPrototype);

            Intrinsics.DefineFunction(arrayIteratorPrototype, "next", 0, realm, Next);
            Intrinsics.DefineDataProperty(arrayIteratorPrototype, Symbol.ToStringTag, "Array Iterator", false);

            Intrinsics.DefineDataProperty(array, "prototype", arrayPrototype, false, false, false);

            return(array, arrayPrototype, arrayIteratorPrototype, arrayProtoEntries, arrayProtoForEach, arrayProtoKeys, arrayProtoValues);
        }