зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1499335 - Support module specifiers containing inline data in the shell r=evilpie
This commit is contained in:
Родитель
022503fa90
Коммит
d92d954cec
|
@ -0,0 +1,17 @@
|
|||
// |jit-test| module
|
||||
|
||||
import { a } from "javascript: export let a = 42;";
|
||||
assertEq(a, 42);
|
||||
|
||||
let result = null;
|
||||
let error = null;
|
||||
let promise = import("javascript: export let b = 100;");
|
||||
promise.then((ns) => {
|
||||
result = ns;
|
||||
}).catch((e) => {
|
||||
error = e;
|
||||
});
|
||||
|
||||
drainJobQueue();
|
||||
assertEq(error, null);
|
||||
assertEq(result.b, 100);
|
|
@ -8,6 +8,9 @@
|
|||
/* global setModuleDynamicImportHook finishDynamicModuleImport abortDynamicModuleImport */
|
||||
|
||||
// A basic synchronous module loader for testing the shell.
|
||||
//
|
||||
// Supports loading files and 'javascript:' URLs that embed JS source text.
|
||||
|
||||
{
|
||||
// Save standard built-ins before scripts can modify them.
|
||||
const ArrayPrototypeJoin = Array.prototype.join;
|
||||
|
@ -22,15 +25,22 @@ const StringPrototypeStartsWith = String.prototype.startsWith;
|
|||
const StringPrototypeSubstring = String.prototype.substring;
|
||||
const ErrorClass = Error;
|
||||
|
||||
const JAVASCRIPT_SCHEME = "javascript:";
|
||||
|
||||
const ReflectLoader = new class {
|
||||
constructor() {
|
||||
this.registry = new Map();
|
||||
this.loadPath = getModuleLoadPath();
|
||||
}
|
||||
|
||||
isJavascriptURL(name) {
|
||||
return ReflectApply(StringPrototypeStartsWith, name, [JAVASCRIPT_SCHEME]);
|
||||
}
|
||||
|
||||
resolve(name, referencingInfo) {
|
||||
if (os.path.isAbsolute(name))
|
||||
if (this.isJavascriptURL(name) || os.path.isAbsolute(name)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
let loadPath = this.loadPath;
|
||||
|
||||
|
@ -67,6 +77,10 @@ const ReflectLoader = new class {
|
|||
}
|
||||
|
||||
normalize(path) {
|
||||
if (this.isJavascriptURL(path)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
// Replace all forward slashes with backward slashes.
|
||||
// NB: It may be tempting to replace this loop with a call to
|
||||
|
@ -150,6 +164,10 @@ const ReflectLoader = new class {
|
|||
}
|
||||
|
||||
fetch(path) {
|
||||
if (this.isJavascriptURL(path)) {
|
||||
return ReflectApply(StringPrototypeSubstring, path, [JAVASCRIPT_SCHEME.length]);
|
||||
}
|
||||
|
||||
return os.file.readFile(path);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче