зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1285438 - Baldr: remove magic empty string export logic (r=bbouvier)
MozReview-Commit-ID: 5FgMIQiBozj --HG-- extra : rebase_source : 86b0b12e7618f950c576b5e77d47cd0abf613d0b
This commit is contained in:
Родитель
e6f8caae67
Коммит
0989d51119
|
@ -384,48 +384,34 @@ NewExportedFunction(JSContext* cx, Handle<WasmInstanceObject*> instanceObj, uint
|
|||
static bool
|
||||
CreateExportObject(JSContext* cx,
|
||||
HandleWasmInstanceObject instanceObj,
|
||||
HandleObject memoryObj,
|
||||
HandleWasmMemoryObject memoryObj,
|
||||
const ExportMap& exportMap,
|
||||
const ExportVector& exports,
|
||||
const Metadata& metadata,
|
||||
MutableHandleObject exportObj)
|
||||
{
|
||||
MOZ_ASSERT(exportMap.fieldNames.length() == exportMap.fieldsToExports.length());
|
||||
|
||||
for (size_t fieldIndex = 0; fieldIndex < exportMap.fieldNames.length(); fieldIndex++) {
|
||||
const char* fieldName = exportMap.fieldNames[fieldIndex].get();
|
||||
if (!*fieldName) {
|
||||
MOZ_ASSERT(!exportObj);
|
||||
uint32_t exportIndex = exportMap.fieldsToExports[fieldIndex];
|
||||
if (exportIndex == MemoryExport) {
|
||||
MOZ_ASSERT(memoryObj);
|
||||
exportObj.set(memoryObj);
|
||||
} else {
|
||||
exportObj.set(NewExportedFunction(cx, instanceObj, exportIndex));
|
||||
if (!exportObj)
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (metadata.isAsmJS() &&
|
||||
exportMap.fieldNames.length() == 1 &&
|
||||
strlen(exportMap.fieldNames[0].get()) == 0)
|
||||
{
|
||||
exportObj.set(NewExportedFunction(cx, instanceObj, 0));
|
||||
return !!exportObj;
|
||||
}
|
||||
|
||||
exportObj.set(JS_NewPlainObject(cx));
|
||||
if (!exportObj)
|
||||
return false;
|
||||
|
||||
Rooted<ValueVector> vals(cx, ValueVector(cx));
|
||||
for (size_t exportIndex = 0; exportIndex < exports.length(); exportIndex++) {
|
||||
for (size_t exportIndex = 0; exportIndex < metadata.exports.length(); exportIndex++) {
|
||||
JSFunction* fun = NewExportedFunction(cx, instanceObj, exportIndex);
|
||||
if (!fun || !vals.append(ObjectValue(*fun)))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!exportObj) {
|
||||
exportObj.set(JS_NewPlainObject(cx));
|
||||
if (!exportObj)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t fieldIndex = 0; fieldIndex < exportMap.fieldNames.length(); fieldIndex++) {
|
||||
const char* fieldName = exportMap.fieldNames[fieldIndex].get();
|
||||
if (!*fieldName)
|
||||
continue;
|
||||
|
||||
JSAtom* atom = AtomizeUTF8Chars(cx, fieldName, strlen(fieldName));
|
||||
if (!atom)
|
||||
return false;
|
||||
|
@ -433,10 +419,14 @@ CreateExportObject(JSContext* cx,
|
|||
RootedId id(cx, AtomToId(atom));
|
||||
RootedValue val(cx);
|
||||
uint32_t exportIndex = exportMap.fieldsToExports[fieldIndex];
|
||||
if (exportIndex == MemoryExport)
|
||||
val = ObjectValue(*memoryObj);
|
||||
else
|
||||
if (exportIndex == MemoryExport) {
|
||||
if (metadata.assumptions.newFormat)
|
||||
val = ObjectValue(*memoryObj);
|
||||
else
|
||||
val = ObjectValue(memoryObj->buffer());
|
||||
} else {
|
||||
val = vals[exportIndex];
|
||||
}
|
||||
|
||||
if (!JS_DefinePropertyById(cx, exportObj, id, val, JSPROP_ENUMERATE))
|
||||
return false;
|
||||
|
@ -499,14 +489,8 @@ Instance::create(JSContext* cx,
|
|||
|
||||
// Create the export object.
|
||||
|
||||
RootedObject memoryObj(cx);
|
||||
if (metadata.assumptions.newFormat)
|
||||
memoryObj = memory;
|
||||
else
|
||||
memoryObj = memory ? &memory->buffer() : nullptr;
|
||||
|
||||
RootedObject exportObj(cx);
|
||||
if (!CreateExportObject(cx, instanceObj, memoryObj, exportMap, metadata.exports, &exportObj))
|
||||
if (!CreateExportObject(cx, instanceObj, memory, exportMap, metadata, &exportObj))
|
||||
return false;
|
||||
|
||||
// Attach the export object to the instance object.
|
||||
|
|
|
@ -4,7 +4,10 @@ if (!wasmIsSupported())
|
|||
load(libdir + "asserts.js");
|
||||
|
||||
function wasmEvalText(str, imports) {
|
||||
return Wasm.instantiateModule(wasmTextToBinary(str), imports).exports;
|
||||
var exports = Wasm.instantiateModule(wasmTextToBinary(str), imports).exports;
|
||||
if (Object.keys(exports).length == 1 && exports[""])
|
||||
return exports[""];
|
||||
return exports;
|
||||
}
|
||||
|
||||
function mismatchError(actual, expect) {
|
||||
|
|
|
@ -10,12 +10,6 @@ assertEq(Object.getOwnPropertyNames(o).length, 0);
|
|||
var o = wasmEvalText('(module (func))');
|
||||
assertEq(Object.getOwnPropertyNames(o).length, 0);
|
||||
|
||||
var o = wasmEvalText('(module (func) (export "" 0))');
|
||||
assertEq(typeof o, "function");
|
||||
assertEq(o.name, "wasm-function[0]");
|
||||
assertEq(o.length, 0);
|
||||
assertEq(o(), undefined);
|
||||
|
||||
var o = wasmEvalText('(module (func) (export "a" 0))');
|
||||
var names = Object.getOwnPropertyNames(o);
|
||||
assertEq(names.length, 1);
|
||||
|
@ -30,21 +24,6 @@ assertEq(desc.enumerable, true);
|
|||
assertEq(desc.configurable, true);
|
||||
assertEq(desc.value(), undefined);
|
||||
|
||||
var o = wasmEvalText('(module (func) (func) (export "" 0) (export "a" 1))');
|
||||
assertEq(typeof o, "function");
|
||||
assertEq(o.name, "wasm-function[0]");
|
||||
assertEq(o.length, 0);
|
||||
assertEq(o(), undefined);
|
||||
var desc = Object.getOwnPropertyDescriptor(o, 'a');
|
||||
assertEq(typeof desc.value, "function");
|
||||
assertEq(desc.value.name, "wasm-function[1]");
|
||||
assertEq(desc.value.length, 0);
|
||||
assertEq(desc.value(), undefined);
|
||||
assertEq(desc.writable, true);
|
||||
assertEq(desc.enumerable, true);
|
||||
assertEq(desc.configurable, true);
|
||||
assertEq(desc.value(), undefined);
|
||||
|
||||
wasmEvalText('(module (func) (func) (export "a" 0))');
|
||||
wasmEvalText('(module (func) (func) (export "a" 1))');
|
||||
wasmEvalText('(module (func $a) (func $b) (export "a" $a) (export "b" $b))');
|
||||
|
|
|
@ -151,6 +151,12 @@ assertEq(Object.keys(e).join(), "bar,foo");
|
|||
assertEq(e.foo(), undefined);
|
||||
assertEq(e.bar.buffer.byteLength, 64*1024);
|
||||
|
||||
var code = textToBinary('(module (memory 1 1) (export "" memory))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).length, 1);
|
||||
assertEq(String(Object.keys(e)), "");
|
||||
assertEq(e[""] instanceof Memory, true);
|
||||
|
||||
// Re-exports:
|
||||
|
||||
var code = textToBinary('(module (import "a" "b" (memory 1 1)) (export "foo" memory) (export "bar" memory))');
|
||||
|
|
|
@ -215,7 +215,7 @@ function exec(e) {
|
|||
|
||||
if (exprName === "module") {
|
||||
let moduleText = e.toString();
|
||||
module = wasmEvalText(moduleText, imports);
|
||||
module = Wasm.instantiateModule(wasmTextToBinary(moduleText), imports).exports;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -231,9 +231,6 @@ function exec(e) {
|
|||
|
||||
if (typeof module[name] === "function") {
|
||||
fn = module[name];
|
||||
} else if (name === "") {
|
||||
fn = module;
|
||||
assert(typeof fn === "function", "Default exported function not found: " + e);
|
||||
} else {
|
||||
assert(false, "Exported function not found: " + e);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче