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/wasm/wasm-objects.h" | 5 #include "src/wasm/wasm-objects.h" |
6 #include "src/utils.h" | 6 #include "src/utils.h" |
7 | 7 |
8 #include "src/assembler-inl.h" | 8 #include "src/assembler-inl.h" |
9 #include "src/base/iterator.h" | 9 #include "src/base/iterator.h" |
10 #include "src/compiler/wasm-compiler.h" | 10 #include "src/compiler/wasm-compiler.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 #endif // DEBUG | 155 #endif // DEBUG |
156 | 156 |
157 } // namespace | 157 } // namespace |
158 | 158 |
159 Handle<WasmModuleObject> WasmModuleObject::New( | 159 Handle<WasmModuleObject> WasmModuleObject::New( |
160 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { | 160 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { |
161 Handle<JSFunction> module_cons( | 161 Handle<JSFunction> module_cons( |
162 isolate->native_context()->wasm_module_constructor()); | 162 isolate->native_context()->wasm_module_constructor()); |
163 auto module_object = Handle<WasmModuleObject>::cast( | 163 auto module_object = Handle<WasmModuleObject>::cast( |
164 isolate->factory()->NewJSObject(module_cons)); | 164 isolate->factory()->NewJSObject(module_cons)); |
165 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); | |
166 Object::SetProperty(module_object, module_sym, module_object, STRICT).Check(); | |
167 module_object->set_compiled_module(*compiled_module); | 165 module_object->set_compiled_module(*compiled_module); |
168 Handle<WeakCell> link_to_module = | 166 Handle<WeakCell> link_to_module = |
169 isolate->factory()->NewWeakCell(module_object); | 167 isolate->factory()->NewWeakCell(module_object); |
170 compiled_module->set_weak_wasm_module(link_to_module); | 168 compiled_module->set_weak_wasm_module(link_to_module); |
171 return module_object; | 169 return module_object; |
172 } | 170 } |
173 | 171 |
174 Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial, | 172 Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial, |
175 int64_t maximum, | 173 int64_t maximum, |
176 Handle<FixedArray>* js_functions) { | 174 Handle<FixedArray>* js_functions) { |
177 Handle<JSFunction> table_ctor( | 175 Handle<JSFunction> table_ctor( |
178 isolate->native_context()->wasm_table_constructor()); | 176 isolate->native_context()->wasm_table_constructor()); |
179 auto table_obj = Handle<WasmTableObject>::cast( | 177 auto table_obj = Handle<WasmTableObject>::cast( |
180 isolate->factory()->NewJSObject(table_ctor)); | 178 isolate->factory()->NewJSObject(table_ctor)); |
181 | 179 |
182 *js_functions = isolate->factory()->NewFixedArray(initial); | 180 *js_functions = isolate->factory()->NewFixedArray(initial); |
183 Object* null = isolate->heap()->null_value(); | 181 Object* null = isolate->heap()->null_value(); |
184 for (int i = 0; i < static_cast<int>(initial); ++i) { | 182 for (int i = 0; i < static_cast<int>(initial); ++i) { |
185 (*js_functions)->set(i, null); | 183 (*js_functions)->set(i, null); |
186 } | 184 } |
187 table_obj->set_functions(**js_functions); | 185 table_obj->set_functions(**js_functions); |
188 DCHECK_EQ(maximum, static_cast<int>(maximum)); | 186 DCHECK_EQ(maximum, static_cast<int>(maximum)); |
189 table_obj->set_maximum_length(static_cast<int>(maximum)); | 187 table_obj->set_maximum_length(static_cast<int>(maximum)); |
190 | 188 |
191 Handle<FixedArray> dispatch_tables = isolate->factory()->NewFixedArray(0); | 189 Handle<FixedArray> dispatch_tables = isolate->factory()->NewFixedArray(0); |
192 table_obj->set_dispatch_tables(*dispatch_tables); | 190 table_obj->set_dispatch_tables(*dispatch_tables); |
193 Handle<Symbol> table_sym(isolate->native_context()->wasm_table_sym()); | |
194 Object::SetProperty(table_obj, table_sym, table_obj, STRICT).Check(); | |
195 return Handle<WasmTableObject>::cast(table_obj); | 191 return Handle<WasmTableObject>::cast(table_obj); |
196 } | 192 } |
197 | 193 |
198 Handle<FixedArray> WasmTableObject::AddDispatchTable( | 194 Handle<FixedArray> WasmTableObject::AddDispatchTable( |
199 Isolate* isolate, Handle<WasmTableObject> table_obj, | 195 Isolate* isolate, Handle<WasmTableObject> table_obj, |
200 Handle<WasmInstanceObject> instance, int table_index, | 196 Handle<WasmInstanceObject> instance, int table_index, |
201 Handle<FixedArray> function_table, Handle<FixedArray> signature_table) { | 197 Handle<FixedArray> function_table, Handle<FixedArray> signature_table) { |
202 Handle<FixedArray> dispatch_tables(table_obj->dispatch_tables()); | 198 Handle<FixedArray> dispatch_tables(table_obj->dispatch_tables()); |
203 DCHECK_EQ(0, dispatch_tables->length() % 4); | 199 DCHECK_EQ(0, dispatch_tables->length() % 4); |
204 | 200 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 isolate->native_context()->wasm_memory_constructor()); | 316 isolate->native_context()->wasm_memory_constructor()); |
321 auto memory_obj = Handle<WasmMemoryObject>::cast( | 317 auto memory_obj = Handle<WasmMemoryObject>::cast( |
322 isolate->factory()->NewJSObject(memory_ctor, TENURED)); | 318 isolate->factory()->NewJSObject(memory_ctor, TENURED)); |
323 if (buffer.is_null()) { | 319 if (buffer.is_null()) { |
324 const bool enable_guard_regions = EnableGuardRegions(); | 320 const bool enable_guard_regions = EnableGuardRegions(); |
325 buffer = SetupArrayBuffer(isolate, nullptr, 0, nullptr, 0, false, | 321 buffer = SetupArrayBuffer(isolate, nullptr, 0, nullptr, 0, false, |
326 enable_guard_regions); | 322 enable_guard_regions); |
327 } | 323 } |
328 memory_obj->set_array_buffer(*buffer); | 324 memory_obj->set_array_buffer(*buffer); |
329 memory_obj->set_maximum_pages(maximum); | 325 memory_obj->set_maximum_pages(maximum); |
330 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym()); | |
331 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check(); | |
332 return Handle<WasmMemoryObject>::cast(memory_obj); | 326 return Handle<WasmMemoryObject>::cast(memory_obj); |
333 } | 327 } |
334 | 328 |
335 uint32_t WasmMemoryObject::current_pages() { | 329 uint32_t WasmMemoryObject::current_pages() { |
336 uint32_t byte_length; | 330 uint32_t byte_length; |
337 CHECK(array_buffer()->byte_length()->ToUint32(&byte_length)); | 331 CHECK(array_buffer()->byte_length()->ToUint32(&byte_length)); |
338 return byte_length / wasm::WasmModule::kPageSize; | 332 return byte_length / wasm::WasmModule::kPageSize; |
339 } | 333 } |
340 | 334 |
341 void WasmMemoryObject::AddInstance(Isolate* isolate, | 335 void WasmMemoryObject::AddInstance(Isolate* isolate, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 return new_info; | 423 return new_info; |
430 } | 424 } |
431 | 425 |
432 Handle<WasmInstanceObject> WasmInstanceObject::New( | 426 Handle<WasmInstanceObject> WasmInstanceObject::New( |
433 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { | 427 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { |
434 Handle<JSFunction> instance_cons( | 428 Handle<JSFunction> instance_cons( |
435 isolate->native_context()->wasm_instance_constructor()); | 429 isolate->native_context()->wasm_instance_constructor()); |
436 Handle<JSObject> instance_object = | 430 Handle<JSObject> instance_object = |
437 isolate->factory()->NewJSObject(instance_cons, TENURED); | 431 isolate->factory()->NewJSObject(instance_cons, TENURED); |
438 | 432 |
439 Handle<Symbol> instance_sym(isolate->native_context()->wasm_instance_sym()); | |
440 Object::SetProperty(instance_object, instance_sym, instance_object, STRICT) | |
441 .Check(); | |
442 Handle<WasmInstanceObject> instance( | 433 Handle<WasmInstanceObject> instance( |
443 reinterpret_cast<WasmInstanceObject*>(*instance_object), isolate); | 434 reinterpret_cast<WasmInstanceObject*>(*instance_object), isolate); |
444 | 435 |
445 instance->set_compiled_module(*compiled_module); | 436 instance->set_compiled_module(*compiled_module); |
446 Handle<WasmInstanceWrapper> instance_wrapper = | 437 Handle<WasmInstanceWrapper> instance_wrapper = |
447 WasmInstanceWrapper::New(isolate, instance); | 438 WasmInstanceWrapper::New(isolate, instance); |
448 instance->set_instance_wrapper(*instance_wrapper); | 439 instance->set_instance_wrapper(*instance_wrapper); |
449 return instance; | 440 return instance; |
450 } | 441 } |
451 | 442 |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 if (!array->get(kWrapperInstanceObjectIndex)->IsWeakCell()) return false; | 1411 if (!array->get(kWrapperInstanceObjectIndex)->IsWeakCell()) return false; |
1421 Isolate* isolate = array->GetIsolate(); | 1412 Isolate* isolate = array->GetIsolate(); |
1422 if (!array->get(kNextInstanceWrapperIndex)->IsUndefined(isolate) && | 1413 if (!array->get(kNextInstanceWrapperIndex)->IsUndefined(isolate) && |
1423 !array->get(kNextInstanceWrapperIndex)->IsFixedArray()) | 1414 !array->get(kNextInstanceWrapperIndex)->IsFixedArray()) |
1424 return false; | 1415 return false; |
1425 if (!array->get(kPreviousInstanceWrapperIndex)->IsUndefined(isolate) && | 1416 if (!array->get(kPreviousInstanceWrapperIndex)->IsUndefined(isolate) && |
1426 !array->get(kPreviousInstanceWrapperIndex)->IsFixedArray()) | 1417 !array->get(kPreviousInstanceWrapperIndex)->IsFixedArray()) |
1427 return false; | 1418 return false; |
1428 return true; | 1419 return true; |
1429 } | 1420 } |
OLD | NEW |