mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-28 01:57:30 +09:00
Bug 1326453 - Part 1: Remove @@iterator method from module namespace objects per ES2017
This commit is contained in:
parent
556510df8f
commit
99f20bdc22
4 changed files with 1 additions and 63 deletions
|
|
@ -318,11 +318,3 @@ function ModuleEvaluation()
|
||||||
return EvaluateModule(module);
|
return EvaluateModule(module);
|
||||||
}
|
}
|
||||||
_SetCanonicalName(ModuleEvaluation, "ModuleEvaluation");
|
_SetCanonicalName(ModuleEvaluation, "ModuleEvaluation");
|
||||||
|
|
||||||
function ModuleNamespaceEnumerate()
|
|
||||||
{
|
|
||||||
if (!IsObject(this) || !IsModuleNamespace(this))
|
|
||||||
return callFunction(CallModuleMethodIfWrapped, this, "ModuleNamespaceEnumerate");
|
|
||||||
|
|
||||||
return CreateListIterator(ModuleNamespaceExports(this));
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -289,14 +289,6 @@ ModuleNamespaceObject::create(JSContext* cx, HandleModuleObject module)
|
||||||
if (!object)
|
if (!object)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
RootedId funName(cx, INTERNED_STRING_TO_JSID(cx, cx->names().Symbol_iterator_fun));
|
|
||||||
RootedFunction enumerateFun(cx);
|
|
||||||
enumerateFun = JS::GetSelfHostedFunction(cx, "ModuleNamespaceEnumerate", funName, 0);
|
|
||||||
if (!enumerateFun)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
SetProxyExtra(object, ProxyHandler::EnumerateFunctionSlot, ObjectValue(*enumerateFun));
|
|
||||||
|
|
||||||
return &object->as<ModuleNamespaceObject>();
|
return &object->as<ModuleNamespaceObject>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,11 +333,6 @@ ModuleNamespaceObject::ProxyHandler::ProxyHandler()
|
||||||
: BaseProxyHandler(&family, true)
|
: BaseProxyHandler(&family, true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
JS::Value ModuleNamespaceObject::ProxyHandler::getEnumerateFunction(HandleObject proxy) const
|
|
||||||
{
|
|
||||||
return GetProxyExtra(proxy, EnumerateFunctionSlot);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ModuleNamespaceObject::ProxyHandler::getPrototype(JSContext* cx, HandleObject proxy,
|
ModuleNamespaceObject::ProxyHandler::getPrototype(JSContext* cx, HandleObject proxy,
|
||||||
MutableHandleObject protop) const
|
MutableHandleObject protop) const
|
||||||
|
|
@ -402,15 +389,6 @@ ModuleNamespaceObject::ProxyHandler::getOwnPropertyDescriptor(JSContext* cx, Han
|
||||||
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
|
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
|
||||||
if (JSID_IS_SYMBOL(id)) {
|
if (JSID_IS_SYMBOL(id)) {
|
||||||
Rooted<JS::Symbol*> symbol(cx, JSID_TO_SYMBOL(id));
|
Rooted<JS::Symbol*> symbol(cx, JSID_TO_SYMBOL(id));
|
||||||
if (symbol == cx->wellKnownSymbols().iterator) {
|
|
||||||
RootedValue enumerateFun(cx, getEnumerateFunction(proxy));
|
|
||||||
desc.object().set(proxy);
|
|
||||||
desc.setConfigurable(false);
|
|
||||||
desc.setEnumerable(false);
|
|
||||||
desc.setValue(enumerateFun);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (symbol == cx->wellKnownSymbols().toStringTag) {
|
if (symbol == cx->wellKnownSymbols().toStringTag) {
|
||||||
RootedValue value(cx, StringValue(cx->names().Module));
|
RootedValue value(cx, StringValue(cx->names().Module));
|
||||||
desc.object().set(proxy);
|
desc.object().set(proxy);
|
||||||
|
|
@ -458,8 +436,7 @@ ModuleNamespaceObject::ProxyHandler::has(JSContext* cx, HandleObject proxy, Hand
|
||||||
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
|
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
|
||||||
if (JSID_IS_SYMBOL(id)) {
|
if (JSID_IS_SYMBOL(id)) {
|
||||||
Rooted<JS::Symbol*> symbol(cx, JSID_TO_SYMBOL(id));
|
Rooted<JS::Symbol*> symbol(cx, JSID_TO_SYMBOL(id));
|
||||||
return symbol == cx->wellKnownSymbols().iterator ||
|
return symbol == cx->wellKnownSymbols().toStringTag;
|
||||||
symbol == cx->wellKnownSymbols().toStringTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*bp = ns->bindings().has(id);
|
*bp = ns->bindings().has(id);
|
||||||
|
|
@ -473,11 +450,6 @@ ModuleNamespaceObject::ProxyHandler::get(JSContext* cx, HandleObject proxy, Hand
|
||||||
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
|
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
|
||||||
if (JSID_IS_SYMBOL(id)) {
|
if (JSID_IS_SYMBOL(id)) {
|
||||||
Rooted<JS::Symbol*> symbol(cx, JSID_TO_SYMBOL(id));
|
Rooted<JS::Symbol*> symbol(cx, JSID_TO_SYMBOL(id));
|
||||||
if (symbol == cx->wellKnownSymbols().iterator) {
|
|
||||||
vp.set(getEnumerateFunction(proxy));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (symbol == cx->wellKnownSymbols().toStringTag) {
|
if (symbol == cx->wellKnownSymbols().toStringTag) {
|
||||||
vp.setString(cx->names().Module);
|
vp.setString(cx->names().Module);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -142,15 +142,8 @@ class ModuleNamespaceObject : public ProxyObject
|
||||||
private:
|
private:
|
||||||
struct ProxyHandler : public BaseProxyHandler
|
struct ProxyHandler : public BaseProxyHandler
|
||||||
{
|
{
|
||||||
enum
|
|
||||||
{
|
|
||||||
EnumerateFunctionSlot = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
ProxyHandler();
|
ProxyHandler();
|
||||||
|
|
||||||
JS::Value getEnumerateFunction(HandleObject proxy) const;
|
|
||||||
|
|
||||||
bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
||||||
MutableHandle<PropertyDescriptor> desc) const override;
|
MutableHandle<PropertyDescriptor> desc) const override;
|
||||||
bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
||||||
|
|
|
||||||
|
|
@ -64,25 +64,6 @@ assertEq(typeof desc.get, "undefined");
|
||||||
assertEq(typeof desc.set, "undefined");
|
assertEq(typeof desc.set, "undefined");
|
||||||
assertEq(Object.prototype.toString.call(ns), "[object Module]");
|
assertEq(Object.prototype.toString.call(ns), "[object Module]");
|
||||||
|
|
||||||
// Test @@iterator method.
|
|
||||||
let iteratorFun = ns[Symbol.iterator];
|
|
||||||
assertEq(iteratorFun.name, "[Symbol.iterator]");
|
|
||||||
|
|
||||||
let iterator = ns[Symbol.iterator]();
|
|
||||||
assertEq(iterator[Symbol.iterator](), iterator);
|
|
||||||
assertIteratorNext(iterator, "a");
|
|
||||||
assertIteratorNext(iterator, "b");
|
|
||||||
assertIteratorDone(iterator);
|
|
||||||
|
|
||||||
// The iterator's next method can only be called on the object it was originally
|
|
||||||
// associated with.
|
|
||||||
iterator = ns[Symbol.iterator]();
|
|
||||||
let iterator2 = ns[Symbol.iterator]();
|
|
||||||
assertThrowsInstanceOf(() => iterator.next.call({}), TypeError);
|
|
||||||
assertThrowsInstanceOf(() => iterator.next.call(iterator2), TypeError);
|
|
||||||
assertEq(iterator.next.call(iterator).value, "a");
|
|
||||||
assertEq(iterator2.next.call(iterator2).value, "a");
|
|
||||||
|
|
||||||
// Test cyclic namespace import and access in module evaluation.
|
// Test cyclic namespace import and access in module evaluation.
|
||||||
let c = moduleRepo['c'] =
|
let c = moduleRepo['c'] =
|
||||||
parseModule("export let c = 1; import * as ns from 'd'; let d = ns.d;");
|
parseModule("export let c = 1; import * as ns from 'd'; let d = ns.d;");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue