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

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

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test failures and TSAN races. 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-macro-gen.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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 153 }
154 154
155 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 155 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
156 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { 156 if (args.Length() > 2 && args[2]->IsArrayBuffer()) {
157 Local<Object> obj = Local<Object>::Cast(args[2]); 157 Local<Object> obj = Local<Object>::Cast(args[2]);
158 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 158 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
159 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); 159 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj));
160 } 160 }
161 161
162 object = i::wasm::WasmModule::Instantiate( 162 object = i::wasm::WasmModule::Instantiate(
163 isolate, module_object.ToHandleChecked(), ffi, memory); 163 isolate, thrower, module_object.ToHandleChecked(), ffi, memory);
164 if (!object.is_null()) { 164 if (!object.is_null()) {
165 args.GetReturnValue().Set(v8::Utils::ToLocal(object.ToHandleChecked())); 165 args.GetReturnValue().Set(v8::Utils::ToLocal(object.ToHandleChecked()));
166 } 166 }
167 } 167 }
168 return object; 168 return object;
169 } 169 }
170 170
171 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) { 171 void InstantiateModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
172 HandleScope scope(args.GetIsolate()); 172 HandleScope scope(args.GetIsolate());
173 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 173 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 Local<Object> obj = Local<Object>::Cast(args[1]); 289 Local<Object> obj = Local<Object>::Cast(args[1]);
290 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); 290 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj));
291 } 291 }
292 292
293 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 293 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
294 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { 294 if (args.Length() > 2 && args[2]->IsArrayBuffer()) {
295 Local<Object> obj = Local<Object>::Cast(args[2]); 295 Local<Object> obj = Local<Object>::Cast(args[2]);
296 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 296 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
297 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); 297 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj));
298 } 298 }
299 i::MaybeHandle<i::JSObject> instance = 299 i::MaybeHandle<i::JSObject> instance = i::wasm::WasmModule::Instantiate(
300 i::wasm::WasmModule::Instantiate(i_isolate, module_obj, ffi, memory); 300 i_isolate, &thrower, module_obj, ffi, memory);
301 if (instance.is_null()) { 301 if (instance.is_null()) {
302 thrower.Error("Could not instantiate module"); 302 if (!thrower.error()) thrower.Error("Could not instantiate module");
303 return; 303 return;
304 } 304 }
305 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 305 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
306 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); 306 return_value.Set(Utils::ToLocal(instance.ToHandleChecked()));
307 } 307 }
308 308
309 bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower, 309 bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower,
310 Local<Context> context, Local<v8::Object> object, 310 Local<Context> context, Local<v8::Object> object,
311 Local<String> property, int* result, int lower_bound, 311 Local<String> property, int* result, int lower_bound,
312 int upper_bound) { 312 int upper_bound) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return; 377 return;
378 } 378 }
379 if (has_maximum.FromJust()) { 379 if (has_maximum.FromJust()) {
380 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 380 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
381 &maximum, initial, max_table_size)) { 381 &maximum, initial, max_table_size)) {
382 return; 382 return;
383 } 383 }
384 } 384 }
385 385
386 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 386 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
387 i::Handle<i::JSFunction> table_cons( 387 i::Handle<i::JSFunction> table_ctor(
388 i_isolate->native_context()->wasm_table_constructor()); 388 i_isolate->native_context()->wasm_table_constructor());
389 i::Handle<i::JSObject> table_obj = 389 i::Handle<i::JSObject> table_obj =
390 i_isolate->factory()->NewJSObject(table_cons); 390 i_isolate->factory()->NewJSObject(table_ctor);
391 i::Handle<i::FixedArray> fixed_array = 391 i::Handle<i::FixedArray> fixed_array =
392 i_isolate->factory()->NewFixedArray(initial); 392 i_isolate->factory()->NewFixedArray(initial);
393 i::Object* null = i_isolate->heap()->null_value(); 393 i::Object* null = i_isolate->heap()->null_value();
394 for (int i = 0; i < initial; ++i) fixed_array->set(i, null); 394 for (int i = 0; i < initial; ++i) fixed_array->set(i, null);
395 table_obj->SetInternalField(0, *fixed_array); 395 table_obj->SetInternalField(0, *fixed_array);
396 table_obj->SetInternalField( 396 table_obj->SetInternalField(
397 1, has_maximum.FromJust() 397 1, has_maximum.FromJust()
398 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) 398 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
399 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); 399 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
400 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym()); 400 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym());
401 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check(); 401 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check();
402 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 402 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
403 return_value.Set(Utils::ToLocal(table_obj)); 403 return_value.Set(Utils::ToLocal(table_obj));
404 } 404 }
405
405 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 406 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
406 v8::Isolate* isolate = args.GetIsolate(); 407 v8::Isolate* isolate = args.GetIsolate();
407 HandleScope scope(isolate); 408 HandleScope scope(isolate);
408 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), 409 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
409 "WebAssembly.Module()"); 410 "WebAssembly.Module()");
410 if (args.Length() < 1 || !args[0]->IsObject()) { 411 if (args.Length() < 1 || !args[0]->IsObject()) {
411 thrower.TypeError("Argument 0 must be a table descriptor"); 412 thrower.TypeError("Argument 0 must be a table descriptor");
412 return; 413 return;
413 } 414 }
414 Local<Context> context = isolate->GetCurrentContext(); 415 Local<Context> context = isolate->GetCurrentContext();
(...skipping 13 matching lines...) Expand all
428 // There has been an exception, just return. 429 // There has been an exception, just return.
429 return; 430 return;
430 } 431 }
431 if (has_maximum.FromJust()) { 432 if (has_maximum.FromJust()) {
432 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 433 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
433 &maximum, initial, 65536)) { 434 &maximum, initial, 65536)) {
434 return; 435 return;
435 } 436 }
436 } 437 }
437 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 438 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
438 i::Handle<i::JSFunction> memory_cons(
439 i_isolate->native_context()->wasm_memory_constructor());
440 i::Handle<i::JSObject> memory_obj =
441 i_isolate->factory()->NewJSObject(memory_cons);
442 i::Handle<i::JSArrayBuffer> buffer = 439 i::Handle<i::JSArrayBuffer> buffer =
443 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); 440 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
444 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 441 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
445 static_cast<size_t>(initial); 442 static_cast<size_t>(initial);
446 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); 443 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size);
447 memory_obj->SetInternalField(0, *buffer); 444
448 memory_obj->SetInternalField( 445 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject(
449 1, has_maximum.FromJust() 446 i_isolate, buffer, has_maximum.FromJust(), maximum);
450 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
451 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
452 i::Handle<i::Symbol> memory_sym(
453 i_isolate->native_context()->wasm_memory_sym());
454 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check();
455 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 447 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
456 return_value.Set(Utils::ToLocal(memory_obj)); 448 return_value.Set(Utils::ToLocal(memory_obj));
457 } 449 }
458 void WebAssemblyTableGetLength( 450 void WebAssemblyTableGetLength(
459 const v8::FunctionCallbackInfo<v8::Value>& args) { 451 const v8::FunctionCallbackInfo<v8::Value>& args) {
460 // TODO(rossberg) 452 // TODO(rossberg)
461 } 453 }
462 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 454 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
463 // TODO(rossberg) 455 // TODO(rossberg)
464 } 456 }
(...skipping 19 matching lines...) Expand all
484 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 476 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
485 i::Handle<i::JSObject> receiver = 477 i::Handle<i::JSObject> receiver =
486 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This())); 478 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
487 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate); 479 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate);
488 DCHECK(buffer->IsJSArrayBuffer()); 480 DCHECK(buffer->IsJSArrayBuffer());
489 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 481 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
490 return_value.Set(Utils::ToLocal(buffer)); 482 return_value.Set(Utils::ToLocal(buffer));
491 } 483 }
492 } // namespace 484 } // namespace
493 485
486 i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject(
487 i::Isolate* i_isolate, i::Handle<i::JSArrayBuffer> buffer, bool has_maximum,
488 int maximum) {
489 i::Handle<i::JSFunction> memory_ctor(
490 i_isolate->native_context()->wasm_memory_constructor());
491 i::Handle<i::JSObject> memory_obj =
492 i_isolate->factory()->NewJSObject(memory_ctor);
493 memory_obj->SetInternalField(0, *buffer);
494 memory_obj->SetInternalField(
495 1, has_maximum
496 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
497 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
498 i::Handle<i::Symbol> memory_sym(
499 i_isolate->native_context()->wasm_memory_sym());
500 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check();
501 return memory_obj;
502 }
503
494 // TODO(titzer): we use the API to create the function template because the 504 // TODO(titzer): we use the API to create the function template because the
495 // internal guts are too ugly to replicate here. 505 // internal guts are too ugly to replicate here.
496 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, 506 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate,
497 FunctionCallback func) { 507 FunctionCallback func) {
498 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); 508 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
499 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); 509 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func);
500 return v8::Utils::OpenHandle(*local); 510 return v8::Utils::OpenHandle(*local);
501 } 511 }
502 512
503 namespace internal { 513 namespace internal {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 int unused_property_fields = in_object_properties - pre_allocated; 696 int unused_property_fields = in_object_properties - pre_allocated;
687 Handle<Map> map = Map::CopyInitialMap( 697 Handle<Map> map = Map::CopyInitialMap(
688 prev_map, instance_size, in_object_properties, unused_property_fields); 698 prev_map, instance_size, in_object_properties, unused_property_fields);
689 699
690 context->set_wasm_function_map(*map); 700 context->set_wasm_function_map(*map);
691 } 701 }
692 } 702 }
693 703
694 } // namespace internal 704 } // namespace internal
695 } // namespace v8 705 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698