| 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 21b58cfbd8d30466cb51a28c9159402012daf3a8..bb252aa51034e366610a98b9274e23d6218805c0 100644
|
| --- a/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
|
| +++ b/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
|
| @@ -45,6 +45,10 @@ namespace {
|
|
|
| blink::InstallConditionalFeaturesFunction
|
| s_originalInstallConditionalFeaturesFunction = nullptr;
|
| +blink::InstallConditionalFeaturesIfNeededFunction
|
| + s_originalInstallConditionalFeaturesIfNeededFunction = nullptr;
|
| +blink::GetAffectedTypesForConditionalFeatureFunction
|
| + s_originalGetAffectedTypesForConditionalFeatureFunction = nullptr;
|
|
|
| v8::Local<v8::Value> createInternalsObject(v8::Local<v8::Context> context) {
|
| ScriptState* scriptState = ScriptState::from(context);
|
| @@ -61,13 +65,7 @@ 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);
|
| - }
|
| + registerInstallConditionalFeaturesForTests();
|
|
|
| ScriptState* scriptState = ScriptState::from(context);
|
| ScriptState::Scope scope(scriptState);
|
| @@ -123,4 +121,61 @@ void resetInternalsObject(v8::Local<v8::Context> context) {
|
| InternalSettings::from(*page)->resetToConsistentState();
|
| }
|
|
|
| +bool installConditionalFeaturesIfNeededForTests(
|
| + const WrapperTypeInfo* wrapperTypeInfo,
|
| + const ScriptState* scriptState) {
|
| + (*s_originalInstallConditionalFeaturesIfNeededFunction)(wrapperTypeInfo,
|
| + scriptState);
|
| +
|
| + // Only install features here, if the target type has an existing instance
|
| + V8PerContextData* contextData = scriptState->perContextData();
|
| + if (wrapperTypeInfo == &V8OriginTrialsTest::wrapperTypeInfo) {
|
| + v8::Local<v8::Function> interfaceObject =
|
| + contextData->constructorForTypeFromCache(wrapperTypeInfo);
|
| + if (interfaceObject.IsEmpty()) {
|
| + LOG(INFO) << "No existing instance for type: "
|
| + << wrapperTypeInfo->interfaceName;
|
| + return true;
|
| + }
|
| + LOG(INFO) << "Found existing instance for type: "
|
| + << wrapperTypeInfo->interfaceName;
|
| + v8::Local<v8::Object> prototypeObject =
|
| + contextData->prototypeForType(wrapperTypeInfo);
|
| +
|
| + installConditionalFeaturesForTests(wrapperTypeInfo, scriptState,
|
| + prototypeObject, interfaceObject);
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +void getAffectedTypesForConditionalFeatureFunctionForTests(
|
| + const String& feature,
|
| + HashSet<const WrapperTypeInfo*>* affectedTypes) {
|
| + (*s_originalGetAffectedTypesForConditionalFeatureFunction)(feature,
|
| + affectedTypes);
|
| + if (feature == "Frobulate") {
|
| + affectedTypes->add(&V8OriginTrialsTest::wrapperTypeInfo);
|
| + return;
|
| + }
|
| +}
|
| +
|
| +void registerInstallConditionalFeaturesForTests() {
|
| + if (!s_originalInstallConditionalFeaturesFunction) {
|
| + s_originalInstallConditionalFeaturesFunction =
|
| + setInstallConditionalFeaturesFunction(
|
| + installConditionalFeaturesForTests);
|
| + }
|
| + if (!s_originalInstallConditionalFeaturesIfNeededFunction) {
|
| + s_originalInstallConditionalFeaturesIfNeededFunction =
|
| + setInstallConditionalFeaturesIfNeededFunction(
|
| + &installConditionalFeaturesIfNeededForTests);
|
| + }
|
| + if (!s_originalGetAffectedTypesForConditionalFeatureFunction) {
|
| + s_originalGetAffectedTypesForConditionalFeatureFunction =
|
| + setGetAffectedTypesForConditionalFeatureFunction(
|
| + &getAffectedTypesForConditionalFeatureFunctionForTests);
|
| + }
|
| +}
|
| +
|
| } // namespace WebCoreTestSupport
|
|
|