Bug 1283924 - Baldr: handle cross-global typed arrays in JS API (r=till)

MozReview-Commit-ID: BzAG4h9o7ua

--HG--
extra : rebase_source : 288bec0533f4601c6bae12c6c09fe0520cc84848
This commit is contained in:
Luke Wagner 2016-08-19 13:41:52 -05:00
Родитель 3a31be9c17
Коммит 0e064004db
2 изменённых файлов: 17 добавлений и 4 удалений

Просмотреть файл

@ -409,12 +409,13 @@ GetCompileArgs(JSContext* cx, CallArgs callArgs, const char* name, MutableBytes*
if (!*bytecode)
return false;
if (callArgs[0].toObject().is<TypedArrayObject>()) {
TypedArrayObject& view = callArgs[0].toObject().as<TypedArrayObject>();
JSObject* unwrapped = CheckedUnwrap(&callArgs[0].toObject());
if (unwrapped && unwrapped->is<TypedArrayObject>()) {
TypedArrayObject& view = unwrapped->as<TypedArrayObject>();
if (!(*bytecode)->append((uint8_t*)view.viewDataEither().unwrap(), view.byteLength()))
return false;
} else if (callArgs[0].toObject().is<ArrayBufferObject>()) {
ArrayBufferObject& buffer = callArgs[0].toObject().as<ArrayBufferObject>();
} else if (unwrapped && unwrapped->is<ArrayBufferObject>()) {
ArrayBufferObject& buffer = unwrapped->as<ArrayBufferObject>();
if (!(*bytecode)->append(buffer.dataPointer(), buffer.byteLength()))
return false;
} else {

Просмотреть файл

@ -0,0 +1,12 @@
load(libdir + "wasm.js");
const Module = WebAssembly.Module;
// Create cross-compartment wrappers to typed arrays and array buffers.
var g = newGlobal();
var code1 = g.eval("wasmTextToBinary('(module)', 'new-format')");
var code2 = g.eval("wasmTextToBinary('(module)', 'new-format').buffer");
// Should get unwrapped.
assertEq(new Module(code1) instanceof Module, true);
assertEq(new Module(code2) instanceof Module, true);