6d266f0088
Use sparingly! This doesn't add any really new functionality, other than making it more convenient to do this. This will primarily be used to wrap a WasmModule to be referenced from a JSObject that represents an instance. There is one WasmModule C++ object per parsed WasmModule, so this should not be more than a handful or a few dozen in well-behaved programs. R=rossberg@chromium.org,mlippautz@chromium.org BUG= Review-Url: https://codereview.chromium.org/2409173005 Cr-Commit-Position: refs/heads/master@{#40346}
60 lines
1.2 KiB
C++
60 lines
1.2 KiB
C++
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "src/wasm/managed.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
#include "test/common/wasm/test-signatures.h"
|
|
|
|
using namespace v8::base;
|
|
using namespace v8::internal;
|
|
|
|
class DeleteRecorder {
|
|
public:
|
|
explicit DeleteRecorder(bool* deleted) : deleted_(deleted) {
|
|
*deleted_ = false;
|
|
}
|
|
~DeleteRecorder() { *deleted_ = true; }
|
|
|
|
private:
|
|
bool* deleted_;
|
|
};
|
|
|
|
TEST(ManagedCollect) {
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
bool deleted = false;
|
|
DeleteRecorder* d = new DeleteRecorder(&deleted);
|
|
|
|
{
|
|
HandleScope scope(isolate);
|
|
auto handle = Managed<DeleteRecorder>::New(isolate, d);
|
|
USE(handle);
|
|
}
|
|
|
|
CcTest::CollectAllAvailableGarbage();
|
|
|
|
CHECK(deleted);
|
|
}
|
|
|
|
TEST(ManagedCollectNoDelete) {
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
bool deleted = false;
|
|
DeleteRecorder* d = new DeleteRecorder(&deleted);
|
|
|
|
{
|
|
HandleScope scope(isolate);
|
|
auto handle = Managed<DeleteRecorder>::New(isolate, d, false);
|
|
USE(handle);
|
|
}
|
|
|
|
CcTest::CollectAllAvailableGarbage();
|
|
|
|
CHECK(!deleted);
|
|
delete d;
|
|
}
|