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

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: [wasm] Master CL for Binary 0xC changes. 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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 table_obj->SetInternalField(0, *fixed_array); 399 table_obj->SetInternalField(0, *fixed_array);
400 table_obj->SetInternalField( 400 table_obj->SetInternalField(
401 1, has_maximum 401 1, has_maximum
402 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) 402 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
403 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); 403 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
404 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym()); 404 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym());
405 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check(); 405 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check();
406 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 406 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
407 return_value.Set(Utils::ToLocal(table_obj)); 407 return_value.Set(Utils::ToLocal(table_obj));
408 } 408 }
409
409 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 410 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
410 v8::Isolate* isolate = args.GetIsolate(); 411 v8::Isolate* isolate = args.GetIsolate();
411 HandleScope scope(isolate); 412 HandleScope scope(isolate);
412 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), 413 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
413 "WebAssembly.Module()"); 414 "WebAssembly.Module()");
414 if (args.Length() < 1 || !args[0]->IsObject()) { 415 if (args.Length() < 1 || !args[0]->IsObject()) {
415 thrower.TypeError("Argument 0 must be a table descriptor"); 416 thrower.TypeError("Argument 0 must be a table descriptor");
416 return; 417 return;
417 } 418 }
418 Local<Context> context = isolate->GetCurrentContext(); 419 Local<Context> context = isolate->GetCurrentContext();
(...skipping 10 matching lines...) Expand all
429 65536)) { 430 65536)) {
430 if (reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception() || 431 if (reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception() ||
431 thrower.error()) { 432 thrower.error()) {
432 return; 433 return;
433 } else { 434 } else {
434 // There was no error, the property just does not exist. 435 // There was no error, the property just does not exist.
435 has_maximum = false; 436 has_maximum = false;
436 } 437 }
437 } 438 }
438 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 439 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
439 i::Handle<i::JSFunction> memory_cons(
440 i_isolate->native_context()->wasm_memory_constructor());
441 i::Handle<i::JSObject> memory_obj =
442 i_isolate->factory()->NewJSObject(memory_cons);
443 i::Handle<i::JSArrayBuffer> buffer = 440 i::Handle<i::JSArrayBuffer> buffer =
444 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); 441 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
445 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 442 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
446 static_cast<size_t>(initial); 443 static_cast<size_t>(initial);
447 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); 444 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size);
448 memory_obj->SetInternalField(0, *buffer); 445
449 memory_obj->SetInternalField( 446 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject(
450 1, has_maximum 447 i_isolate, buffer, has_maximum, maximum);
451 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
452 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
453 i::Handle<i::Symbol> memory_sym(
454 i_isolate->native_context()->wasm_memory_sym());
455 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check();
456 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 448 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
457 return_value.Set(Utils::ToLocal(memory_obj)); 449 return_value.Set(Utils::ToLocal(memory_obj));
458 } 450 }
459 void WebAssemblyTableGetLength( 451 void WebAssemblyTableGetLength(
460 const v8::FunctionCallbackInfo<v8::Value>& args) { 452 const v8::FunctionCallbackInfo<v8::Value>& args) {
461 // TODO(rossberg) 453 // TODO(rossberg)
462 } 454 }
463 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 455 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
464 // TODO(rossberg) 456 // TODO(rossberg)
465 } 457 }
(...skipping 19 matching lines...) Expand all
485 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 477 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
486 i::Handle<i::JSObject> receiver = 478 i::Handle<i::JSObject> receiver =
487 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This())); 479 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
488 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate); 480 i::Handle<i::Object> buffer(receiver->GetInternalField(0), i_isolate);
489 DCHECK(buffer->IsJSArrayBuffer()); 481 DCHECK(buffer->IsJSArrayBuffer());
490 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 482 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
491 return_value.Set(Utils::ToLocal(buffer)); 483 return_value.Set(Utils::ToLocal(buffer));
492 } 484 }
493 } // namespace 485 } // namespace
494 486
487 i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject(
488 i::Isolate* i_isolate, i::Handle<i::JSArrayBuffer> buffer, bool has_maximum,
489 int maximum) {
490 i::Handle<i::JSFunction> memory_cons(
bradnelson 2016/09/23 11:36:01 Unfortunate abreviation in a context with s-exprs
titzer 2016/09/23 12:07:30 Changed to _ctor.
491 i_isolate->native_context()->wasm_memory_constructor());
492 i::Handle<i::JSObject> memory_obj =
493 i_isolate->factory()->NewJSObject(memory_cons);
494 memory_obj->SetInternalField(0, *buffer);
495 memory_obj->SetInternalField(
496 1, has_maximum
497 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
498 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
499 i::Handle<i::Symbol> memory_sym(
500 i_isolate->native_context()->wasm_memory_sym());
501 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check();
502 return memory_obj;
503 }
504
495 // TODO(titzer): we use the API to create the function template because the 505 // TODO(titzer): we use the API to create the function template because the
496 // internal guts are too ugly to replicate here. 506 // internal guts are too ugly to replicate here.
497 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, 507 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate,
498 FunctionCallback func) { 508 FunctionCallback func) {
499 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); 509 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
500 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); 510 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func);
501 return v8::Utils::OpenHandle(*local); 511 return v8::Utils::OpenHandle(*local);
502 } 512 }
503 513
504 namespace internal { 514 namespace internal {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 int unused_property_fields = in_object_properties - pre_allocated; 697 int unused_property_fields = in_object_properties - pre_allocated;
688 Handle<Map> map = Map::CopyInitialMap( 698 Handle<Map> map = Map::CopyInitialMap(
689 prev_map, instance_size, in_object_properties, unused_property_fields); 699 prev_map, instance_size, in_object_properties, unused_property_fields);
690 700
691 context->set_wasm_function_map(*map); 701 context->set_wasm_function_map(*map);
692 } 702 }
693 } 703 }
694 704
695 } // namespace internal 705 } // namespace internal
696 } // namespace v8 706 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698