Add GetIdentityHash to v8::Name object API
v8::Object already has GetIdentityHash on it. This change adds its counterpart to v8::Name. BUG=chromium:437416 LOG=Y Review URL: https://codereview.chromium.org/753373003 Cr-Commit-Position: refs/heads/master@{#25598}
This commit is contained in:
parent
d9c83f6bd0
commit
f434123a16
@ -1822,6 +1822,15 @@ class V8_EXPORT Boolean : public Primitive {
|
||||
*/
|
||||
class V8_EXPORT Name : public Primitive {
|
||||
public:
|
||||
/**
|
||||
* Returns the identity hash for this object. The current implementation
|
||||
* uses an inline property on the object to store the identity hash.
|
||||
*
|
||||
* The return value will never be 0. Also, it is not guaranteed to be
|
||||
* unique.
|
||||
*/
|
||||
int GetIdentityHash();
|
||||
|
||||
V8_INLINE static Name* Cast(v8::Value* obj);
|
||||
private:
|
||||
static void CheckCast(v8::Value* obj);
|
||||
|
10
src/api.cc
10
src/api.cc
@ -4231,6 +4231,16 @@ Local<v8::Value> Function::GetBoundFunction() const {
|
||||
}
|
||||
|
||||
|
||||
int Name::GetIdentityHash() {
|
||||
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
||||
ON_BAILOUT(isolate, "v8::Name::GetIdentityHash()", return 0);
|
||||
ENTER_V8(isolate);
|
||||
i::HandleScope scope(isolate);
|
||||
i::Handle<i::Name> self = Utils::OpenHandle(this);
|
||||
return static_cast<int>(self->Hash());
|
||||
}
|
||||
|
||||
|
||||
int String::Length() const {
|
||||
i::Handle<i::String> str = Utils::OpenHandle(this);
|
||||
return str->length();
|
||||
|
@ -3033,6 +3033,53 @@ THREADED_TEST(GlobalProxyIdentityHash) {
|
||||
}
|
||||
|
||||
|
||||
TEST(SymbolIdentityHash) {
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
{
|
||||
Local<v8::Symbol> symbol = v8::Symbol::New(isolate);
|
||||
int hash = symbol->GetIdentityHash();
|
||||
int hash1 = symbol->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash1);
|
||||
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
int hash3 = symbol->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash3);
|
||||
}
|
||||
|
||||
{
|
||||
v8::Handle<v8::Symbol> js_symbol =
|
||||
CompileRun("Symbol('foo')").As<v8::Symbol>();
|
||||
int hash = js_symbol->GetIdentityHash();
|
||||
int hash1 = js_symbol->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash1);
|
||||
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
int hash3 = js_symbol->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(StringIdentityHash) {
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
Local<v8::String> str = v8::String::NewFromUtf8(isolate, "str1");
|
||||
int hash = str->GetIdentityHash();
|
||||
int hash1 = str->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash1);
|
||||
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
int hash3 = str->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash3);
|
||||
|
||||
Local<v8::String> str2 = v8::String::NewFromUtf8(isolate, "str1");
|
||||
int hash4 = str2->GetIdentityHash();
|
||||
CHECK_EQ(hash, hash4);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SymbolProperties) {
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
|
Loading…
Reference in New Issue
Block a user