Remove NativeWeakMap

Bug: v8:7016
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I5a509fb91a337eec4a58ab4a13d7104e8ba3ff23
Reviewed-on: https://chromium-review.googlesource.com/760677
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49346}
This commit is contained in:
peterwmwong 2017-11-13 07:47:15 -06:00 committed by Commit Bot
parent 837ce0f9a3
commit 81931e726b
7 changed files with 4 additions and 205 deletions

View File

@ -2087,20 +2087,6 @@ class V8_EXPORT ValueDeserializer {
PrivateData* private_;
};
/**
* A map whose keys are referenced weakly. It is similar to JavaScript WeakMap
* but can be created without entering a v8::Context and hence shouldn't
* escape to JavaScript.
*/
class V8_EXPORT NativeWeakMap : public Data {
public:
static Local<NativeWeakMap> New(Isolate* isolate);
void Set(Local<Value> key, Local<Value> value);
Local<Value> Get(Local<Value> key) const;
bool Has(Local<Value> key);
bool Delete(Local<Value> key);
};
// --- Value ---

View File

@ -3152,101 +3152,6 @@ bool StackFrame::IsConstructor() const {
bool StackFrame::IsWasm() const { return Utils::OpenHandle(this)->is_wasm(); }
// --- N a t i v e W e a k M a p ---
Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
i::JSWeakCollection::Initialize(weakmap, isolate);
return Utils::NativeWeakMapToLocal(weakmap);
}
void NativeWeakMap::Set(Local<Value> v8_key, Local<Value> v8_value) {
i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this);
i::Isolate* isolate = weak_collection->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::HandleScope scope(isolate);
i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
i::Handle<i::Object> value = Utils::OpenHandle(*v8_value);
if (!key->IsJSReceiver() && !key->IsSymbol()) {
DCHECK(false);
return;
}
i::Handle<i::ObjectHashTable> table(
i::ObjectHashTable::cast(weak_collection->table()));
if (!table->IsKey(isolate, *key)) {
DCHECK(false);
return;
}
int32_t hash = key->GetOrCreateHash(isolate)->value();
i::JSWeakCollection::Set(weak_collection, key, value, hash);
}
Local<Value> NativeWeakMap::Get(Local<Value> v8_key) const {
i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this);
i::Isolate* isolate = weak_collection->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
if (!key->IsJSReceiver() && !key->IsSymbol()) {
DCHECK(false);
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
i::Handle<i::ObjectHashTable> table(
i::ObjectHashTable::cast(weak_collection->table()));
if (!table->IsKey(isolate, *key)) {
DCHECK(false);
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
i::Handle<i::Object> lookup(table->Lookup(key), isolate);
if (lookup->IsTheHole(isolate))
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
return Utils::ToLocal(lookup);
}
bool NativeWeakMap::Has(Local<Value> v8_key) {
i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this);
i::Isolate* isolate = weak_collection->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::HandleScope scope(isolate);
i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
if (!key->IsJSReceiver() && !key->IsSymbol()) {
DCHECK(false);
return false;
}
i::Handle<i::ObjectHashTable> table(
i::ObjectHashTable::cast(weak_collection->table()));
if (!table->IsKey(isolate, *key)) {
DCHECK(false);
return false;
}
i::Handle<i::Object> lookup(table->Lookup(key), isolate);
return !lookup->IsTheHole(isolate);
}
bool NativeWeakMap::Delete(Local<Value> v8_key) {
i::Handle<i::JSWeakMap> weak_collection = Utils::OpenHandle(this);
i::Isolate* isolate = weak_collection->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::HandleScope scope(isolate);
i::Handle<i::Object> key = Utils::OpenHandle(*v8_key);
if (!key->IsJSReceiver() && !key->IsSymbol()) {
DCHECK(false);
return false;
}
i::Handle<i::ObjectHashTable> table(
i::ObjectHashTable::cast(weak_collection->table()));
if (!table->IsKey(isolate, *key)) {
DCHECK(false);
return false;
}
int32_t hash = key->GetOrCreateHash(isolate)->value();
return i::JSWeakCollection::Delete(weak_collection, key, hash);
}
// --- J S O N ---

View File

@ -108,7 +108,6 @@ class RegisteredExtension {
V(StackTrace, FixedArray) \
V(StackFrame, StackFrameInfo) \
V(Proxy, JSProxy) \
V(NativeWeakMap, JSWeakMap) \
V(debug::GeneratorObject, JSGeneratorObject) \
V(debug::Script, Script) \
V(Promise, JSPromise) \
@ -208,8 +207,6 @@ class Utils {
v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj);
static inline Local<External> ExternalToLocal(
v8::internal::Handle<v8::internal::JSObject> obj);
static inline Local<NativeWeakMap> NativeWeakMapToLocal(
v8::internal::Handle<v8::internal::JSWeakMap> obj);
static inline Local<Function> CallableToLocal(
v8::internal::Handle<v8::internal::JSReceiver> obj);
static inline Local<Primitive> ToLocalPrimitive(
@ -332,7 +329,6 @@ MAKE_TO_LOCAL(NumberToLocal, Object, Number)
MAKE_TO_LOCAL(IntegerToLocal, Object, Integer)
MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)
MAKE_TO_LOCAL(ExternalToLocal, JSObject, External)
MAKE_TO_LOCAL(NativeWeakMapToLocal, JSWeakMap, NativeWeakMap)
MAKE_TO_LOCAL(CallableToLocal, JSReceiver, Function)
MAKE_TO_LOCAL(ToLocalPrimitive, Object, Primitive)
MAKE_TO_LOCAL(ToLocal, FixedArray, PrimitiveArray)

View File

@ -2828,15 +2828,6 @@ Handle<JSObject> Factory::NewArgumentsObject(Handle<JSFunction> callee,
return result;
}
Handle<JSWeakMap> Factory::NewJSWeakMap() {
// TODO(adamk): Currently the map is only created three times per
// isolate. If it's created more often, the map should be moved into the
// strong root list.
Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map));
}
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context,
int number_of_properties) {
DCHECK(native_context->IsNativeContext());

View File

@ -495,8 +495,6 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<BigInt> NewBigIntFromSafeInteger(
double value, PretenureFlag pretenure = NOT_TENURED);
Handle<JSWeakMap> NewJSWeakMap();
Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
// JS objects are pretenured when allocated by the bootstrapper and

View File

@ -4868,86 +4868,6 @@ TEST(MessageHandler5) {
}
TEST(NativeWeakMap) {
v8::Isolate* isolate = CcTest::isolate();
HandleScope scope(isolate);
Local<v8::NativeWeakMap> weak_map(v8::NativeWeakMap::New(isolate));
CHECK(!weak_map.IsEmpty());
LocalContext env;
Local<Object> value = v8::Object::New(isolate);
Local<Object> local1 = v8::Object::New(isolate);
CHECK(!weak_map->Has(local1));
CHECK(weak_map->Get(local1)->IsUndefined());
weak_map->Set(local1, value);
CHECK(weak_map->Has(local1));
CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
WeakCallCounter counter(1234);
WeakCallCounterAndPersistent<Value> o1(&counter);
WeakCallCounterAndPersistent<Value> o2(&counter);
WeakCallCounterAndPersistent<Value> s1(&counter);
{
HandleScope scope(isolate);
Local<v8::Object> obj1 = v8::Object::New(isolate);
Local<v8::Object> obj2 = v8::Object::New(isolate);
Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
weak_map->Set(obj1, value);
weak_map->Set(obj2, value);
weak_map->Set(sym1, value);
o1.handle.Reset(isolate, obj1);
o2.handle.Reset(isolate, obj2);
s1.handle.Reset(isolate, sym1);
CHECK(weak_map->Has(local1));
CHECK(weak_map->Has(obj1));
CHECK(weak_map->Has(obj2));
CHECK(weak_map->Has(sym1));
CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
CHECK(value->Equals(env.local(), weak_map->Get(obj1)).FromJust());
CHECK(value->Equals(env.local(), weak_map->Get(obj2)).FromJust());
CHECK(value->Equals(env.local(), weak_map->Get(sym1)).FromJust());
}
CcTest::CollectAllGarbage();
{
HandleScope scope(isolate);
CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
CHECK(value->Equals(env.local(),
weak_map->Get(Local<Value>::New(isolate, o1.handle)))
.FromJust());
CHECK(value->Equals(env.local(),
weak_map->Get(Local<Value>::New(isolate, o2.handle)))
.FromJust());
CHECK(value->Equals(env.local(),
weak_map->Get(Local<Value>::New(isolate, s1.handle)))
.FromJust());
}
o1.handle.SetWeak(&o1, &WeakPointerCallback,
v8::WeakCallbackType::kParameter);
o2.handle.SetWeak(&o2, &WeakPointerCallback,
v8::WeakCallbackType::kParameter);
s1.handle.SetWeak(&s1, &WeakPointerCallback,
v8::WeakCallbackType::kParameter);
CcTest::CollectAllGarbage();
CHECK_EQ(3, counter.NumberOfWeakCalls());
CHECK(o1.handle.IsEmpty());
CHECK(o2.handle.IsEmpty());
CHECK(s1.handle.IsEmpty());
CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
CHECK(weak_map->Delete(local1));
CHECK(!weak_map->Has(local1));
CHECK(weak_map->Get(local1)->IsUndefined());
}
THREADED_TEST(GetSetProperty) {
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();

View File

@ -44,7 +44,10 @@ static Isolate* GetIsolateFrom(LocalContext* context) {
static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) {
Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
Handle<Map> map =
isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
Handle<JSObject> weakmap_obj = isolate->factory()->NewJSObjectFromMap(map);
Handle<JSWeakMap> weakmap(JSWeakMap::cast(*weakmap_obj));
// Do not leak handles for the hash table, it would make entries strong.
{
HandleScope scope(isolate);