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

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

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: Address review comments Created 4 years, 2 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 | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-module.cc » ('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"
11 #include "src/ast/ast.h" 11 #include "src/ast/ast.h"
12 #include "src/execution.h" 12 #include "src/execution.h"
13 #include "src/factory.h" 13 #include "src/factory.h"
14 #include "src/handles.h" 14 #include "src/handles.h"
15 #include "src/isolate.h" 15 #include "src/isolate.h"
16 #include "src/objects.h" 16 #include "src/objects.h"
17 #include "src/parsing/parse-info.h" 17 #include "src/parsing/parse-info.h"
18 18
19 #include "src/wasm/module-decoder.h" 19 #include "src/wasm/module-decoder.h"
20 #include "src/wasm/wasm-js.h" 20 #include "src/wasm/wasm-js.h"
21 #include "src/wasm/wasm-module.h" 21 #include "src/wasm/wasm-module.h"
22 #include "src/wasm/wasm-result.h" 22 #include "src/wasm/wasm-result.h"
23 23
24 typedef uint8_t byte; 24 typedef uint8_t byte;
25 25
26 using v8::internal::wasm::ErrorThrower; 26 using v8::internal::wasm::ErrorThrower;
27 27
28 namespace v8 { 28 namespace v8 {
29 29
30 static const int kWasmMemoryBufferFieldIndex = 0;
31
30 namespace { 32 namespace {
31 i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) { 33 i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) {
32 return isolate->factory()->NewStringFromAsciiChecked(str); 34 return isolate->factory()->NewStringFromAsciiChecked(str);
33 } 35 }
34 Local<String> v8_str(Isolate* isolate, const char* str) { 36 Local<String> v8_str(Isolate* isolate, const char* str) {
35 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str)); 37 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str));
36 } 38 }
37 39
38 struct RawBuffer { 40 struct RawBuffer {
39 const byte* start; 41 const byte* start;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 Local<Context> context = isolate->GetCurrentContext(); 504 Local<Context> context = isolate->GetCurrentContext();
503 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 505 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
504 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 506 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
505 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), 507 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
506 "Receiver is not a WebAssembly.Memory")) { 508 "Receiver is not a WebAssembly.Memory")) {
507 return; 509 return;
508 } 510 }
509 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 511 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
510 i::Handle<i::JSObject> receiver = 512 i::Handle<i::JSObject> receiver =
511 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This())); 513 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
512 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate); 514 i::Handle<i::Object> buffer(
515 receiver->GetInternalField(kWasmMemoryBufferFieldIndex), i_isolate);
513 DCHECK(buffer->IsJSArrayBuffer()); 516 DCHECK(buffer->IsJSArrayBuffer());
514 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 517 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
515 return_value.Set(Utils::ToLocal(buffer)); 518 return_value.Set(Utils::ToLocal(buffer));
516 } 519 }
517 } // namespace 520 } // namespace
518 521
519 i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject( 522 i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject(
520 i::Isolate* i_isolate, i::Handle<i::JSArrayBuffer> buffer, bool has_maximum, 523 i::Isolate* i_isolate, i::Handle<i::JSArrayBuffer> buffer, bool has_maximum,
521 int maximum) { 524 int maximum) {
522 i::Handle<i::JSFunction> memory_ctor( 525 i::Handle<i::JSFunction> memory_ctor(
523 i_isolate->native_context()->wasm_memory_constructor()); 526 i_isolate->native_context()->wasm_memory_constructor());
524 i::Handle<i::JSObject> memory_obj = 527 i::Handle<i::JSObject> memory_obj =
525 i_isolate->factory()->NewJSObject(memory_ctor); 528 i_isolate->factory()->NewJSObject(memory_ctor);
526 memory_obj->SetInternalField(0, *buffer); 529 memory_obj->SetInternalField(kWasmMemoryBufferFieldIndex, *buffer);
527 memory_obj->SetInternalField( 530 memory_obj->SetInternalField(
528 1, has_maximum 531 1, has_maximum
529 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) 532 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
530 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); 533 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
531 i::Handle<i::Symbol> memory_sym( 534 i::Handle<i::Symbol> memory_sym(
532 i_isolate->native_context()->wasm_memory_sym()); 535 i_isolate->native_context()->wasm_memory_sym());
533 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check(); 536 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check();
534 return memory_obj; 537 return memory_obj;
535 } 538 }
536 539
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 &in_object_properties); 733 &in_object_properties);
731 734
732 int unused_property_fields = in_object_properties - pre_allocated; 735 int unused_property_fields = in_object_properties - pre_allocated;
733 Handle<Map> map = Map::CopyInitialMap( 736 Handle<Map> map = Map::CopyInitialMap(
734 prev_map, instance_size, in_object_properties, unused_property_fields); 737 prev_map, instance_size, in_object_properties, unused_property_fields);
735 738
736 context->set_wasm_function_map(*map); 739 context->set_wasm_function_map(*map);
737 } 740 }
738 } 741 }
739 742
743 bool WasmJs::IsWasmMemoryObject(Isolate* isolate, Handle<Object> value) {
744 if (value->IsJSObject()) {
745 i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value);
746 i::Handle<i::Symbol> sym(isolate->context()->wasm_memory_sym(), isolate);
747 Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym);
748 if (has_brand.IsNothing()) return false;
749 if (has_brand.ToChecked()) return true;
750 }
751 return false;
752 }
753
754 Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate,
755 Handle<Object> value) {
756 DCHECK(IsWasmMemoryObject(isolate, value));
757 Handle<Object> buf(
758 JSObject::cast(*value)->GetInternalField(kWasmMemoryBufferFieldIndex),
759 isolate);
760 return Handle<JSArrayBuffer>::cast(buf);
761 }
740 } // namespace internal 762 } // namespace internal
741 } // namespace v8 763 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698