Commit 902fd0fe authored by apavlov@chromium.org's avatar apavlov@chromium.org

Revert of Ensure DOMWrapperWorld always exists in all webkit_unit_tests...

Revert of Ensure DOMWrapperWorld always exists in all webkit_unit_tests (https://codereview.chromium.org/180743013/)

Reason for revert:
A few inspector tests are crashing:
WebCore::DOMWrapperWorld::ensureIsolatedWorld(int, int) [DOMWrapperWorld.cpp : 124 + 0x33]

Original issue's description:
> Ensure DOMWrapperWorld always exists in all webkit_unit_tests
> 
> Currently DOMWrapperWorld can be 0 in some tests. This is problematic since I want to make DOMWrapperWorld::current() callable from anywhere. Thus this CL adds DOMWrapperWorld to all webkit_unit_tests.
> 
> - It's verbose to initialize v8::HandleScope, v8::Context, v8::Context::Scope, V8PerContextData and DOMWrapperWorld in each test. So this CL adds a helper class (V8BindingTestScope) that does all the initialization work.
> 
> - This CL also fixes indentation of V8Binding.h.
> 
> BUG=341032
> NOTRY=true
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=168355

TBR=jochen@chromium.org,dcarney@chromium.org,haraken@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=341032

Review URL: https://codereview.chromium.org/183803017

git-svn-id: svn://svn.chromium.org/blink/trunk@168369 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ba25a49a
......@@ -115,7 +115,7 @@ DOMWrapperWorld::~DOMWrapperWorld()
#ifndef NDEBUG
static bool isIsolatedWorldId(int worldId)
{
return MainWorldId < worldId && worldId <= EmbedderWorldIdLimit;
return worldId != MainWorldId && worldId != WorkerWorldId;
}
#endif
......
......@@ -51,13 +51,12 @@ enum WorldIdConstants {
EmbedderWorldIdLimit = (1 << 29),
ScriptPreprocessorIsolatedWorldId,
WorkerWorldId,
TestingWorldId,
};
// This class represent a collection of DOM wrappers for a specific world.
class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGroup = -1);
static PassRefPtr<DOMWrapperWorld> create(int worldId, int extensionGroup);
static const int mainWorldExtensionGroup = 0;
static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int extensionGroup);
......@@ -97,7 +96,7 @@ public:
bool isMainWorld() const { return m_worldId == MainWorldId; }
bool isWorkerWorld() const { return m_worldId == WorkerWorldId; }
bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId <= EmbedderWorldIdLimit; }
bool isIsolatedWorld() const { return !isMainWorld() && !isWorkerWorld(); }
int worldId() const { return m_worldId; }
int extensionGroup() const { return m_extensionGroup; }
......
......@@ -93,11 +93,14 @@ void checkKeyPathNumberValue(const ScriptValue& value, const String& keyPath, in
class IDBKeyFromValueAndKeyPathTest : public testing::Test {
public:
IDBKeyFromValueAndKeyPathTest()
: m_scope(V8BindingTestScope::create(v8::Isolate::GetCurrent()))
: m_handleScope(v8::Isolate::GetCurrent())
, m_scope(v8::Context::New(v8::Isolate::GetCurrent()))
{
}
private:
OwnPtr<V8BindingTestScope> m_scope;
v8::HandleScope m_handleScope;
v8::Context::Scope m_scope;
};
TEST_F(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue)
......
......@@ -47,12 +47,16 @@ class ScriptPromiseResolverTest : public testing::Test {
public:
ScriptPromiseResolverTest()
: m_isolate(v8::Isolate::GetCurrent())
, m_handleScope(m_isolate)
, m_context(m_isolate, v8::Context::New(m_isolate))
, m_contextScope(m_context.newLocal(m_isolate))
{
}
void SetUp()
{
m_scope = V8BindingTestScope::create(m_isolate);
// FIXME: Create a new world and pass it to V8PerContextData.
m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate), 0);
m_promise = ScriptPromise::createPending();
m_resolver = ScriptPromiseResolver::create(m_promise);
}
......@@ -61,7 +65,7 @@ public:
{
m_resolver = nullptr;
m_promise.clear();
m_scope.clear();
m_perContextData.clear();
}
V8PromiseCustom::PromiseState state()
......@@ -82,10 +86,12 @@ public:
protected:
v8::Isolate* m_isolate;
v8::HandleScope m_handleScope;
ScopedPersistent<v8::Context> m_context;
v8::Context::Scope m_contextScope;
RefPtr<ScriptPromiseResolver> m_resolver;
ScriptPromise m_promise;
private:
OwnPtr<V8BindingTestScope> m_scope;
OwnPtr<V8PerContextData> m_perContextData;
};
TEST_F(ScriptPromiseResolverTest, initialState)
......
......@@ -47,17 +47,21 @@ class ScriptPromiseTest : public testing::Test {
public:
ScriptPromiseTest()
: m_isolate(v8::Isolate::GetCurrent())
, m_handleScope(m_isolate)
, m_context(m_isolate, v8::Context::New(m_isolate))
, m_contextScope(m_context.newLocal(m_isolate))
{
}
void SetUp()
{
m_scope = V8BindingTestScope::create(m_isolate);
// FIXME: Create a new world and pass it to V8PerContextData.
m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate), 0);
}
void TearDown()
{
m_scope.clear();
m_perContextData.clear();
}
V8PromiseCustom::PromiseState state(ScriptPromise promise)
......@@ -67,9 +71,10 @@ public:
protected:
v8::Isolate* m_isolate;
private:
OwnPtr<V8BindingTestScope> m_scope;
v8::HandleScope m_handleScope;
ScopedPersistent<v8::Context> m_context;
v8::Context::Scope m_contextScope;
OwnPtr<V8PerContextData> m_perContextData;
};
TEST_F(ScriptPromiseTest, castPromise)
......
......@@ -734,18 +734,4 @@ v8::Isolate* toIsolate(LocalFrame* frame)
return frame->script().isolate();
}
PassOwnPtr<V8BindingTestScope> V8BindingTestScope::create(v8::Isolate* isolate)
{
return adoptPtr(new V8BindingTestScope(isolate));
}
V8BindingTestScope::V8BindingTestScope(v8::Isolate* isolate)
: m_handleScope(isolate)
, m_context(v8::Context::New(isolate))
, m_contextScope(m_context)
, m_world(DOMWrapperWorld::create())
, m_perContextData(V8PerContextData::create(m_context, m_world.get()))
{
}
} // namespace WebCore
......@@ -68,7 +68,7 @@ WorkerScriptController::WorkerScriptController(WorkerGlobalScope& workerGlobalSc
V8Initializer::initializeWorker(m_isolate);
v8::V8::Initialize();
V8PerIsolateData::ensureInitialized(m_isolate);
m_world = DOMWrapperWorld::create(WorkerWorldId);
m_world = DOMWrapperWorld::create(WorkerWorldId, -1);
m_interruptor = adoptPtr(new V8IsolateInterruptor(m_isolate));
ThreadState::current()->addInterruptor(m_interruptor.get());
}
......
......@@ -36,11 +36,18 @@ protected:
class AnimationAnimationV8Test : public AnimationAnimationTest {
protected:
AnimationAnimationV8Test()
: m_isolate(v8::Isolate::GetCurrent())
, m_scope(V8BindingTestScope::create(m_isolate))
: isolate(v8::Isolate::GetCurrent())
, scope(isolate)
, context(v8::Context::New(isolate))
, contextScope(context)
{
}
v8::Isolate* isolate;
v8::HandleScope scope;
v8::Local<v8::Context> context;
v8::Context::Scope contextScope;
PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, Dictionary timingInput)
{
return Animation::createUnsafe(element, keyframeDictionaryVector, timingInput);
......@@ -55,18 +62,13 @@ protected:
{
return Animation::createUnsafe(element, keyframeDictionaryVector);
}
v8::Isolate* m_isolate;
private:
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation)
{
Vector<Dictionary> jsKeyframes;
v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate);
v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate);
v8::Handle<v8::Object> keyframe1 = v8::Object::New(isolate);
v8::Handle<v8::Object> keyframe2 = v8::Object::New(isolate);
setV8ObjectPropertyAsString(keyframe1, "width", "100px");
setV8ObjectPropertyAsString(keyframe1, "offset", "0");
......@@ -75,8 +77,8 @@ TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation)
setV8ObjectPropertyAsString(keyframe2, "offset", "1");
setV8ObjectPropertyAsString(keyframe2, "easing", "cubic-bezier(1, 1, 0.3, 0.3)");
jsKeyframes.append(Dictionary(keyframe1, m_isolate));
jsKeyframes.append(Dictionary(keyframe2, m_isolate));
jsKeyframes.append(Dictionary(keyframe1, isolate));
jsKeyframes.append(Dictionary(keyframe2, isolate));
String value1;
ASSERT_TRUE(jsKeyframes[0].get("width", value1));
......@@ -140,7 +142,7 @@ TEST_F(AnimationAnimationV8Test, SpecifiedGetters)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
setV8ObjectPropertyAsNumber(timingInput, "delay", 2);
setV8ObjectPropertyAsNumber(timingInput, "endDelay", 0.5);
setV8ObjectPropertyAsString(timingInput, "fill", "backwards");
......@@ -149,7 +151,7 @@ TEST_F(AnimationAnimationV8Test, SpecifiedGetters)
setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2);
setV8ObjectPropertyAsString(timingInput, "direction", "reverse");
setV8ObjectPropertyAsString(timingInput, "easing", "step-start");
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, timingInputDictionary);
......@@ -168,9 +170,9 @@ TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(m_isolate);
v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(isolate);
setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5);
Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputWithDuration), m_isolate);
Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputWithDuration), isolate);
RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsKeyframes, timingInputDictionaryWithDuration);
......@@ -186,8 +188,8 @@ TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
EXPECT_EQ("", stringDuration);
v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(m_isolate);
Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputNoDuration), m_isolate);
v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(isolate);
Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputNoDuration), isolate);
RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKeyframes, timingInputDictionaryNoDuration);
......@@ -206,8 +208,8 @@ TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
TEST_F(AnimationAnimationV8Test, SpecifiedSetters)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, timingInputDictionary);
RefPtr<TimedItemTiming> specified = animation->specified();
......@@ -248,8 +250,8 @@ TEST_F(AnimationAnimationV8Test, SpecifiedSetters)
TEST_F(AnimationAnimationV8Test, SetSpecifiedDuration)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, timingInputDictionary);
RefPtr<TimedItemTiming> specified = animation->specified();
......
......@@ -17,11 +17,18 @@ namespace WebCore {
class AnimationAnimationTimingInputTest : public ::testing::Test {
protected:
AnimationAnimationTimingInputTest()
: m_isolate(v8::Isolate::GetCurrent())
, m_scope(V8BindingTestScope::create(m_isolate))
: isolate(v8::Isolate::GetCurrent())
, scope(isolate)
, context(v8::Context::New(isolate))
, contextScope(context)
{
}
v8::Isolate* isolate;
v8::HandleScope scope;
v8::Local<v8::Context> context;
v8::Context::Scope contextScope;
void populateTiming(Timing& timing, Dictionary timingInputDictionary)
{
Animation::populateTiming(timing, timingInputDictionary);
......@@ -29,9 +36,9 @@ protected:
Timing applyTimingInputNumber(String timingProperty, double timingPropertyValue)
{
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
setV8ObjectPropertyAsNumber(timingInput, timingProperty, timingPropertyValue);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
Timing timing;
populateTiming(timing, timingInputDictionary);
return timing;
......@@ -39,18 +46,13 @@ protected:
Timing applyTimingInputString(String timingProperty, String timingPropertyValue)
{
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
setV8ObjectPropertyAsString(timingInput, timingProperty, timingPropertyValue);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
Timing timing;
populateTiming(timing, timingInputDictionary);
return timing;
}
v8::Isolate* m_isolate;
private:
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(AnimationAnimationTimingInputTest, TimingInputStartDelay)
......@@ -175,8 +177,8 @@ TEST_F(AnimationAnimationTimingInputTest, TimingInputEmpty)
Timing updatedTiming;
Timing controlTiming;
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
populateTiming(updatedTiming, timingInputDictionary);
EXPECT_EQ(controlTiming.startDelay, updatedTiming.startDelay);
......
......@@ -72,7 +72,8 @@ NullExecutionContext::NullExecutionContext()
class IDBRequestTest : public testing::Test {
public:
IDBRequestTest()
: m_scope(V8BindingTestScope::create(v8::Isolate::GetCurrent()))
: m_handleScope(v8::Isolate::GetCurrent())
, m_scope(v8::Context::New(v8::Isolate::GetCurrent()))
, m_context(adoptRef(new NullExecutionContext()))
{
}
......@@ -83,7 +84,8 @@ public:
}
private:
OwnPtr<V8BindingTestScope> m_scope;
v8::HandleScope m_handleScope;
v8::Context::Scope m_scope;
RefPtr<ExecutionContext> m_context;
};
......
......@@ -50,7 +50,8 @@ namespace {
class IDBTransactionTest : public testing::Test {
public:
IDBTransactionTest()
: m_scope(V8BindingTestScope::create(v8::Isolate::GetCurrent()))
: m_handleScope(v8::Isolate::GetCurrent())
, m_scope(v8::Context::New(v8::Isolate::GetCurrent()))
, m_document(Document::create())
{
}
......@@ -61,7 +62,8 @@ public:
}
private:
OwnPtr<V8BindingTestScope> m_scope;
v8::HandleScope m_handleScope;
v8::Context::Scope m_scope;
RefPtr<Document> m_document;
};
......
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