Commit 3b1a09f5 authored by gsathya's avatar gsathya Committed by Commit bot

[stubs] Add CSA::IsSymbol() and CSA::IsPrivateSymbol().

Review-Url: https://codereview.chromium.org/2571883002
Cr-Commit-Position: refs/heads/master@{#41682}
parent 8ff9efc8
......@@ -2915,6 +2915,22 @@ Node* CodeStubAssembler::IsString(Node* object) {
Int32Constant(FIRST_NONSTRING_TYPE));
}
Node* CodeStubAssembler::IsSymbol(Node* object) {
return IsSymbolMap(LoadMap(object));
}
Node* CodeStubAssembler::IsPrivateSymbol(Node* object) {
return Select(
IsSymbol(object),
[=] {
Node* const flags =
SmiToWord32(LoadObjectField(object, Symbol::kFlagsOffset));
const int kPrivateMask = 1 << Symbol::kPrivateBit;
return IsSetWord32(flags, kPrivateMask);
},
[=] { return Int32Constant(0); }, MachineRepresentation::kWord32);
}
Node* CodeStubAssembler::IsNativeContext(Node* object) {
return WordEqual(LoadMap(object), LoadRoot(Heap::kNativeContextMapRootIndex));
}
......@@ -4271,10 +4287,10 @@ void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
Goto(if_keyisindex);
Bind(&if_keyisnotindex);
Node* key_instance_type = LoadInstanceType(key);
Node* key_map = LoadMap(key);
// Symbols are unique.
GotoIf(Word32Equal(key_instance_type, Int32Constant(SYMBOL_TYPE)),
if_keyisunique);
GotoIf(IsSymbolMap(key_map), if_keyisunique);
Node* key_instance_type = LoadMapInstanceType(key_map);
// Miss if |key| is not a String.
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
GotoUnless(IsStringInstanceType(key_instance_type), if_bailout);
......
......@@ -639,6 +639,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* IsMap(Node* object);
Node* IsCallableMap(Node* map);
Node* IsName(Node* object);
Node* IsSymbol(Node* object);
Node* IsPrivateSymbol(Node* object);
Node* IsJSValue(Node* object);
Node* IsJSArray(Node* object);
Node* IsNativeContext(Node* object);
......
......@@ -2103,5 +2103,52 @@ TEST(AllocatePromiseReactionJobInfo) {
CHECK(promise_info->debug_name()->IsUndefined(isolate));
}
TEST(IsSymbol) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int kNumParams = 1;
CodeAssemblerTester data(isolate, kNumParams);
CodeStubAssembler m(data.state());
Node* const symbol = m.Parameter(0);
m.Return(m.SelectBooleanConstant(m.IsSymbol(symbol)));
Handle<Code> code = data.GenerateCode();
CHECK(!code.is_null());
FunctionTester ft(code, kNumParams);
Handle<Object> result =
ft.Call(isolate->factory()->NewSymbol()).ToHandleChecked();
CHECK_EQ(isolate->heap()->true_value(), *result);
result = ft.Call(isolate->factory()->empty_string()).ToHandleChecked();
CHECK_EQ(isolate->heap()->false_value(), *result);
}
TEST(IsPrivateSymbol) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int kNumParams = 1;
CodeAssemblerTester data(isolate, kNumParams);
CodeStubAssembler m(data.state());
Node* const symbol = m.Parameter(0);
m.Return(m.SelectBooleanConstant(m.IsPrivateSymbol(symbol)));
Handle<Code> code = data.GenerateCode();
CHECK(!code.is_null());
FunctionTester ft(code, kNumParams);
Handle<Object> result =
ft.Call(isolate->factory()->NewSymbol()).ToHandleChecked();
CHECK_EQ(isolate->heap()->false_value(), *result);
result = ft.Call(isolate->factory()->empty_string()).ToHandleChecked();
CHECK_EQ(isolate->heap()->false_value(), *result);
result = ft.Call(isolate->factory()->NewPrivateSymbol()).ToHandleChecked();
CHECK_EQ(isolate->heap()->true_value(), *result);
}
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment