| OLD | NEW |
| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 return; | 418 return; |
| 419 } | 419 } |
| 420 if (has_maximum.FromJust()) { | 420 if (has_maximum.FromJust()) { |
| 421 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, | 421 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, |
| 422 &maximum, initial, max_table_size)) { | 422 &maximum, initial, max_table_size)) { |
| 423 return; | 423 return; |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 427 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 428 i::Handle<i::JSFunction> table_ctor( | 428 i::Handle<i::FixedArray> fixed_array; |
| 429 i_isolate->native_context()->wasm_table_constructor()); | 429 i::Handle<i::JSObject> table_obj = i::WasmJs::CreateWasmTableObject( |
| 430 i::Handle<i::JSObject> table_obj = | 430 i_isolate, initial, has_maximum.FromJust(), maximum, &fixed_array); |
| 431 i_isolate->factory()->NewJSObject(table_ctor); | |
| 432 i::Handle<i::FixedArray> fixed_array = | |
| 433 i_isolate->factory()->NewFixedArray(initial); | |
| 434 i::Object* null = i_isolate->heap()->null_value(); | |
| 435 for (int i = 0; i < initial; ++i) fixed_array->set(i, null); | |
| 436 table_obj->SetInternalField(kWasmTableArrayFieldIndex, *fixed_array); | |
| 437 table_obj->SetInternalField( | |
| 438 kWasmTableMaximumFieldIndex, | |
| 439 has_maximum.FromJust() | |
| 440 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) | |
| 441 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); | |
| 442 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym()); | |
| 443 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check(); | |
| 444 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 431 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| 445 return_value.Set(Utils::ToLocal(table_obj)); | 432 return_value.Set(Utils::ToLocal(table_obj)); |
| 446 } | 433 } |
| 447 | 434 |
| 448 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { | 435 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 449 v8::Isolate* isolate = args.GetIsolate(); | 436 v8::Isolate* isolate = args.GetIsolate(); |
| 450 HandleScope scope(isolate); | 437 HandleScope scope(isolate); |
| 451 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), | 438 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), |
| 452 "WebAssembly.Module()"); | 439 "WebAssembly.Module()"); |
| 453 if (args.Length() < 1 || !args[0]->IsObject()) { | 440 if (args.Length() < 1 || !args[0]->IsObject()) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 kWasmMemoryMaximum, | 701 kWasmMemoryMaximum, |
| 715 has_maximum | 702 has_maximum |
| 716 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) | 703 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) |
| 717 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); | 704 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); |
| 718 i::Handle<i::Symbol> memory_sym( | 705 i::Handle<i::Symbol> memory_sym( |
| 719 i_isolate->native_context()->wasm_memory_sym()); | 706 i_isolate->native_context()->wasm_memory_sym()); |
| 720 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check(); | 707 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check(); |
| 721 return memory_obj; | 708 return memory_obj; |
| 722 } | 709 } |
| 723 | 710 |
| 711 i::Handle<i::JSObject> i::WasmJs::CreateWasmTableObject( |
| 712 i::Isolate* i_isolate, uint32_t initial, bool has_maximum, uint32_t maximum, |
| 713 i::Handle<i::FixedArray>* array) { |
| 714 i::Handle<i::JSFunction> table_ctor( |
| 715 i_isolate->native_context()->wasm_table_constructor()); |
| 716 i::Handle<i::JSObject> table_obj = |
| 717 i_isolate->factory()->NewJSObject(table_ctor); |
| 718 *array = i_isolate->factory()->NewFixedArray(initial); |
| 719 i::Object* null = i_isolate->heap()->null_value(); |
| 720 // TODO(titzer): consider moving FixedArray to size_t. |
| 721 for (int i = 0; i < static_cast<int>(initial); ++i) (*array)->set(i, null); |
| 722 table_obj->SetInternalField(kWasmTableArrayFieldIndex, *(*array)); |
| 723 table_obj->SetInternalField( |
| 724 kWasmTableMaximumFieldIndex, |
| 725 has_maximum |
| 726 ? static_cast<i::Object*>(i::Smi::FromInt(maximum)) |
| 727 : static_cast<i::Object*>(i_isolate->heap()->undefined_value())); |
| 728 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym()); |
| 729 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check(); |
| 730 return table_obj; |
| 731 } |
| 732 |
| 724 // TODO(titzer): we use the API to create the function template because the | 733 // TODO(titzer): we use the API to create the function template because the |
| 725 // internal guts are too ugly to replicate here. | 734 // internal guts are too ugly to replicate here. |
| 726 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, | 735 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, |
| 727 FunctionCallback func) { | 736 FunctionCallback func) { |
| 728 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 737 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
| 729 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); | 738 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); |
| 730 return v8::Utils::OpenHandle(*local); | 739 return v8::Utils::OpenHandle(*local); |
| 731 } | 740 } |
| 732 | 741 |
| 733 namespace internal { | 742 namespace internal { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 if (!memory_object->IsUndefined(isolate)) { | 987 if (!memory_object->IsUndefined(isolate)) { |
| 979 DCHECK(IsWasmMemoryObject(isolate, memory_object)); | 988 DCHECK(IsWasmMemoryObject(isolate, memory_object)); |
| 980 // TODO(gdeepti): This should be a weak list of instance objects | 989 // TODO(gdeepti): This should be a weak list of instance objects |
| 981 // for instances that share memory. | 990 // for instances that share memory. |
| 982 JSObject::cast(*memory_object) | 991 JSObject::cast(*memory_object) |
| 983 ->SetInternalField(kWasmMemoryInstanceObject, *instance); | 992 ->SetInternalField(kWasmMemoryInstanceObject, *instance); |
| 984 } | 993 } |
| 985 } | 994 } |
| 986 } // namespace internal | 995 } // namespace internal |
| 987 } // namespace v8 | 996 } // namespace v8 |
| OLD | NEW |