Refactor Managed construction
Rename Managed::New to Managed::From (since it takes ownership of an existing object), and re-introduce Managed::Allocate, which allocates a new object and stores it in a Managed. R=titzer@chromium.org Change-Id: I20b0750697fbe7d56d3816b19919c31e389278b3 Reviewed-on: https://chromium-review.googlesource.com/645806 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#47794}
This commit is contained in:
parent
e461e1c646
commit
3972183c35
@ -42,7 +42,16 @@ class Managed : public Foreign {
|
||||
return reinterpret_cast<Managed<CppType>*>(obj);
|
||||
}
|
||||
|
||||
static Handle<Managed<CppType>> New(Isolate* isolate, CppType* ptr) {
|
||||
// Allocate a new CppType and wrap it in a Managed.
|
||||
template <typename... Args>
|
||||
static Handle<Managed<CppType>> Allocate(Isolate* isolate, Args&&... args) {
|
||||
CppType* ptr = new CppType(std::forward<Args>(args)...);
|
||||
return From(isolate, ptr);
|
||||
}
|
||||
|
||||
// Create a Managed from an existing CppType*. Takes ownership of the passed
|
||||
// object.
|
||||
static Handle<Managed<CppType>> From(Isolate* isolate, CppType* ptr) {
|
||||
FinalizerWithHandle* finalizer =
|
||||
new FinalizerWithHandle(ptr, &NativeDelete);
|
||||
isolate->RegisterForReleaseAtTeardown(finalizer);
|
||||
|
@ -672,7 +672,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
|
||||
// The {module_wrapper} will take ownership of the {WasmModule} object,
|
||||
// and it will be destroyed when the GC reclaims the wrapper object.
|
||||
Handle<WasmModuleWrapper> module_wrapper =
|
||||
WasmModuleWrapper::New(isolate_, module_.release());
|
||||
WasmModuleWrapper::From(isolate_, module_.release());
|
||||
WasmModule* module = module_wrapper->get();
|
||||
|
||||
// Create the shared module data.
|
||||
@ -2304,7 +2304,7 @@ class AsyncCompileJob::FinishCompile : public CompileStep {
|
||||
|
||||
// The {module_wrapper} will take ownership of the {WasmModule} object,
|
||||
// and it will be destroyed when the GC reclaims the wrapper object.
|
||||
Handle<WasmModuleWrapper> module_wrapper = WasmModuleWrapper::New(
|
||||
Handle<WasmModuleWrapper> module_wrapper = WasmModuleWrapper::From(
|
||||
job_->isolate_, job_->compiler_->ReleaseModule().release());
|
||||
|
||||
// Create the shared module data.
|
||||
|
@ -569,8 +569,8 @@ wasm::InterpreterHandle* GetOrCreateInterpreterHandle(
|
||||
Handle<Object> handle(debug_info->get(WasmDebugInfo::kInterpreterHandleIndex),
|
||||
isolate);
|
||||
if (handle->IsUndefined(isolate)) {
|
||||
auto* cpp_handle = new wasm::InterpreterHandle(isolate, *debug_info);
|
||||
handle = Managed<wasm::InterpreterHandle>::New(isolate, cpp_handle);
|
||||
handle = Managed<wasm::InterpreterHandle>::Allocate(isolate, isolate,
|
||||
*debug_info);
|
||||
debug_info->set(WasmDebugInfo::kInterpreterHandleIndex, *handle);
|
||||
}
|
||||
|
||||
@ -660,11 +660,10 @@ wasm::WasmInterpreter* WasmDebugInfo::SetupForTesting(
|
||||
Handle<WasmInstanceObject> instance_obj) {
|
||||
Handle<WasmDebugInfo> debug_info = WasmDebugInfo::New(instance_obj);
|
||||
Isolate* isolate = instance_obj->GetIsolate();
|
||||
auto* cpp_handle = new wasm::InterpreterHandle(isolate, *debug_info);
|
||||
Handle<Object> handle =
|
||||
Managed<wasm::InterpreterHandle>::New(isolate, cpp_handle);
|
||||
debug_info->set(kInterpreterHandleIndex, *handle);
|
||||
return cpp_handle->interpreter();
|
||||
auto interp_handle =
|
||||
Managed<wasm::InterpreterHandle>::Allocate(isolate, isolate, *debug_info);
|
||||
debug_info->set(kInterpreterHandleIndex, *interp_handle);
|
||||
return interp_handle->get()->interpreter();
|
||||
}
|
||||
|
||||
bool WasmDebugInfo::IsWasmDebugInfo(Object* object) {
|
||||
@ -795,8 +794,7 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry(
|
||||
if (!debug_info->has_c_wasm_entries()) {
|
||||
auto entries = isolate->factory()->NewFixedArray(4, TENURED);
|
||||
debug_info->set_c_wasm_entries(*entries);
|
||||
auto managed_map =
|
||||
Managed<wasm::SignatureMap>::New(isolate, new wasm::SignatureMap());
|
||||
auto managed_map = Managed<wasm::SignatureMap>::Allocate(isolate);
|
||||
debug_info->set_c_wasm_entry_map(*managed_map);
|
||||
}
|
||||
Handle<FixedArray> entries(debug_info->c_wasm_entries(), isolate);
|
||||
|
@ -708,7 +708,7 @@ void WasmSharedModuleData::ReinitializeAfterDeserialization(
|
||||
}
|
||||
|
||||
Handle<wasm::WasmModuleWrapper> module_wrapper =
|
||||
wasm::WasmModuleWrapper::New(isolate, module);
|
||||
wasm::WasmModuleWrapper::From(isolate, module);
|
||||
|
||||
shared->set(kModuleWrapperIndex, *module_wrapper);
|
||||
DCHECK(WasmSharedModuleData::IsWasmSharedModuleData(*shared));
|
||||
@ -838,9 +838,8 @@ void WasmSharedModuleData::PrepareForLazyCompilation(
|
||||
Handle<WasmSharedModuleData> shared) {
|
||||
if (shared->has_lazy_compilation_orchestrator()) return;
|
||||
Isolate* isolate = shared->GetIsolate();
|
||||
auto* orch = new wasm::LazyCompilationOrchestrator();
|
||||
Handle<Managed<wasm::LazyCompilationOrchestrator>> orch_handle =
|
||||
Managed<wasm::LazyCompilationOrchestrator>::New(isolate, orch);
|
||||
auto orch_handle =
|
||||
Managed<wasm::LazyCompilationOrchestrator>::Allocate(isolate);
|
||||
shared->set_lazy_compilation_orchestrator(*orch_handle);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ TEST(ManagedCollect) {
|
||||
isolate->RegisterForReleaseAtTeardown(&finalizer);
|
||||
{
|
||||
HandleScope scope(isolate);
|
||||
auto handle = Managed<DeleteRecorder>::New(isolate, d1);
|
||||
auto handle = Managed<DeleteRecorder>::From(isolate, d1);
|
||||
USE(handle);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ TEST(DisposeCollect) {
|
||||
DeleteRecorder* d2 = new DeleteRecorder(&deleted2);
|
||||
{
|
||||
HandleScope scope(i_isolate);
|
||||
auto handle = Managed<DeleteRecorder>::New(i_isolate, d1);
|
||||
auto handle = Managed<DeleteRecorder>::From(i_isolate, d1);
|
||||
USE(handle);
|
||||
}
|
||||
Isolate::ManagedObjectFinalizer finalizer(d2, DeleteRecorder::Deleter);
|
||||
|
Loading…
Reference in New Issue
Block a user