[builtins] CSA for WeakSet.p.has.

Change-Id: Ib233e9801d5deed1acde36620d033d19957319d0
Bug: v8:6604
Reviewed-on: https://chromium-review.googlesource.com/573781
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46696}
This commit is contained in:
Jaroslav Sevcik 2017-07-17 10:18:14 +02:00 committed by Commit Bot
parent bba7c07e01
commit 033d44f0a6
6 changed files with 31 additions and 27 deletions

View File

@ -3150,6 +3150,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
// Setup %WeakSetPrototype%.
Handle<JSObject> prototype(JSObject::cast(cons->instance_prototype()));
SimpleInstallFunction(prototype, "has", Builtins::kWeakSetHas, 1, true);
JSObject::AddProperty(
prototype, factory->to_string_tag_symbol(),
factory->NewStringFromAsciiChecked("WeakSet"),

View File

@ -1327,5 +1327,31 @@ TF_BUILTIN(WeakMapHas, CollectionsBuiltinsAssembler) {
Return(FalseConstant());
}
TF_BUILTIN(WeakSetHas, CollectionsBuiltinsAssembler) {
Node* const receiver = Parameter(Descriptor::kReceiver);
Node* const key = Parameter(Descriptor::kKey);
Node* const context = Parameter(Descriptor::kContext);
Label return_false(this);
ThrowIfNotInstanceType(context, receiver, JS_WEAK_SET_TYPE,
"WeakSet.prototype.get");
GotoIf(TaggedIsSmi(key), &return_false);
GotoIfNot(IsJSReceiver(key), &return_false);
Node* const table = LoadObjectField(receiver, JSWeakCollection::kTableOffset);
Node* const index =
CallBuiltin(Builtins::kWeakMapLookupHashIndex, context, table, key);
GotoIf(WordEqual(index, SmiConstant(-1)), &return_false);
Return(TrueConstant());
BIND(&return_false);
Return(FalseConstant());
}
} // namespace internal
} // namespace v8

View File

@ -1038,6 +1038,9 @@ namespace internal {
TFJ(WeakMapGet, 1, kKey) \
TFJ(WeakMapHas, 1, kKey) \
\
/* WeakSet */ \
TFJ(WeakSetHas, 1, kKey) \
\
/* AsyncGenerator */ \
\
TFS(AsyncGeneratorResolve, kGenerator, kValue, kDone) \

View File

@ -112,17 +112,6 @@ DEFINE_METHODS(
return %WeakCollectionSet(this, value, true, GetHash(value));
}
has(value) {
if (!IS_WEAKSET(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,
'WeakSet.prototype.has', this);
}
if (!IS_RECEIVER(value)) return false;
var hash = GetExistingHash(value);
if (IS_UNDEFINED(hash)) return false;
return %WeakCollectionHas(this, value, hash);
}
delete(value) {
if (!IS_WEAKSET(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,

View File

@ -143,21 +143,6 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) {
}
RUNTIME_FUNCTION(Runtime_WeakCollectionHas) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
CONVERT_SMI_ARG_CHECKED(hash, 2)
CHECK(key->IsJSReceiver() || key->IsSymbol());
Handle<ObjectHashTable> table(
ObjectHashTable::cast(weak_collection->table()));
CHECK(table->IsKey(isolate, *key));
Handle<Object> lookup(table->Lookup(key, hash), isolate);
return isolate->heap()->ToBoolean(!lookup->IsTheHole(isolate));
}
RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());

View File

@ -104,7 +104,6 @@ namespace internal {
F(MapIteratorClone, 1, 1) \
F(GetWeakMapEntries, 2, 1) \
F(WeakCollectionInitialize, 1, 1) \
F(WeakCollectionHas, 3, 1) \
F(WeakCollectionDelete, 3, 1) \
F(WeakCollectionSet, 4, 1) \
F(GetWeakSetValues, 2, 1) \