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

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

Issue 1775353003: [wasm] Memory is exported on the module.exports object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 | test/mjsunit/wasm/calls.js » ('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/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/simulator.h" 9 #include "src/simulator.h"
10 10
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (!AllocateMemory(&thrower, isolate, &instance)) { 371 if (!AllocateMemory(&thrower, isolate, &instance)) {
372 return MaybeHandle<JSObject>(); 372 return MaybeHandle<JSObject>();
373 } 373 }
374 } else { 374 } else {
375 SetMemory(&instance, memory); 375 SetMemory(&instance, memory);
376 } 376 }
377 instance.js_object->SetInternalField(kWasmMemArrayBuffer, 377 instance.js_object->SetInternalField(kWasmMemArrayBuffer,
378 *instance.mem_buffer); 378 *instance.mem_buffer);
379 LoadDataSegments(this, instance.mem_start, instance.mem_size); 379 LoadDataSegments(this, instance.mem_start, instance.mem_size);
380 380
381 if (mem_export) {
382 // Export the memory as a named property.
383 Handle<String> name = factory->InternalizeUtf8String("memory");
384 JSObject::AddProperty(instance.js_object, name, instance.mem_buffer,
385 READ_ONLY);
386 }
387
388 //------------------------------------------------------------------------- 381 //-------------------------------------------------------------------------
389 // Allocate the globals area if necessary. 382 // Allocate the globals area if necessary.
390 //------------------------------------------------------------------------- 383 //-------------------------------------------------------------------------
391 if (!AllocateGlobals(&thrower, isolate, &instance)) { 384 if (!AllocateGlobals(&thrower, isolate, &instance)) {
392 return MaybeHandle<JSObject>(); 385 return MaybeHandle<JSObject>();
393 } 386 }
394 if (!instance.globals_buffer.is_null()) { 387 if (!instance.globals_buffer.is_null()) {
395 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, 388 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer,
396 *instance.globals_buffer); 389 *instance.globals_buffer);
397 } 390 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 464 }
472 465
473 // Second pass: patch all direct call sites. 466 // Second pass: patch all direct call sites.
474 linker.Link(instance.function_table, this->function_table); 467 linker.Link(instance.function_table, this->function_table);
475 instance.js_object->SetInternalField(kWasmModuleFunctionTable, 468 instance.js_object->SetInternalField(kWasmModuleFunctionTable,
476 Smi::FromInt(0)); 469 Smi::FromInt(0));
477 470
478 //------------------------------------------------------------------------- 471 //-------------------------------------------------------------------------
479 // Create and populate the exports object. 472 // Create and populate the exports object.
480 //------------------------------------------------------------------------- 473 //-------------------------------------------------------------------------
481 if (export_table.size() > 0) { 474 if (export_table.size() > 0 || mem_export) {
482 index = 0; 475 index = 0;
483 // Create the "exports" object. 476 // Create the "exports" object.
484 Handle<JSFunction> object_function = Handle<JSFunction>( 477 Handle<JSFunction> object_function = Handle<JSFunction>(
485 isolate->native_context()->object_function(), isolate); 478 isolate->native_context()->object_function(), isolate);
486 Handle<JSObject> exports_object = 479 Handle<JSObject> exports_object =
487 factory->NewJSObject(object_function, TENURED); 480 factory->NewJSObject(object_function, TENURED);
488 Handle<String> exports_name = factory->InternalizeUtf8String("exports"); 481 Handle<String> exports_name = factory->InternalizeUtf8String("exports");
489 JSObject::AddProperty(instance.js_object, exports_name, exports_object, 482 JSObject::AddProperty(instance.js_object, exports_name, exports_object,
490 READ_ONLY); 483 READ_ONLY);
491 484
492 // Compile wrappers and add them to the exports object. 485 // Compile wrappers and add them to the exports object.
493 for (const WasmExport& exp : export_table) { 486 for (const WasmExport& exp : export_table) {
494 if (thrower.error()) break; 487 if (thrower.error()) break;
495 const char* cstr = GetName(exp.name_offset); 488 const char* cstr = GetName(exp.name_offset);
496 Handle<String> name = factory->InternalizeUtf8String(cstr); 489 Handle<String> name = factory->InternalizeUtf8String(cstr);
497 Handle<Code> code = linker.GetFunctionCode(exp.func_index); 490 Handle<Code> code = linker.GetFunctionCode(exp.func_index);
498 Handle<JSFunction> function = compiler::CompileJSToWasmWrapper( 491 Handle<JSFunction> function = compiler::CompileJSToWasmWrapper(
499 isolate, &module_env, name, code, instance.js_object, exp.func_index); 492 isolate, &module_env, name, code, instance.js_object, exp.func_index);
500 JSObject::AddProperty(exports_object, name, function, READ_ONLY); 493 JSObject::AddProperty(exports_object, name, function, READ_ONLY);
501 } 494 }
495
496 if (mem_export) {
497 // Export the memory as a named property.
498 Handle<String> name = factory->InternalizeUtf8String("memory");
499 JSObject::AddProperty(exports_object, name, instance.mem_buffer,
500 READ_ONLY);
501 }
502 } 502 }
503 503
504 // Run the start function if one was specified. 504 // Run the start function if one was specified.
505 if (this->start_function_index >= 0) { 505 if (this->start_function_index >= 0) {
506 HandleScope scope(isolate); 506 HandleScope scope(isolate);
507 uint32_t index = static_cast<uint32_t>(this->start_function_index); 507 uint32_t index = static_cast<uint32_t>(this->start_function_index);
508 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); 508 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start");
509 Handle<Code> code = linker.GetFunctionCode(index); 509 Handle<Code> code = linker.GetFunctionCode(index);
510 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( 510 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper(
511 isolate, &module_env, name, code, instance.js_object, index); 511 isolate, &module_env, name, code, instance.js_object, index);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 647 }
648 if (result->IsHeapNumber()) { 648 if (result->IsHeapNumber()) {
649 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 649 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
650 } 650 }
651 thrower.Error("WASM.compileRun() failed: Return value should be number"); 651 thrower.Error("WASM.compileRun() failed: Return value should be number");
652 return -1; 652 return -1;
653 } 653 }
654 } // namespace wasm 654 } // namespace wasm
655 } // namespace internal 655 } // namespace internal
656 } // namespace v8 656 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/wasm/calls.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698