Commit 91475f95 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[api] Add v8::Object::GetCreationContextChecked

Using v8::Object::GetCreationContext().ToLocalChecked() causes needless
binary size regression on android due to the additional call after
migrating to the non-deprecated GetCreationContext API.

Bug: chromium:1166077, v8:11451, v8:11165
Change-Id: Ic5e2aada4d47392c5d61b419c19b5bcdbf869f0b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3244411
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77563}
parent f2c7d3a8
...@@ -598,6 +598,11 @@ class V8_EXPORT Object : public Value { ...@@ -598,6 +598,11 @@ class V8_EXPORT Object : public Value {
Local<Context> CreationContext(); Local<Context> CreationContext();
MaybeLocal<Context> GetCreationContext(); MaybeLocal<Context> GetCreationContext();
/**
* Shortcut for GetCreationContext().ToLocalChecked().
**/
Local<Context> GetCreationContextChecked();
/** Same as above, but works for Persistents */ /** Same as above, but works for Persistents */
V8_DEPRECATE_SOON( V8_DEPRECATE_SOON(
"Use MaybeLocal<Context> GetCreationContext(const " "Use MaybeLocal<Context> GetCreationContext(const "
......
...@@ -5024,10 +5024,17 @@ MaybeLocal<v8::Context> v8::Object::GetCreationContext() { ...@@ -5024,10 +5024,17 @@ MaybeLocal<v8::Context> v8::Object::GetCreationContext() {
if (self->GetCreationContext().ToHandle(&context)) { if (self->GetCreationContext().ToHandle(&context)) {
return Utils::ToLocal(context); return Utils::ToLocal(context);
} }
return MaybeLocal<v8::Context>(); return MaybeLocal<v8::Context>();
} }
Local<v8::Context> v8::Object::GetCreationContextChecked() {
Local<Context> context;
Utils::ApiCheck(GetCreationContext().ToLocal(&context),
"v8::Object::GetCreationContextChecked",
"No creation context available");
return context;
}
int v8::Object::GetIdentityHash() { int v8::Object::GetIdentityHash() {
i::DisallowGarbageCollection no_gc; i::DisallowGarbageCollection no_gc;
auto self = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
......
...@@ -19265,16 +19265,22 @@ THREADED_TEST(CreationContext) { ...@@ -19265,16 +19265,22 @@ THREADED_TEST(CreationContext) {
Local<Context> other_context = Context::New(isolate); Local<Context> other_context = Context::New(isolate);
Context::Scope scope(other_context); Context::Scope scope(other_context);
CHECK(object1->GetCreationContext().ToLocalChecked() == context1); CHECK(object1->GetCreationContext().ToLocalChecked() == context1);
CHECK(object1->GetCreationContextChecked() == context1);
CheckContextId(object1, 1); CheckContextId(object1, 1);
CHECK(func1->GetCreationContext().ToLocalChecked() == context1); CHECK(func1->GetCreationContext().ToLocalChecked() == context1);
CHECK(func1->GetCreationContextChecked() == context1);
CheckContextId(func1, 1); CheckContextId(func1, 1);
CHECK(instance1->GetCreationContext().ToLocalChecked() == context1); CHECK(instance1->GetCreationContext().ToLocalChecked() == context1);
CHECK(instance1->GetCreationContextChecked() == context1);
CheckContextId(instance1, 1); CheckContextId(instance1, 1);
CHECK(object2->GetCreationContext().ToLocalChecked() == context2); CHECK(object2->GetCreationContext().ToLocalChecked() == context2);
CHECK(object2->GetCreationContextChecked() == context2);
CheckContextId(object2, 2); CheckContextId(object2, 2);
CHECK(func2->GetCreationContext().ToLocalChecked() == context2); CHECK(func2->GetCreationContext().ToLocalChecked() == context2);
CHECK(func2->GetCreationContextChecked() == context2);
CheckContextId(func2, 2); CheckContextId(func2, 2);
CHECK(instance2->GetCreationContext().ToLocalChecked() == context2); CHECK(instance2->GetCreationContext().ToLocalChecked() == context2);
CHECK(instance2->GetCreationContextChecked() == context2);
CheckContextId(instance2, 2); CheckContextId(instance2, 2);
} }
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