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

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

Issue 2299873002: [wasm] consolidate wasm and asm.js module compilation sequence (Closed)
Patch Set: [wasm] consolidate wasm and asm.js module compilation sequence Created 4 years, 4 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/wasm/wasm-module.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('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 7a276dfc94e0597c0b6922d2291d7ac00520c0a2..2470257735299c590511fb7e82f6d4f2b4152635 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -1629,17 +1629,50 @@ int GetNumberOfFunctions(JSObject* wasm) {
return ByteArray::cast(func_names_obj)->get_int(0);
}
-Handle<JSObject> CreateCompiledModuleObject(
- Isolate* isolate, Handle<FixedArray> compiled_module) {
- Handle<JSFunction> module_cons(
- isolate->native_context()->wasm_module_constructor());
- Handle<JSObject> module_obj = isolate->factory()->NewJSObject(module_cons);
+Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate,
+ Handle<FixedArray> compiled_module,
+ ModuleOrigin origin) {
+ Handle<JSObject> module_obj;
+ if (origin == ModuleOrigin::kWasmOrigin) {
+ Handle<JSFunction> module_cons(
+ isolate->native_context()->wasm_module_constructor());
+ module_obj = isolate->factory()->NewJSObject(module_cons);
+ } else {
+ DCHECK(origin == ModuleOrigin::kAsmJsOrigin);
+ Handle<Map> map = isolate->factory()->NewMap(
+ JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize);
+ module_obj = isolate->factory()->NewJSObjectFromMap(map, TENURED);
+ }
module_obj->SetInternalField(0, *compiled_module);
- Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym());
- Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check();
+ if (origin == ModuleOrigin::kWasmOrigin) {
+ Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym());
+ Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check();
+ }
return module_obj;
}
+MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate,
+ const byte* start,
+ const byte* end,
+ ErrorThrower* thrower,
+ ModuleOrigin origin) {
+ MaybeHandle<JSObject> nothing;
+ Zone zone(isolate->allocator());
+ ModuleResult result =
+ DecodeWasmModule(isolate, &zone, start, end, false, origin);
+ std::unique_ptr<const WasmModule> decoded_module(result.val);
+ if (result.failed()) {
+ thrower->Failed("Wasm decoding failed", result);
+ return nothing;
+ }
+ MaybeHandle<FixedArray> compiled_module =
+ decoded_module->CompileFunctions(isolate, thrower);
+ if (compiled_module.is_null()) return nothing;
+
+ return CreateCompiledModuleObject(isolate, compiled_module.ToHandleChecked(),
+ origin);
+}
+
namespace testing {
int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698