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

Side by Side Diff: src/wasm/wasm-js.cc

Issue 2623183002: [wasm] Implement WebAssembly.Module.exports function. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api-natives.h" 5 #include "src/api-natives.h"
6 #include "src/api.h" 6 #include "src/api.h"
7 #include "src/asmjs/asm-js.h" 7 #include "src/asmjs/asm-js.h"
8 #include "src/asmjs/asm-typer.h" 8 #include "src/asmjs/asm-typer.h"
9 #include "src/asmjs/asm-wasm-builder.h" 9 #include "src/asmjs/asm-wasm-builder.h"
10 #include "src/assert-scope.h" 10 #include "src/assert-scope.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 Local<Object> module_obj = Local<Object>::Cast(args[0]); 255 Local<Object> module_obj = Local<Object>::Cast(args[0]);
256 i::Handle<i::WasmModuleObject> i_module_obj = 256 i::Handle<i::WasmModuleObject> i_module_obj =
257 i::Handle<i::WasmModuleObject>::cast(v8::Utils::OpenHandle(*module_obj)); 257 i::Handle<i::WasmModuleObject>::cast(v8::Utils::OpenHandle(*module_obj));
258 258
259 i::Handle<i::JSArray> imports = i::wasm::GetImports(i_isolate, i_module_obj); 259 i::Handle<i::JSArray> imports = i::wasm::GetImports(i_isolate, i_module_obj);
260 260
261 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 261 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
262 return_value.Set(Utils::ToLocal(imports)); 262 return_value.Set(Utils::ToLocal(imports));
263 } 263 }
264 264
265 void WebAssemblyModuleExports(const v8::FunctionCallbackInfo<v8::Value>& args) {
266 HandleScope scope(args.GetIsolate());
267 v8::Isolate* isolate = args.GetIsolate();
268 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
269
270 ErrorThrower thrower(i_isolate, "WebAssembly.Module.exports()");
271
272 if (args.Length() < 1) {
273 thrower.TypeError("Argument 0 must be a WebAssembly.Module");
274 return;
275 }
276
277 Local<Context> context = isolate->GetCurrentContext();
278 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
279 if (!BrandCheck(isolate, Utils::OpenHandle(*args[0]),
280 i::Handle<i::Symbol>(i_context->wasm_module_sym()),
281 "Argument 0 must be a WebAssembly.Module")) {
282 return;
283 }
284
285 Local<Object> module_obj = Local<Object>::Cast(args[0]);
286 i::Handle<i::WasmModuleObject> i_module_obj =
287 i::Handle<i::WasmModuleObject>::cast(v8::Utils::OpenHandle(*module_obj));
288
289 i::Handle<i::JSArray> exports = i::wasm::GetExports(i_isolate, i_module_obj);
290
291 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
292 return_value.Set(Utils::ToLocal(exports));
293 }
294
265 void WebAssemblyInstanceCtor(const v8::FunctionCallbackInfo<v8::Value>& args) { 295 void WebAssemblyInstanceCtor(const v8::FunctionCallbackInfo<v8::Value>& args) {
266 HandleScope scope(args.GetIsolate()); 296 HandleScope scope(args.GetIsolate());
267 v8::Isolate* isolate = args.GetIsolate(); 297 v8::Isolate* isolate = args.GetIsolate();
268 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 298 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
269 299
270 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()"); 300 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()");
271 301
272 if (args.Length() < 1) { 302 if (args.Length() < 1) {
273 thrower.TypeError("Argument 0 must be a WebAssembly.Module"); 303 thrower.TypeError("Argument 0 must be a WebAssembly.Module");
274 return; 304 return;
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 Handle<JSObject> module_proto = 776 Handle<JSObject> module_proto =
747 factory->NewJSObject(module_constructor, TENURED); 777 factory->NewJSObject(module_constructor, TENURED);
748 i::Handle<i::Map> map = isolate->factory()->NewMap( 778 i::Handle<i::Map> map = isolate->factory()->NewMap(
749 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 779 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize +
750 WasmModuleObject::kFieldCount * i::kPointerSize); 780 WasmModuleObject::kFieldCount * i::kPointerSize);
751 JSFunction::SetInitialMap(module_constructor, map, module_proto); 781 JSFunction::SetInitialMap(module_constructor, map, module_proto);
752 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(), 782 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(),
753 module_constructor, DONT_ENUM); 783 module_constructor, DONT_ENUM);
754 InstallFunc(isolate, module_constructor, "imports", WebAssemblyModuleImports, 784 InstallFunc(isolate, module_constructor, "imports", WebAssemblyModuleImports,
755 1); 785 1);
786 InstallFunc(isolate, module_constructor, "exports", WebAssemblyModuleExports,
787 1);
756 788
757 // Setup Instance 789 // Setup Instance
758 Handle<JSFunction> instance_constructor = 790 Handle<JSFunction> instance_constructor =
759 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstanceCtor, 1); 791 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstanceCtor, 1);
760 context->set_wasm_instance_constructor(*instance_constructor); 792 context->set_wasm_instance_constructor(*instance_constructor);
761 793
762 // Setup Table 794 // Setup Table
763 Handle<JSFunction> table_constructor = 795 Handle<JSFunction> table_constructor =
764 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable, 1); 796 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable, 1);
765 context->set_wasm_table_constructor(*table_constructor); 797 context->set_wasm_table_constructor(*table_constructor);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); 896 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
865 return HasBrand(value, symbol); 897 return HasBrand(value, symbol);
866 } 898 }
867 899
868 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { 900 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
869 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); 901 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
870 return HasBrand(value, symbol); 902 return HasBrand(value, symbol);
871 } 903 }
872 } // namespace internal 904 } // namespace internal
873 } // namespace v8 905 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698