summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-14 08:52:37 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-14 08:52:37 +0200
commit6452e3c9785260f21c5013d31e855e7b3e0497f4 (patch)
tree93cbcc1593efd16e5455711865b4790cbe5719c0 /js
parente2719e1dbf7b706cd5ec8b3ecd899d2fc063c20f (diff)
downloadUXP-6452e3c9785260f21c5013d31e855e7b3e0497f4.tar
UXP-6452e3c9785260f21c5013d31e855e7b3e0497f4.tar.gz
UXP-6452e3c9785260f21c5013d31e855e7b3e0497f4.tar.lz
UXP-6452e3c9785260f21c5013d31e855e7b3e0497f4.tar.xz
UXP-6452e3c9785260f21c5013d31e855e7b3e0497f4.zip
Bug 1326453 - Part 4: Return @@toStringTag in [[OwnPropertyKeys]] trap for module namespace objects
Diffstat (limited to 'js')
-rw-r--r--js/src/builtin/ModuleObject.cpp4
-rw-r--r--js/src/jit-test/tests/modules/import-namespace.js19
2 files changed, 20 insertions, 3 deletions
diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp
index 28a3329a8..6d42508e0 100644
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -500,7 +500,7 @@ ModuleNamespaceObject::ProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
RootedObject exports(cx, &ns->exports());
uint32_t count;
- if (!GetLengthProperty(cx, exports, &count) || !props.reserve(props.length() + count))
+ if (!GetLengthProperty(cx, exports, &count) || !props.reserve(props.length() + count + 1))
return false;
Rooted<ValueVector> names(cx, ValueVector(cx));
@@ -510,6 +510,8 @@ ModuleNamespaceObject::ProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject
for (uint32_t i = 0; i < count; i++)
props.infallibleAppend(AtomToId(&names[i].toString()->asAtom()));
+ props.infallibleAppend(SYMBOL_TO_JSID(cx->wellKnownSymbols().toStringTag));
+
return true;
}
diff --git a/js/src/jit-test/tests/modules/import-namespace.js b/js/src/jit-test/tests/modules/import-namespace.js
index 27d0193aa..2094c27fe 100644
--- a/js/src/jit-test/tests/modules/import-namespace.js
+++ b/js/src/jit-test/tests/modules/import-namespace.js
@@ -19,9 +19,19 @@ function testHasNames(names, expected) {
});
}
+function testEqualArrays(actual, expected) {
+ assertEq(Array.isArray(actual), true);
+ assertEq(Array.isArray(expected), true);
+ assertEq(actual.length, expected.length);
+ for (let i = 0; i < expected.length; i++) {
+ assertEq(actual[i], expected[i]);
+ }
+}
+
let a = moduleRepo['a'] = parseModule(
- `export var a = 1;
- export var b = 2;`
+ `// Reflection methods should return these exports alphabetically sorted.
+ export var b = 2;
+ export var a = 1;`
);
let b = moduleRepo['b'] = parseModule(
@@ -66,6 +76,11 @@ assertEq(typeof desc.get, "undefined");
assertEq(typeof desc.set, "undefined");
assertEq(Object.prototype.toString.call(ns), "[object Module]");
+// Test [[OwnPropertyKeys]] internal method.
+testEqualArrays(Reflect.ownKeys(ns), ["a", "b", Symbol.toStringTag]);
+testEqualArrays(Object.getOwnPropertyNames(ns), ["a", "b"]);
+testEqualArrays(Object.getOwnPropertySymbols(ns), [Symbol.toStringTag]);
+
// Test cyclic namespace import and access in module evaluation.
let c = moduleRepo['c'] =
parseModule("export let c = 1; import * as ns from 'd'; let d = ns.d;");