From 2cfac65eacd308ab83b8750b159d321f380b6cf2 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 21 Apr 2016 02:48:58 -0700 Subject: [PATCH] Allow for creating Private API symbols that have a number as an ID BUG=v8:4933 R=verwaest@chromium.org LOG=n Review URL: https://codereview.chromium.org/1899283003 Cr-Commit-Position: refs/heads/master@{#35692} --- src/api.cc | 2 +- src/objects-inl.h | 11 +++++++++++ src/objects.h | 4 ++++ test/cctest/test-api.cc | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/api.cc b/src/api.cc index 6b6f80f795..17792341ea 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6996,7 +6996,7 @@ static i::Handle SymbolFor(i::Isolate* isolate, else symbol = isolate->factory()->NewSymbol(); i::Handle::cast(symbol)->set_name(*name); - i::JSObject::SetProperty(symbols, name, symbol, i::STRICT).Assert(); + i::Object::SetPropertyOrElement(symbols, name, symbol, i::STRICT).Assert(); } return i::Handle::cast(symbol); } diff --git a/src/objects-inl.h b/src/objects-inl.h index b96d6257c0..095425262a 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -7034,6 +7034,17 @@ MaybeHandle Object::GetPropertyOrElement(Handle object, return GetProperty(&it); } +MaybeHandle Object::SetPropertyOrElement(Handle object, + Handle name, + Handle value, + LanguageMode language_mode, + StoreFromKeyed store_mode) { + LookupIterator it = + LookupIterator::PropertyOrElement(name->GetIsolate(), object, name); + MAYBE_RETURN_NULL(SetProperty(&it, value, language_mode, store_mode)); + return value; +} + MaybeHandle Object::GetPropertyOrElement(Handle receiver, Handle name, Handle holder) { diff --git a/src/objects.h b/src/objects.h index 53b70beb6f..d4590e25fe 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1241,6 +1241,10 @@ class Object { Handle object, Handle name, Handle value, LanguageMode language_mode, StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); + MUST_USE_RESULT static inline MaybeHandle SetPropertyOrElement( + Handle object, Handle name, Handle value, + LanguageMode language_mode, + StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); MUST_USE_RESULT static Maybe SetSuperProperty( LookupIterator* it, Handle value, LanguageMode language_mode, diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 3d7bddda79..86dcb9e954 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -25026,3 +25026,12 @@ TEST(SetIntegrityLevel) { is_frozen = CompileRun("Object.isFrozen(o)"); CHECK(is_frozen->BooleanValue(context.local()).FromJust()); } + +TEST(PrivateForApiIsNumber) { + LocalContext context; + v8::Isolate* isolate = CcTest::isolate(); + v8::HandleScope scope(isolate); + + // Shouldn't crash. + v8::Private::ForApi(isolate, v8_str("42")); +}