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 | 6 |
7 #include "src/wasm/module-decoder.h" | 7 #include "src/wasm/module-decoder.h" |
8 #include "src/wasm/wasm-module.h" | 8 #include "src/wasm/wasm-module.h" |
9 #include "src/wasm/wasm-text.h" | 9 #include "src/wasm/wasm-text.h" |
10 | 10 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 | 201 |
202 WasmMemoryObject* WasmMemoryObject::cast(Object* object) { | 202 WasmMemoryObject* WasmMemoryObject::cast(Object* object) { |
203 DCHECK(object && object->IsJSObject()); | 203 DCHECK(object && object->IsJSObject()); |
204 // TODO(titzer): brand check for WasmMemoryObject. | 204 // TODO(titzer): brand check for WasmMemoryObject. |
205 return reinterpret_cast<WasmMemoryObject*>(object); | 205 return reinterpret_cast<WasmMemoryObject*>(object); |
206 } | 206 } |
207 | 207 |
208 void WasmMemoryObject::AddInstance(Isolate* isolate, | 208 void WasmMemoryObject::AddInstance(Isolate* isolate, |
209 Handle<WasmInstanceObject> instance) { | 209 Handle<WasmInstanceObject> instance) { |
210 Handle<WasmInstanceWrapper> instance_wrapper; | 210 Handle<WasmInstanceWrapper> instance_wrapper = |
| 211 handle(instance->get_instance_wrapper()); |
211 if (has_instances_link()) { | 212 if (has_instances_link()) { |
212 Handle<WasmInstanceWrapper> current_wrapper(get_instances_link()); | 213 Handle<WasmInstanceWrapper> current_wrapper(get_instances_link()); |
213 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*current_wrapper)); | 214 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*current_wrapper)); |
214 DCHECK(!current_wrapper->has_previous()); | 215 DCHECK(!current_wrapper->has_previous()); |
215 instance_wrapper = WasmInstanceWrapper::New(isolate, instance); | |
216 instance_wrapper->set_next_wrapper(*current_wrapper); | 216 instance_wrapper->set_next_wrapper(*current_wrapper); |
217 current_wrapper->set_previous_wrapper(*instance_wrapper); | 217 current_wrapper->set_previous_wrapper(*instance_wrapper); |
218 } else { | |
219 instance_wrapper = WasmInstanceWrapper::New(isolate, instance); | |
220 } | 218 } |
221 set_instances_link(*instance_wrapper); | 219 set_instances_link(*instance_wrapper); |
222 instance->set_instance_wrapper(*instance_wrapper); | |
223 } | 220 } |
224 | 221 |
225 void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) { | 222 void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) { |
226 Handle<Object> undefined = isolate->factory()->undefined_value(); | 223 Handle<Object> undefined = isolate->factory()->undefined_value(); |
227 SetInternalField(kInstancesLink, *undefined); | 224 SetInternalField(kInstancesLink, *undefined); |
228 } | 225 } |
229 | 226 |
230 DEFINE_ACCESSORS(WasmInstanceObject, compiled_module, kCompiledModule, | 227 DEFINE_ACCESSORS(WasmInstanceObject, compiled_module, kCompiledModule, |
231 WasmCompiledModule) | 228 WasmCompiledModule) |
232 DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, globals_buffer, | 229 DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, globals_buffer, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { | 277 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { |
281 Handle<Map> map = isolate->factory()->NewMap( | 278 Handle<Map> map = isolate->factory()->NewMap( |
282 JS_OBJECT_TYPE, JSObject::kHeaderSize + kFieldCount * kPointerSize); | 279 JS_OBJECT_TYPE, JSObject::kHeaderSize + kFieldCount * kPointerSize); |
283 Handle<WasmInstanceObject> instance( | 280 Handle<WasmInstanceObject> instance( |
284 reinterpret_cast<WasmInstanceObject*>( | 281 reinterpret_cast<WasmInstanceObject*>( |
285 *isolate->factory()->NewJSObjectFromMap(map, TENURED)), | 282 *isolate->factory()->NewJSObjectFromMap(map, TENURED)), |
286 isolate); | 283 isolate); |
287 | 284 |
288 instance->SetInternalField(kCompiledModule, *compiled_module); | 285 instance->SetInternalField(kCompiledModule, *compiled_module); |
289 instance->SetInternalField(kMemoryObject, isolate->heap()->undefined_value()); | 286 instance->SetInternalField(kMemoryObject, isolate->heap()->undefined_value()); |
| 287 Handle<WasmInstanceWrapper> instance_wrapper = |
| 288 WasmInstanceWrapper::New(isolate, instance); |
| 289 instance->SetInternalField(kWasmMemInstanceWrapper, *instance_wrapper); |
290 return instance; | 290 return instance; |
291 } | 291 } |
292 | 292 |
293 WasmInstanceObject* WasmExportedFunction::instance() { | 293 WasmInstanceObject* WasmExportedFunction::instance() { |
294 return WasmInstanceObject::cast(GetInternalField(kInstance)); | 294 return WasmInstanceObject::cast(GetInternalField(kInstance)); |
295 } | 295 } |
296 | 296 |
297 int WasmExportedFunction::function_index() { | 297 int WasmExportedFunction::function_index() { |
298 return SafeInt32(GetInternalField(kIndex)); | 298 return SafeInt32(GetInternalField(kIndex)); |
299 } | 299 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 584 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
585 return false; | 585 return false; |
586 return true; | 586 return true; |
587 } | 587 } |
588 | 588 |
589 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, | 589 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, |
590 Isolate* isolate) { | 590 Isolate* isolate) { |
591 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); | 591 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); |
592 set(kWrapperInstanceObject, *cell); | 592 set(kWrapperInstanceObject, *cell); |
593 } | 593 } |
OLD | NEW |