Bug 1227533 - Factor out dummy module resolve hook from tests r=shu
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 26 Nov 2015 11:49:54 +0000
changeset 308503 fd69e842ed494010cb24ac06b815ef3a8f043e09
parent 308471 6499724b05d08d6eb15e2e67d33e8cd0420f2475
child 308504 b61c35cebe4f3e49ea92faaa1723df836152fe97
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1227533
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1227533 - Factor out dummy module resolve hook from tests r=shu
js/src/jit-test/lib/dummyModuleResolveHook.js
js/src/jit-test/tests/modules/ambiguous-star-export.js
js/src/jit-test/tests/modules/bug1210391.js
js/src/jit-test/tests/modules/debugger-frames.js
js/src/jit-test/tests/modules/import-namespace.js
js/src/jit-test/tests/modules/many-exports.js
js/src/jit-test/tests/modules/many-imports.js
js/src/jit-test/tests/modules/many-namespace-imports.js
js/src/jit-test/tests/modules/module-declaration-instantiation.js
js/src/jit-test/tests/modules/module-evaluation.js
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/lib/dummyModuleResolveHook.js
@@ -0,0 +1,14 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// A dummy implementation of the module resolve hook used by module tests. This
+// implements the bare minimum necessary to allow modules to refer to each
+// other.
+
+let moduleRepo = {};
+setModuleResolveHook(function(module, specifier) {
+    if (specifier in moduleRepo)
+        return moduleRepo[specifier];
+    throw "Module '" + specifier + "' not found";
+});
--- a/js/src/jit-test/tests/modules/ambiguous-star-export.js
+++ b/js/src/jit-test/tests/modules/ambiguous-star-export.js
@@ -1,38 +1,31 @@
 // Test ambigious export * statements.
 
 "use strict";
 
 load(libdir + "asserts.js");
+load(libdir + "dummyModuleResolveHook.js");
 
 function checkModuleEval(source, result) {
     let m = parseModule(source);
     m.declarationInstantiation();
     assertEq(m.evaluation(), result);
 }
 
 function checkModuleSyntaxError(source) {
     let m = parseModule(source);
     assertThrowsInstanceOf(() => m.declarationInstantiation(), SyntaxError);
 }
 
-let moduleRepo = new Map();
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
-
 let a = moduleRepo['a'] = parseModule("export var a = 1; export var b = 2;");
 let b = moduleRepo['b'] = parseModule("export var b = 3; export var c = 4;");
 let c = moduleRepo['c'] = parseModule("export * from 'a'; export * from 'b';");
-let ms = [a, b, c];
-ms.map((m) => m.declarationInstantiation());
-ms.map((m) => m.evaluation(), moduleRepo.values());
+c.declarationInstantiation();
+c.evaluation();
 
 // Check importing/exporting non-ambiguous name works.
 checkModuleEval("import { a } from 'c'; a;", 1);
 checkModuleEval("export { a } from 'c';", undefined);
 
 // Check importing/exporting ambiguous name is a syntax error.
 checkModuleSyntaxError("import { b } from 'c';");
 checkModuleSyntaxError("export { b } from 'c';");
--- a/js/src/jit-test/tests/modules/bug1210391.js
+++ b/js/src/jit-test/tests/modules/bug1210391.js
@@ -1,11 +1,8 @@
-let moduleRepo = new Map();
-setModuleResolveHook(function(module, specifier) {
-        return moduleRepo[specifier];
-});
+load(libdir + "dummyModuleResolveHook.js");
 let a = moduleRepo['a'] = parseModule("export var a = 1; export var b = 2;");
 let b = moduleRepo['b'] = parseModule("export var b = 3; export var c = 4;");
 let c = moduleRepo['c'] = parseModule("export * from 'a'; export * from 'b';");
 let d = moduleRepo['d'] = parseModule("import { a } from 'c'; a;");
 d.declarationInstantiation();
 d.evaluation();
 
--- a/js/src/jit-test/tests/modules/debugger-frames.js
+++ b/js/src/jit-test/tests/modules/debugger-frames.js
@@ -52,21 +52,21 @@ dbg.onDebuggerStatement = function (fram
     // followed by the global.
     assertEq(env.parent.type, 'declarative');
     assertEq(env.parent.parent.type, 'object');
     assertEq(env.parent.parent.parent, null);
 };
 
 f = g2.eval(
 `
-    let moduleRepo = new Map();
+    let moduleRepo = {};
     setModuleResolveHook(function(module, specifier) {
         if (specifier in moduleRepo)
             return moduleRepo[specifier];
-        throw "Module " + specifier + " not found";
+        throw "Module '" + specifier + "' not found";
     });
 
     // Set up a module to import from.
     a = moduleRepo['a'] = parseModule(
     \`
         export var a = 1;
         export let b = 2;
         export const c = 3;
--- a/js/src/jit-test/tests/modules/import-namespace.js
+++ b/js/src/jit-test/tests/modules/import-namespace.js
@@ -1,21 +1,15 @@
 // Test importing module namespaces
 
 "use strict";
 
 load(libdir + "asserts.js");
 load(libdir + "iteration.js");
-
-let moduleRepo = new Map();
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
+load(libdir + "dummyModuleResolveHook.js");
 
 function parseAndEvaluate(source) {
     let m = parseModule(source);
     m.declarationInstantiation();
     return m.evaluation();
 }
 
 function testHasNames(names, expected) {
--- a/js/src/jit-test/tests/modules/many-exports.js
+++ b/js/src/jit-test/tests/modules/many-exports.js
@@ -1,19 +1,14 @@
 // Test many exports.
 
+load(libdir + "dummyModuleResolveHook.js");
+
 const count = 1024;
 
-let moduleRepo = {};
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
-
 let s = "";
 for (let i = 0; i < count; i++)
     s += "export let e" + i + " = " + (i * i) + ";\n";
 let a = moduleRepo['a'] = parseModule(s);
 
 let b = moduleRepo['b'] = parseModule("import * as ns from 'a'");
 
 b.declarationInstantiation();
--- a/js/src/jit-test/tests/modules/many-imports.js
+++ b/js/src/jit-test/tests/modules/many-imports.js
@@ -1,19 +1,14 @@
 // Test importing an import many times.
 
+load(libdir + "dummyModuleResolveHook.js");
+
 const count = 1024;
 
-let moduleRepo = {};
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
-
 let a = moduleRepo['a'] = parseModule("export let a = 1;");
 
 let s = "";
 for (let i = 0; i < count; i++) {
     s += "import { a as i" + i + " } from 'a';\n";
     s += "assertEq(i" + i + ", 1);\n";
 }
 let b = moduleRepo['b'] = parseModule(s);
--- a/js/src/jit-test/tests/modules/many-namespace-imports.js
+++ b/js/src/jit-test/tests/modules/many-namespace-imports.js
@@ -1,19 +1,14 @@
 // Test importing a namespace many times.
 
+load(libdir + "dummyModuleResolveHook.js");
+
 const count = 1024;
 
-let moduleRepo = {};
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
-
 let a = moduleRepo['a'] = parseModule("export let a = 1;");
 
 let s = "";
 for (let i = 0; i < count; i++) {
     s += "import * as ns" + i + " from 'a';\n";
     s += "assertEq(ns" + i + ".a, 1);\n";
 }
 let b = moduleRepo['b'] = parseModule(s);
--- a/js/src/jit-test/tests/modules/module-declaration-instantiation.js
+++ b/js/src/jit-test/tests/modules/module-declaration-instantiation.js
@@ -1,30 +1,25 @@
 // Exercise ModuleDeclarationInstantiation() operation.
 
+load(libdir + "dummyModuleResolveHook.js");
+
 function testModuleEnvironment(module, expected) {
     var actual = getModuleEnvironmentNames(module).sort();
     assertEq(actual.length, expected.length);
     for (var i = 0; i < actual.length; i++) {
         assertEq(actual[i], expected[i]);
     }
 }
 
 // Check the environment of an empty module.
 let m = parseModule("");
 m.declarationInstantiation();
 testModuleEnvironment(m, []);
 
-let moduleRepo = new Map();
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
-
 let a = moduleRepo['a'] = parseModule("var x = 1; export { x };");
 let b = moduleRepo['b'] = parseModule("import { x as y } from 'a';");
 
 a.declarationInstantiation();
 b.declarationInstantiation();
 
 testModuleEnvironment(a, ['x']);
 testModuleEnvironment(b, ['y']);
--- a/js/src/jit-test/tests/modules/module-evaluation.js
+++ b/js/src/jit-test/tests/modules/module-evaluation.js
@@ -1,18 +1,12 @@
 // Exercise ModuleEvaluation() concrete method.
 
 load(libdir + "asserts.js");
-
-let moduleRepo = new Map();
-setModuleResolveHook(function(module, specifier) {
-    if (specifier in moduleRepo)
-        return moduleRepo[specifier];
-    throw "Module " + specifier + " not found";
-});
+load(libdir + "dummyModuleResolveHook.js");
 
 function parseAndEvaluate(source) {
     let m = parseModule(source);
     m.declarationInstantiation();
     return m.evaluation();
 }
 
 // Check the evaluation of an empty module succeeds.