From: yurys Date: Tue, 2 Dec 2014 09:13:16 +0000 (-0800) Subject: Add GetIdentityHash to v8::Name object API X-Git-Tag: upstream/4.7.83~5442 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f434123a16e65188d944edba335c3549337b7f6a;p=platform%2Fupstream%2Fv8.git 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} --- diff --git a/include/v8.h b/include/v8.h index ee6b2e8..d4e76f5 100644 --- a/include/v8.h +++ b/include/v8.h @@ -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); diff --git a/src/api.cc b/src/api.cc index 58c08f5..cc0f70b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4231,6 +4231,16 @@ Local 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 self = Utils::OpenHandle(this); + return static_cast(self->Hash()); +} + + int String::Length() const { i::Handle str = Utils::OpenHandle(this); return str->length(); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 0920178..a70cdbb 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -3033,6 +3033,53 @@ THREADED_TEST(GlobalProxyIdentityHash) { } +TEST(SymbolIdentityHash) { + LocalContext env; + v8::Isolate* isolate = env->GetIsolate(); + v8::HandleScope scope(isolate); + + { + Local 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 js_symbol = + CompileRun("Symbol('foo')").As(); + 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 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 str2 = v8::String::NewFromUtf8(isolate, "str1"); + int hash4 = str2->GetIdentityHash(); + CHECK_EQ(hash, hash4); +} + + THREADED_TEST(SymbolProperties) { LocalContext env; v8::Isolate* isolate = env->GetIsolate();