Bug 1380087 - Add an intrinsic to test for Map and Set objects. r=till

--HG--
extra : rebase_source : c30f89c15ddce434a86ca043b7ae6a9c5d00c905
This commit is contained in:
André Bargull 2017-07-12 07:37:53 -07:00
Родитель a108ef2f00
Коммит 8c234e0627
5 изменённых файлов: 31 добавлений и 26 удалений

Просмотреть файл

@ -25,26 +25,21 @@ function MapConstructorInit(iterable) {
}
}
/* ES6 20121122 draft 15.14.4.4. */
// ES2018 draft rev f83aa38282c2a60c6916ebc410bfdf105a0f6a54
// 23.1.3.5 Map.prototype.forEach ( callbackfn [ , thisArg ] )
function MapForEach(callbackfn, thisArg = undefined) {
/* Step 1-2. */
// Step 1.
var M = this;
if (!IsObject(M))
ThrowTypeError(JSMSG_INCOMPATIBLE_PROTO, "Map", "forEach", typeof M);
/* Step 3-4. */
try {
callFunction(std_Map_has, M);
} catch (e) {
// has will throw on non-Map objects, throw our own error in that case.
ThrowTypeError(JSMSG_INCOMPATIBLE_PROTO, "Map", "forEach", typeof M);
}
// Steps 2-3.
if (!IsObject(M) || !IsMapObject(M))
return callFunction(CallMapMethodIfWrapped, M, callbackfn, thisArg, "MapForEach");
/* Step 5. */
// Step 4.
if (!IsCallable(callbackfn))
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
/* Step 6-8. */
// Steps 5-8.
var entries = callFunction(std_Map_iterator, M);
while (true) {
var result = callFunction(MapIteratorNext, entries);

Просмотреть файл

@ -19,26 +19,21 @@ function SetConstructorInit(iterable) {
callContentFunction(adder, set, nextValue);
}
/* ES6 20121122 draft 15.16.4.6. */
// ES2018 draft rev f83aa38282c2a60c6916ebc410bfdf105a0f6a54
// 23.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] )
function SetForEach(callbackfn, thisArg = undefined) {
/* Step 1-2. */
// Step 1.
var S = this;
if (!IsObject(S))
ThrowTypeError(JSMSG_INCOMPATIBLE_PROTO, "Set", "forEach", typeof S);
/* Step 3-4. */
try {
callFunction(std_Set_has, S);
} catch (e) {
// has will throw on non-Set objects, throw our own error in that case.
ThrowTypeError(JSMSG_INCOMPATIBLE_PROTO, "Set", "forEach", typeof S);
}
// Steps 2-3.
if (!IsObject(S) || !IsSetObject(S))
return callFunction(CallSetMethodIfWrapped, S, callbackfn, thisArg, "SetForEach");
/* Step 5-6. */
// Step 4.
if (!IsCallable(callbackfn))
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
/* Step 7-8. */
// Steps 5-8.
var values = callFunction(std_Set_iterator, S);
while (true) {
var result = callFunction(SetIteratorNext, values);

Просмотреть файл

@ -128,8 +128,10 @@
_(IntrinsicIsSetIterator) \
_(IntrinsicIsStringIterator) \
\
_(IntrinsicIsMapObject) \
_(IntrinsicGetNextMapEntryForIterator) \
\
_(IntrinsicIsSetObject) \
_(IntrinsicGetNextSetEntryForIterator) \
\
_(IntrinsicNewArrayIterator) \

Просмотреть файл

@ -12,6 +12,7 @@
#include "builtin/AtomicsObject.h"
#include "builtin/Intl.h"
#include "builtin/MapObject.h"
#include "builtin/SIMD.h"
#include "builtin/TestingFunctions.h"
#include "builtin/TypedObject.h"
@ -313,10 +314,14 @@ IonBuilder::inlineNativeCall(CallInfo& callInfo, JSFunction* target)
return inlineFinishBoundFunctionInit(callInfo);
// Map intrinsics.
case InlinableNative::IntrinsicIsMapObject:
return inlineHasClass(callInfo, &MapObject::class_);
case InlinableNative::IntrinsicGetNextMapEntryForIterator:
return inlineGetNextEntryForIterator(callInfo, MGetNextEntryForIterator::Map);
// Set intrinsics.
case InlinableNative::IntrinsicIsSetObject:
return inlineHasClass(callInfo, &SetObject::class_);
case InlinableNative::IntrinsicGetNextSetEntryForIterator:
return inlineGetNextEntryForIterator(callInfo, MGetNextEntryForIterator::Set);

Просмотреть файл

@ -2428,6 +2428,14 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("CallStarGeneratorMethodIfWrapped",
CallNonGenericSelfhostedMethod<Is<StarGeneratorObject>>, 2, 0),
JS_INLINABLE_FN("IsMapObject", intrinsic_IsInstanceOfBuiltin<MapObject>, 1, 0,
IntrinsicIsMapObject),
JS_FN("CallMapMethodIfWrapped", CallNonGenericSelfhostedMethod<Is<MapObject>>, 2, 0),
JS_INLINABLE_FN("IsSetObject", intrinsic_IsInstanceOfBuiltin<SetObject>, 1, 0,
IntrinsicIsSetObject),
JS_FN("CallSetMethodIfWrapped", CallNonGenericSelfhostedMethod<Is<SetObject>>, 2, 0),
JS_FN("IsWeakSet", intrinsic_IsInstanceOfBuiltin<WeakSetObject>, 1,0),
JS_FN("CallWeakSetMethodIfWrapped",
CallNonGenericSelfhostedMethod<Is<WeakSetObject>>, 2, 0),