Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1545)

Unified Diff: src/wasm/wasm-module.cc

Issue 2664493002: [wasm][asm.js] Make asm.js->wasm return a regular object. (Closed)
Patch Set: fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/asmjs/asm-js.cc ('k') | test/mjsunit/asm/asm-validation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index e4188da72a3bf1b0545c5a712c18c218ff5da8ba..ed915b10460f23381f9305b0fa4a8fa226aa4160 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -16,6 +16,7 @@
#include "src/snapshot/snapshot.h"
#include "src/v8.h"
+#include "src/asmjs/asm-wasm-builder.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-js.h"
@@ -1918,17 +1919,30 @@ class WasmInstanceBuilder {
Handle<JSFunction>::null());
}
- Handle<JSObject> exports_object = instance;
+ Handle<JSObject> exports_object;
if (module_->origin == kWasmOrigin) {
// Create the "exports" object.
exports_object = isolate_->factory()->NewJSObjectWithNullProto();
- Handle<String> exports_name =
- isolate_->factory()->InternalizeUtf8String("exports");
- JSObject::AddProperty(instance, exports_name, exports_object, NONE);
+ } else if (module_->origin == kAsmJsOrigin) {
+ Handle<JSFunction> object_function = Handle<JSFunction>(
+ isolate_->native_context()->object_function(), isolate_);
+ exports_object = isolate_->factory()->NewJSObject(object_function);
+ } else {
+ UNREACHABLE();
}
+ Handle<String> exports_name =
+ isolate_->factory()->InternalizeUtf8String("exports");
+ JSObject::AddProperty(instance, exports_name, exports_object, NONE);
+
+ Handle<String> foreign_init_name =
+ isolate_->factory()->InternalizeUtf8String(
+ wasm::AsmWasmBuilder::foreign_init_name);
+ Handle<String> single_function_name =
+ isolate_->factory()->InternalizeUtf8String(
+ wasm::AsmWasmBuilder::single_function_name);
PropertyDescriptor desc;
- desc.set_writable(false);
+ desc.set_writable(module_->origin == kAsmJsOrigin);
desc.set_enumerable(true);
// Count up export indexes.
@@ -1957,6 +1971,15 @@ class WasmInstanceBuilder {
WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
isolate_, compiled_module_, exp.name_offset, exp.name_length)
.ToHandleChecked();
+ Handle<JSObject> export_to;
+ if (module_->origin == kAsmJsOrigin && exp.kind == kExternalFunction &&
titzer 2017/01/31 00:08:13 Can you leave a TODO here? We're adding to string
+ (String::Equals(name, foreign_init_name) ||
+ String::Equals(name, single_function_name))) {
+ export_to = instance;
+ } else {
+ export_to = exports_object;
+ }
+
switch (exp.kind) {
case kExternalFunction: {
// Wrap and export the code as a JSFunction.
@@ -2053,14 +2076,13 @@ class WasmInstanceBuilder {
// Skip duplicates for asm.js.
if (module_->origin == kAsmJsOrigin) {
- v8::Maybe<bool> status =
- JSReceiver::HasOwnProperty(exports_object, name);
+ v8::Maybe<bool> status = JSReceiver::HasOwnProperty(export_to, name);
if (status.FromMaybe(false)) {
continue;
}
}
v8::Maybe<bool> status = JSReceiver::DefineOwnProperty(
- isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR);
+ isolate_, export_to, name, &desc, Object::THROW_ON_ERROR);
if (!status.IsJust()) {
thrower_->LinkError("export of %.*s failed.", name->length(),
name->ToCString().get());
« no previous file with comments | « src/asmjs/asm-js.cc ('k') | test/mjsunit/asm/asm-validation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698