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

Unified Diff: third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp

Issue 2260113002: Lazily install origin trial features on V8 objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase after parent CL landed Created 4 years, 3 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
Index: third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
diff --git a/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp b/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
index 6b6a8c15d57546b7a93686650ac5a7c187a83640..b3ddee390907211132efb59c448555b20f0022e8 100644
--- a/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
+++ b/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
@@ -25,6 +25,7 @@
#include "core/testing/v8/WebCoreTestSupport.h"
+#include "bindings/core/v8/ConditionalFeatures.h"
#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8OriginTrialsTest.h"
@@ -41,7 +42,7 @@ using namespace blink;
namespace WebCoreTestSupport {
namespace {
-blink::InstallOriginTrialsFunction s_originalInstallOriginTrialsFunction = nullptr;
+blink::InstallConditionalFeaturesFunction s_originalInstallConditionalFeaturesFunction = nullptr;
}
v8::Local<v8::Value> createInternalsObject(v8::Local<v8::Context> context)
@@ -58,6 +59,11 @@ v8::Local<v8::Value> createInternalsObject(v8::Local<v8::Context> context)
void injectInternalsObject(v8::Local<v8::Context> context)
{
+ // Set conditional features installation function to |installConditionalFeaturesForTests|
+ if (!s_originalInstallConditionalFeaturesFunction) {
+ s_originalInstallConditionalFeaturesFunction = setInstallConditionalFeaturesFunction(installConditionalFeaturesForTests);
+ }
+
ScriptState* scriptState = ScriptState::from(context);
ScriptState::Scope scope(scriptState);
v8::Local<v8::Object> global = scriptState->context()->Global();
@@ -67,43 +73,18 @@ void injectInternalsObject(v8::Local<v8::Context> context)
global->Set(scriptState->context(), v8AtomicString(scriptState->isolate(), Internals::internalsId), internals).ToChecked();
- // Set origin trials installation function to |installOriginTrialsForTests|
- if (!s_originalInstallOriginTrialsFunction) {
- s_originalInstallOriginTrialsFunction = setInstallOriginTrialsFunction(installOriginTrialsForTests);
- }
-
- // If Origin Trials have been registered before the internals object was ready,
- // then inject them into the context now
- ExecutionContext* executionContext = toExecutionContext(context);
- if (executionContext) {
- OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext);
- if (originTrialContext)
- originTrialContext->initializePendingFeatures();
- }
}
-void installOriginTrialsForTests(ScriptState* scriptState)
+void installConditionalFeaturesForTests(const WrapperTypeInfo* type, const blink::ScriptState* scriptState, v8::Local<v8::Object> prototypeObject, v8::Local<v8::Function> interfaceObject)
{
- (*s_originalInstallOriginTrialsFunction)(scriptState);
+ (*s_originalInstallConditionalFeaturesFunction)(type, scriptState, prototypeObject, interfaceObject);
- v8::Local<v8::Context> context = scriptState->context();
- ExecutionContext* executionContext = toExecutionContext(scriptState->context());
- if (!executionContext->isDocument() && !executionContext->isWorkerGlobalScope())
- return;
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext, OriginTrialContext::DontCreateIfNotExists);
- if (!originTrialContext)
- return;
- ScriptState::Scope scope(scriptState);
- v8::Local<v8::Object> global = context->Global();
- v8::Isolate* isolate = scriptState->isolate();
-
- if (!originTrialContext->featureBindingsInstalled("Frobulate") && originTrialContext->isFeatureEnabled("Frobulate")) {
- v8::Local<v8::String> internalsName = v8::String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>("internals"), v8::NewStringType::kNormal).ToLocalChecked();
- v8::Local<v8::Value> v8Internals = global->Get(context, internalsName).ToLocalChecked();
- if (v8Internals->IsObject()) {
- V8OriginTrialsTest::installOriginTrialsSampleAPI(scriptState);
- originTrialContext->setFeatureBindingsInstalled("Frobulate");
+ if (type == &V8OriginTrialsTest::wrapperTypeInfo) {
+ if (originTrialContext && originTrialContext->isFeatureEnabled("Frobulate")) {
+ V8OriginTrialsTest::installOriginTrialsSampleAPI(scriptState->isolate(), scriptState->world(), v8::Local<v8::Object>(), prototypeObject, interfaceObject);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698