Skip to content

Commit 76275c2

Browse files
committed
Update JsBuiltIns to use similar functions enum approach as Intl
1 parent 1c22ba5 commit 76275c2

File tree

6 files changed

+115
-172
lines changed

6 files changed

+115
-172
lines changed

lib/Parser/perrors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ LSC_ERROR_MSG( 1077, ERRDestructNotInit, "Destructuring declarations cannot have
8888
LSC_ERROR_MSG(1079, ERRInvalidNewTarget, "Invalid use of the 'new.target' keyword")
8989
LSC_ERROR_MSG(1080, ERRForInNoInitAllowed, "for-in loop head declarations cannot have an initializer")
9090
LSC_ERROR_MSG(1081, ERRForOfNoInitAllowed, "for-of loop head declarations cannot have an initializer")
91-
LSC_ERROR_MSG(1082, ERRNonSimpleParamListInStrictMode, "Cannot apply strict mode on functions with non-simple parameter list")
91+
LSC_ERROR_MSG(1082, ERRNonSimpleParamListInStrictMode, "Illegal 'use strict' directive in function with non-simple parameter list")
9292

9393
LSC_ERROR_MSG(1083, ERRBadAwait, "'await' expression not allowed in this context")
9494

lib/Runtime/Base/JnDirectFields.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,16 @@ ENTRY(toLength)
645645
ENTRY(toInteger)
646646
ENTRY(arraySpeciesCreate)
647647
ENTRY(arrayCreateDataPropertyOrThrow)
648+
ENTRY(Array_values)
649+
ENTRY(Array_keys)
650+
ENTRY(Array_entries)
651+
ENTRY(Array_indexOf)
652+
ENTRY(Array_filter)
653+
ENTRY(Array_flat)
654+
ENTRY(Array_flatMap)
655+
ENTRY(Array_forEach)
656+
ENTRY(Object_fromEntries)
657+
ENTRY(FunctionKind)
648658

649659
// EngineInterfaceObject built-ins
650660
ENTRY(builtInJavascriptArrayEntryFilter)

lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,12 @@
88
(function (intrinsic) {
99
var platform = intrinsic.JsBuiltIn;
1010

11-
let FunctionsEnum = {
12-
ArrayValues: { className: "Array", methodName: "values", argumentsCount: 0, forceInline: true /*optional*/, alias: "Symbol.iterator" },
13-
ArrayKeys: { className: "Array", methodName: "keys", argumentsCount: 0, forceInline: true /*optional*/ },
14-
ArrayEntries: { className: "Array", methodName: "entries", argumentsCount: 0, forceInline: true /*optional*/ },
15-
ArrayIndexOf: { className: "Array", methodName: "indexOf", argumentsCount: 1, forceInline: true /*optional*/ },
16-
ArrayFilter: { className: "Array", methodName: "filter", argumentsCount: 1, forceInline: true /*optional*/ },
17-
ArrayFlat: { className: "Array", methodName: "flat", argumentsCount: 0, forceInline: true /*optional*/ },
18-
ArrayFlatMap: { className: "Array", methodName: "flatMap", argumentsCount: 1, forceInline: true /*optional*/ },
19-
ArrayForEach: { className: "Array", methodName: "forEach", argumentsCount: 1, forceInline: true /*optional*/ },
20-
ObjectFromEntries: { className: "Object", staticMethod: true, methodName: "fromEntries", argumentsCount: 1, forceInline: true /*optional*/ },
21-
};
22-
2311
var setPrototype = platform.builtInSetPrototype;
2412
var _objectDefineProperty = platform.builtInJavascriptObjectEntryDefineProperty;
2513
var Symbol = platform.Symbol;
2614
var CreateObject = platform.builtInJavascriptObjectEntryCreate;
2715

2816
platform.registerChakraLibraryFunction("ArrayIterator", function (arrayObj, iterationKind) {
29-
"use strict";
3017
__chakraLibrary.InitInternalProperties(this, 4, "__$arrayObj$__", "__$nextIndex$__", "__$kind$__", "__$internalDone$__");
3118
this.__$arrayObj$__ = arrayObj;
3219
this.__$nextIndex$__ = 0;
@@ -52,7 +39,6 @@
5239
// So, we need to set the prototype of attributes to null
5340
setPrototype({
5441
value: function () {
55-
"use strict";
5642
let o = this;
5743

5844
if (!(o instanceof __chakraLibrary.ArrayIterator)) {
@@ -100,40 +86,35 @@
10086
_objectDefineProperty(__chakraLibrary.ArrayIterator.prototype.next, 'name', setPrototype({ value: "next", writable: false, enumerable: false, configurable: true }, null));
10187

10288
platform.registerChakraLibraryFunction("CreateArrayIterator", function (arrayObj, iterationKind) {
103-
"use strict";
10489
return new __chakraLibrary.ArrayIterator(arrayObj, iterationKind);
10590
});
10691

107-
platform.registerFunction(FunctionsEnum.ArrayKeys, function () {
108-
"use strict";
92+
platform.registerFunction(platform.FunctionKind.Array_keys, function () {
10993
if (this === null || this === undefined) {
11094
__chakraLibrary.raiseThis_NullOrUndefined("Array.prototype.keys");
11195
}
11296
let o = __chakraLibrary.Object(this);
11397
return __chakraLibrary.CreateArrayIterator(o, 0 /* ArrayIterationKind.Key*/);
11498
});
11599

116-
platform.registerFunction(FunctionsEnum.ArrayValues, function () {
117-
"use strict";
100+
platform.registerFunction(platform.FunctionKind.Array_values, function () {
118101
if (this === null || this === undefined) {
119102
__chakraLibrary.raiseThis_NullOrUndefined("Array.prototype.values");
120103
}
121104
let o = __chakraLibrary.Object(this);
122105
return __chakraLibrary.CreateArrayIterator(o, 1 /* ArrayIterationKind.Value*/);
123106
});
124107

125-
platform.registerFunction(FunctionsEnum.ArrayEntries, function () {
126-
"use strict";
108+
platform.registerFunction(platform.FunctionKind.Array_entries, function () {
127109
if (this === null || this === undefined) {
128110
__chakraLibrary.raiseThis_NullOrUndefined("Array.prototype.entries");
129111
}
130112
let o = __chakraLibrary.Object(this);
131113
return __chakraLibrary.CreateArrayIterator(o, 2 /* ArrayIterationKind.KeyAndValue*/);
132114
});
133115

134-
platform.registerFunction(FunctionsEnum.ArrayIndexOf, function (searchElement, fromIndex) {
116+
platform.registerFunction(platform.FunctionKind.Array_indexOf, function (searchElement, fromIndex = undefined) {
135117
// ECMAScript 2017 #sec-array.prototype.indexof
136-
"use strict";
137118

138119
if (this === null || this === undefined) {
139120
__chakraLibrary.raiseThis_NullOrUndefined("Array.prototype.indexOf");
@@ -190,8 +171,6 @@
190171
});
191172

192173
platform.registerChakraLibraryFunction("CheckArrayAndGetLen", function (obj, builtInFunc) {
193-
"use strict";
194-
195174
if (__chakraLibrary.isArray(obj)) {
196175
return { o: obj, len: obj.length };
197176
} else {
@@ -202,9 +181,8 @@
202181
}
203182
});
204183

205-
platform.registerFunction(FunctionsEnum.ArrayFilter, function (callbackfn, thisArg) {
184+
platform.registerFunction(platform.FunctionKind.Array_filter, function (callbackfn, thisArg = undefined) {
206185
// ECMAScript 2017 #sec-array.prototype.filter
207-
"use strict";
208186

209187
let objInfo = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.filter");
210188
let o = objInfo.o;
@@ -236,7 +214,7 @@
236214
{
237215
// this is FlattenIntoArray from the flat/flatMap proposal BUT with no mapperFunction
238216
// a seperate function has been made to handle the case where there is a mapperFunction
239-
"use strict";
217+
240218
//1. Let targetIndex be start.
241219
let targetIndex = start;
242220
//2. Let sourceIndex be 0.
@@ -279,7 +257,6 @@
279257
});
280258

281259
platform.registerChakraLibraryFunction("FlattenIntoArrayMapped", function(target, source, sourceLen, start, mapperFunction, thisArg) {
282-
"use strict";
283260
// this is FlattenIntoArray from the flat/flatMap proposal BUT with:
284261
// depth = 1 and the presence of a mapperFunction guaranteed
285262
// both these conditions are always met when this is called from flatMap
@@ -344,8 +321,7 @@
344321
return targetIndex;
345322
});
346323

347-
platform.registerFunction(FunctionsEnum.ArrayFlat, function (depth) {
348-
"use strict";
324+
platform.registerFunction(platform.FunctionKind.Array_flat, function (depth = undefined) {
349325
//1. Let O be ? ToObject(this value).
350326
//2. Let sourceLen be ? ToLength(? Get(O, "length")).
351327
let objInfo = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.flat");
@@ -363,8 +339,7 @@
363339
return A;
364340
});
365341

366-
platform.registerFunction(FunctionsEnum.ArrayFlatMap, function (mapperFunction, thisArg) {
367-
"use strict";
342+
platform.registerFunction(platform.FunctionKind.Array_flatMap, function (mapperFunction, thisArg = undefined) {
368343
//1. Let O be ? ToObject(this value).
369344
//2. Let sourceLen be ? ToLength(? Get(O, "length")).
370345

@@ -385,9 +360,8 @@
385360
return A;
386361
});
387362

388-
platform.registerFunction(FunctionsEnum.ArrayForEach, function (callbackfn, thisArg) {
363+
platform.registerFunction(platform.FunctionKind.Array_forEach, function (callbackfn, thisArg = undefined) {
389364
// ECMAScript 2017 #sec-array.prototype.foreach
390-
"use strict";
391365

392366
let objInfo = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.forEach");
393367
let o = objInfo.o;
@@ -410,9 +384,8 @@
410384
return undefined;
411385
});
412386

413-
platform.registerFunction(FunctionsEnum.ObjectFromEntries, function (iterable) {
387+
platform.registerFunction(platform.FunctionKind.Object_fromEntries, function (iterable) {
414388
// #sec-object.fromentries
415-
"use strict";
416389
if (iterable === null || iterable === undefined) {
417390
__chakraLibrary.raiseNeedObject("Object.fromEntries");
418391
}

0 commit comments

Comments
 (0)