Diff
Modified: trunk/Source/WebCore/ChangeLog (126387 => 126388)
--- trunk/Source/WebCore/ChangeLog 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/ChangeLog 2012-08-23 03:42:54 UTC (rev 126388)
@@ -1,3 +1,33 @@
+2012-08-22 Kentaro Hara <[email protected]>
+
+ [V8] Move evaluate() from V8Proxy to ScriptController
+ https://bugs.webkit.org/show_bug.cgi?id=94768
+
+ Reviewed by Adam Barth.
+
+ To kill V8Proxy, we can move evaluate() from V8Proxy to ScriptController.
+
+ - Renamed evaluate() to compileAndRunScript() to avoid name conflict
+ with existing ScriptController::evaluate().
+
+ - Removed toV8Proxy() from NPV8Object, as it is no longer used.
+
+ No tests. No change in behavior.
+
+ * bindings/v8/NPV8Object.cpp:
+ (_NPN_EvaluateHelper):
+ * bindings/v8/ScheduledAction.cpp:
+ (WebCore::ScheduledAction::execute):
+ * bindings/v8/ScriptController.cpp:
+ (WebCore::ScriptController::compileAndRunScript):
+ (WebCore):
+ (WebCore::ScriptController::evaluate):
+ (WebCore::ScriptController::evaluateInIsolatedWorld):
+ * bindings/v8/ScriptController.h:
+ (ScriptController):
+ * bindings/v8/V8Proxy.cpp:
+ * bindings/v8/V8Proxy.h:
+
2012-08-22 Vineet Chaudhary <[email protected]>
Consider replacing return type of Clipboard::types() from HashSet<String> to Vector<String>.
Modified: trunk/Source/WebCore/bindings/v8/NPV8Object.cpp (126387 => 126388)
--- trunk/Source/WebCore/bindings/v8/NPV8Object.cpp 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/bindings/v8/NPV8Object.cpp 2012-08-23 03:42:54 UTC (rev 126388)
@@ -69,15 +69,6 @@
return ScriptController::mainWorldContext(object->rootObject->frame());
}
-static V8Proxy* toV8Proxy(NPObject* npObject)
-{
- V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject);
- Frame* frame = object->rootObject->frame();
- if (!frame)
- return 0;
- return frame->script()->proxy();
-}
-
static V8NPObjectMap* staticV8NPObjectMap()
{
DEFINE_STATIC_LOCAL(V8NPObjectMap, v8npObjectMap, ());
@@ -335,9 +326,6 @@
if (context.IsEmpty())
return false;
- V8Proxy* proxy = toV8Proxy(npObject);
- ASSERT(proxy);
-
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
@@ -346,10 +334,14 @@
if (!popupsAllowed)
filename = "npscript";
+ V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject);
+ Frame* frame = v8NpObject->rootObject->frame();
+ ASSERT(frame);
+
String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length);
UserGestureIndicator gestureIndicator(popupsAllowed ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
- v8::Local<v8::Value> v8result = proxy->evaluate(ScriptSourceCode(script, KURL(ParsedURLString, filename)), 0);
+ v8::Local<v8::Value> v8result = frame->script()->compileAndRunScript(ScriptSourceCode(script, KURL(ParsedURLString, filename)));
if (v8result.IsEmpty())
return false;
Modified: trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp (126387 => 126388)
--- trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp 2012-08-23 03:42:54 UTC (rev 126388)
@@ -132,7 +132,7 @@
if (!m_function.IsEmpty() && m_function->IsFunction())
script->callFunction(v8::Persistent<v8::Function>::Cast(m_function), v8Context->Global(), m_argc, m_argv);
else
- script->proxy()->evaluate(m_code, 0);
+ script->compileAndRunScript(m_code);
// The 'proxy' may be invalid at this point since JS could have released the owning Frame.
}
Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (126387 => 126388)
--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-08-23 03:42:54 UTC (rev 126388)
@@ -50,6 +50,7 @@
#include "PlatformSupport.h"
#include "ScriptCallStack.h"
#include "ScriptCallStackFactory.h"
+#include "ScriptRunner.h"
#include "ScriptSourceCode.h"
#include "ScriptableDocumentParser.h"
#include "SecurityOrigin.h"
@@ -256,6 +257,73 @@
return ScriptValue(callFunction(function, receiver, argc, argv));
}
+v8::Local<v8::Value> ScriptController::compileAndRunScript(const ScriptSourceCode& source)
+{
+ ASSERT(v8::Context::InContext());
+
+ V8GCController::checkMemoryUsage();
+
+ InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, source.url().isNull() ? String() : source.url().string(), source.startLine());
+
+ v8::Local<v8::Value> result;
+ {
+ // Isolate exceptions that occur when compiling and executing
+ // the code. These exceptions should not interfere with
+ // _javascript_ code we might evaluate from C++ when returning
+ // from here.
+ v8::TryCatch tryCatch;
+ tryCatch.SetVerbose(true);
+
+ // Compile the script.
+ v8::Local<v8::String> code = v8ExternalString(source.source());
+#if PLATFORM(CHROMIUM)
+ TRACE_EVENT_BEGIN0("v8", "v8.compile");
+#endif
+ OwnPtr<v8::ScriptData> scriptData = ScriptSourceCode::precompileScript(code, source.cachedScript());
+
+ // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
+ // 1, whereas v8 starts at 0.
+ v8::Handle<v8::Script> script = ScriptSourceCode::compileScript(code, source.url(), source.startPosition(), scriptData.get());
+#if PLATFORM(CHROMIUM)
+ TRACE_EVENT_END0("v8", "v8.compile");
+ TRACE_EVENT0("v8", "v8.run");
+#endif
+
+ // Keep Frame (and therefore ScriptController) alive.
+ RefPtr<Frame> protect(m_frame);
+ result = ScriptRunner::runCompiledScript(script, m_frame->document());
+ }
+
+ InspectorInstrumentation::didEvaluateScript(cookie);
+
+ return result;
+}
+
+ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode)
+{
+ String sourceURL = sourceCode.url();
+ const String* savedSourceURL = m_sourceURL;
+ m_sourceURL = &sourceURL;
+
+ v8::HandleScope handleScope;
+ v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_frame);
+ if (v8Context.IsEmpty())
+ return ScriptValue();
+
+ v8::Context::Scope scope(v8Context);
+
+ RefPtr<Frame> protect(m_frame);
+
+ v8::Local<v8::Value> object = compileAndRunScript(sourceCode);
+
+ m_sourceURL = savedSourceURL;
+
+ if (object.IsEmpty())
+ return ScriptValue();
+
+ return ScriptValue(object);
+}
+
void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, Vector<ScriptValue>* results)
{
evaluateInIsolatedWorld(worldID, sources, 0, results);
@@ -304,7 +372,7 @@
v8::Local<v8::Array> resultArray = v8::Array::New(sources.size());
for (size_t i = 0; i < sources.size(); ++i) {
- v8::Local<v8::Value> evaluationResult = m_proxy->evaluate(sources[i], 0);
+ v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[i]);
if (evaluationResult.IsEmpty())
evaluationResult = v8::Local<v8::Value>::New(v8::Undefined());
resultArray->Set(i, evaluationResult);
@@ -331,32 +399,6 @@
iter->second->setSecurityOrigin(securityOrigin);
}
-// Evaluate a script file in the environment of this proxy.
-ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode)
-{
- String sourceURL = sourceCode.url();
- const String* savedSourceURL = m_sourceURL;
- m_sourceURL = &sourceURL;
-
- v8::HandleScope handleScope;
- v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_proxy->frame());
- if (v8Context.IsEmpty())
- return ScriptValue();
-
- v8::Context::Scope scope(v8Context);
-
- RefPtr<Frame> protect(m_frame);
-
- v8::Local<v8::Value> object = m_proxy->evaluate(sourceCode, 0);
-
- m_sourceURL = savedSourceURL;
-
- if (object.IsEmpty())
- return ScriptValue();
-
- return ScriptValue(object);
-}
-
TextPosition ScriptController::eventHandlerPosition() const
{
ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
Modified: trunk/Source/WebCore/bindings/v8/ScriptController.h (126387 => 126388)
--- trunk/Source/WebCore/bindings/v8/ScriptController.h 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.h 2012-08-23 03:42:54 UTC (rev 126388)
@@ -88,7 +88,10 @@
// This function must be called from the main thread. It is safe to call it repeatedly.
static void initializeThreading();
- // Evaluate a script file in the environment of this proxy.
+ v8::Local<v8::Value> compileAndRunScript(const ScriptSourceCode&);
+
+ // Evaluate _javascript_ in the main world.
+ // The caller must hold an execution context.
ScriptValue evaluate(const ScriptSourceCode&);
// Evaluate _javascript_ in a new isolated world. The script gets its own
Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.cpp (126387 => 126388)
--- trunk/Source/WebCore/bindings/v8/V8Proxy.cpp 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.cpp 2012-08-23 03:42:54 UTC (rev 126388)
@@ -88,48 +88,6 @@
windowShell()->destroyGlobal();
}
-v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* node)
-{
- ASSERT(v8::Context::InContext());
-
- V8GCController::checkMemoryUsage();
-
- InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, source.url().isNull() ? String() : source.url().string(), source.startLine());
-
- v8::Local<v8::Value> result;
- {
- // Isolate exceptions that occur when compiling and executing
- // the code. These exceptions should not interfere with
- // _javascript_ code we might evaluate from C++ when returning
- // from here.
- v8::TryCatch tryCatch;
- tryCatch.SetVerbose(true);
-
- // Compile the script.
- v8::Local<v8::String> code = v8ExternalString(source.source());
-#if PLATFORM(CHROMIUM)
- TRACE_EVENT_BEGIN0("v8", "v8.compile");
-#endif
- OwnPtr<v8::ScriptData> scriptData = ScriptSourceCode::precompileScript(code, source.cachedScript());
-
- // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
- // 1, whereas v8 starts at 0.
- v8::Handle<v8::Script> script = ScriptSourceCode::compileScript(code, source.url(), source.startPosition(), scriptData.get());
-#if PLATFORM(CHROMIUM)
- TRACE_EVENT_END0("v8", "v8.compile");
- TRACE_EVENT0("v8", "v8.run");
-#endif
-
- // Keep Frame (and therefore ScriptController) alive.
- RefPtr<Frame> protect(frame());
- result = ScriptRunner::runCompiledScript(script, frame()->document());
- }
-
- InspectorInstrumentation::didEvaluateScript(cookie);
-
- return result;
-}
-
V8DOMWindowShell* V8Proxy::windowShell() const
{
return frame()->script()->windowShell();
Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.h (126387 => 126388)
--- trunk/Source/WebCore/bindings/v8/V8Proxy.h 2012-08-23 03:38:52 UTC (rev 126387)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.h 2012-08-23 03:42:54 UTC (rev 126388)
@@ -87,11 +87,6 @@
Frame* frame() const { return m_frame; }
- // Evaluate a script file in the current execution environment.
- // The caller must hold an execution context.
- // If cannot evalute the script, it returns an error.
- v8::Local<v8::Value> evaluate(const ScriptSourceCode&, Node*);
-
// FIXME: This should eventually take DOMWrapperWorld argument!
// FIXME: This method will be soon removed, as all methods that access windowShell()
// will be moved to ScriptController.