Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: src/api.cc

Issue 1428793002: Reland v8::Private and related APIs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/v8.h ('K') | « include/v8.h ('k') | src/factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index fa16f31481bdc63dc5ed553cbdf63abf6f063746..1d714aff8330225dd2748c6024e06238919f6788 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3606,6 +3606,13 @@ bool v8::Object::ForceSet(v8::Local<Value> key, v8::Local<Value> value,
}
+Maybe<bool> v8::Object::SetPrivate(Local<Context> context, Local<Private> key,
+ Local<Value> value) {
+ return DefineOwnProperty(context, Local<Name>(reinterpret_cast<Name*>(*key)),
+ value, DontEnum);
+}
+
+
MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
Local<Value> key) {
PREPARE_FOR_EXECUTION(context, "v8::Object::Get()", Value);
@@ -3642,6 +3649,12 @@ Local<Value> v8::Object::Get(uint32_t index) {
}
+MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
+ Local<Private> key) {
+ return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
+}
+
+
Maybe<PropertyAttribute> v8::Object::GetPropertyAttributes(
Local<Context> context, Local<Value> key) {
PREPARE_FOR_EXECUTION_PRIMITIVE(
@@ -3878,6 +3891,12 @@ bool v8::Object::Delete(v8::Local<Value> key) {
}
+Maybe<bool> v8::Object::DeletePrivate(Local<Context> context,
+ Local<Private> key) {
+ return Delete(context, Local<Value>(reinterpret_cast<Value*>(*key)));
+}
+
+
Maybe<bool> v8::Object::Has(Local<Context> context, Local<Value> key) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Get()", bool);
auto self = Utils::OpenHandle(this);
@@ -3906,6 +3925,11 @@ bool v8::Object::Has(v8::Local<Value> key) {
}
+Maybe<bool> v8::Object::HasPrivate(Local<Context> context, Local<Private> key) {
+ return HasOwnProperty(context, Local<Name>(reinterpret_cast<Name*>(*key)));
+}
+
+
Maybe<bool> v8::Object::Delete(Local<Context> context, uint32_t index) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DeleteProperty()",
bool);
@@ -4238,13 +4262,16 @@ int v8::Object::GetIdentityHash() {
bool v8::Object::SetHiddenValue(v8::Local<v8::String> key,
v8::Local<v8::Value> value) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- if (value.IsEmpty()) return DeleteHiddenValue(key);
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
i::Handle<i::String> key_string =
isolate->factory()->InternalizeString(key_obj);
+ if (value.IsEmpty()) {
+ i::JSObject::DeleteHiddenProperty(self, key_string);
+ return true;
+ }
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
i::Handle<i::Object> result =
i::JSObject::SetHiddenProperty(self, key_string, value_obj);
@@ -5249,6 +5276,11 @@ Local<Value> Symbol::Name() const {
}
+Local<Value> Private::Name() const {
+ return reinterpret_cast<const Symbol*>(this)->Name();
+}
+
+
double Number::Value() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
return obj->Number();
@@ -6821,7 +6853,8 @@ Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
static i::Handle<i::Symbol> SymbolFor(i::Isolate* isolate,
i::Handle<i::String> name,
- i::Handle<i::String> part) {
+ i::Handle<i::String> part,
+ bool private_symbol) {
i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry();
i::Handle<i::JSObject> symbols =
i::Handle<i::JSObject>::cast(
@@ -6830,7 +6863,10 @@ static i::Handle<i::Symbol> SymbolFor(i::Isolate* isolate,
i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked();
if (!symbol->IsSymbol()) {
DCHECK(symbol->IsUndefined());
- symbol = isolate->factory()->NewSymbol();
+ if (private_symbol)
+ symbol = isolate->factory()->NewPrivateSymbol();
+ else
+ symbol = isolate->factory()->NewSymbol();
i::Handle<i::Symbol>::cast(symbol)->set_name(*name);
i::JSObject::SetProperty(symbols, name, symbol, i::STRICT).Assert();
}
@@ -6842,7 +6878,7 @@ Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::String> i_name = Utils::OpenHandle(*name);
i::Handle<i::String> part = i_isolate->factory()->for_string();
- return Utils::ToLocal(SymbolFor(i_isolate, i_name, part));
+ return Utils::ToLocal(SymbolFor(i_isolate, i_name, part, false));
}
@@ -6850,7 +6886,7 @@ Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::String> i_name = Utils::OpenHandle(*name);
i::Handle<i::String> part = i_isolate->factory()->for_api_string();
- return Utils::ToLocal(SymbolFor(i_isolate, i_name, part));
+ return Utils::ToLocal(SymbolFor(i_isolate, i_name, part, false));
}
@@ -6878,6 +6914,27 @@ Local<Symbol> v8::Symbol::GetIsConcatSpreadable(Isolate* isolate) {
}
+Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ LOG_API(i_isolate, "Private::New()");
+ ENTER_V8(i_isolate);
+ i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
+ if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
+ Local<Symbol> result = Utils::ToLocal(symbol);
+ return v8::Local<Private>(reinterpret_cast<Private*>(*result));
+}
+
+
+Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ i::Handle<i::String> i_name = Utils::OpenHandle(*name);
+ i::Handle<i::String> part = i_isolate->factory()->private_api_string();
+ Local<Symbol> result =
+ Utils::ToLocal(SymbolFor(i_isolate, i_name, part, true));
+ return v8::Local<Private>(reinterpret_cast<Private*>(*result));
+}
+
+
Local<Number> v8::Number::New(Isolate* isolate, double value) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
if (std::isnan(value)) {
« include/v8.h ('K') | « include/v8.h ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698