Merge from Chromium at DEPS revision r213057
This commit was generated by merge_to_master.py.
Change-Id: If0dbdee1edae80ae428c081eb0ecd6ce3518559f
diff --git a/Source/bindings/v8/BindingSecurity.cpp b/Source/bindings/v8/BindingSecurity.cpp
index 056a256..92f0f10 100644
--- a/Source/bindings/v8/BindingSecurity.cpp
+++ b/Source/bindings/v8/BindingSecurity.cpp
@@ -56,7 +56,7 @@
if (reportingOption == ReportSecurityError) {
if (Frame* frame = targetDocument->frame())
- frame->document()->domWindow()->printErrorMessage(targetDocument->domWindow()->crossDomainAccessErrorMessage(active));
+ frame->domWindow()->printErrorMessage(targetDocument->domWindow()->crossDomainAccessErrorMessage(active));
}
return false;
diff --git a/Source/bindings/v8/CustomElementConstructorBuilder.cpp b/Source/bindings/v8/CustomElementConstructorBuilder.cpp
index 6e4dd40..1ba1e5b 100644
--- a/Source/bindings/v8/CustomElementConstructorBuilder.cpp
+++ b/Source/bindings/v8/CustomElementConstructorBuilder.cpp
@@ -39,6 +39,7 @@
#include "bindings/v8/CustomElementBinding.h"
#include "bindings/v8/DOMWrapperWorld.h"
#include "bindings/v8/Dictionary.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/UnsafePersistent.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8CustomElementLifecycleCallbacks.h"
@@ -297,7 +298,7 @@
}
if (args.Length() > 0) {
- throwTypeError(0, isolate);
+ throwTypeError(isolate);
return;
}
@@ -307,13 +308,11 @@
v8::Handle<v8::Value> maybeType = args.Callee()->GetHiddenValue(V8HiddenPropertyName::customElementType());
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType);
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
- RefPtr<Element> element = document->createElementNS(namespaceURI, tagName, maybeType->IsNull() ? nullAtom : type, ec);
- if (ec) {
- setDOMException(ec, isolate);
+ RefPtr<Element> element = document->createElementNS(namespaceURI, tagName, maybeType->IsNull() ? nullAtom : type, es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Fast(element.release(), args, document));
}
diff --git a/Source/bindings/v8/DOMWrapperWorld.h b/Source/bindings/v8/DOMWrapperWorld.h
index 22128c6..1efedc0 100644
--- a/Source/bindings/v8/DOMWrapperWorld.h
+++ b/Source/bindings/v8/DOMWrapperWorld.h
@@ -45,6 +45,11 @@
class DOMDataStore;
class ScriptExecutionContext;
+enum IsolatedWorldConstants {
+ EmbedderWorldIdLimit = (1 << 29),
+ ScriptPreprocessorIsolatedWorldId
+};
+
// This class represent a collection of DOM wrappers for a specific world.
class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
@@ -88,7 +93,7 @@
bool isolatedWorldHasContentSecurityPolicy();
// Associate a logger with the world identified by worldId (worlId may be 0
- // identifying the main world).
+ // identifying the main world).
static void setActivityLogger(int worldId, PassOwnPtr<V8DOMActivityLogger>);
static V8DOMActivityLogger* activityLogger(int worldId);
diff --git a/Source/bindings/v8/DebuggerScript.js b/Source/bindings/v8/DebuggerScript.js
index f1d5840..ab54b11 100644
--- a/Source/bindings/v8/DebuggerScript.js
+++ b/Source/bindings/v8/DebuggerScript.js
@@ -302,6 +302,49 @@
return numbers;
}
+// Matched enum in V8 objects.h
+DebuggerScript.ScriptCompilationType = {
+ Host: 0,
+ Eval: 1,
+ JSON: 2
+};
+
+DebuggerScript._getScriptCompilationTypeInfo = function(script)
+{
+ var result = "";
+ var fromScript = script.evalFromScript();
+ if (script.compilationType() == DebuggerScript.ScriptCompilationType.Eval && fromScript) {
+ result += 'eval from ';
+ if (fromScript.compilationType() == DebuggerScript.ScriptCompilationType.Eval) {
+ result += DebuggerScript._getScriptCompilationTypeInfo(fromScript);
+ } else {
+ var name = fromScript.name();
+ if (name) {
+ var location = script.evalFromLocation();
+ result += name + (location ? ':' + (location.line + 1) + ':' + (location.column + 1) : '');
+ } else {
+ result += '(unknown source)';
+ }
+ }
+ return result;
+ } else if (script.compilationType() == Debug.ScriptCompilationType.JSON) {
+ result += 'JSON ';
+ } else { // script.compilation == Debug.ScriptCompilationType.Host
+ result += '[unnamed] ';
+ }
+ return result || 'Failed to extract info';
+}
+
+DebuggerScript.getScriptCompilationTypeInfo = function(eventData)
+{
+ try {
+ var script = eventData.script();
+ return DebuggerScript._getScriptCompilationTypeInfo(script);
+ } catch (exc) {
+ return exc + '';
+ }
+}
+
DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame)
{
// Get function name.
@@ -324,7 +367,6 @@
// Get this object.
var thisObject = frameMirror.details_.receiver();
- // Get scope chain array in format: [<scope type>, <scope object>, <scope type>, <scope object>,...]
var scopeChain = [];
var scopeType = [];
for (var i = 0; i < frameMirror.scopeCount(); i++) {
@@ -348,6 +390,28 @@
return DebuggerScript._setScopeVariableValue(frameMirror, scopeNumber, variableName, newValue);
}
+ function stepInPositions()
+ {
+ var stepInPositionsV8 = frameMirror.stepInPositions();
+ var stepInPositionsProtocol;
+ if (stepInPositionsV8) {
+ stepInPositionsProtocol = [];
+ var script = frameMirror.func().script();
+ if (script) {
+ var scriptId = String(script.id());
+ for (var i = 0; i < stepInPositionsV8.length; i++) {
+ var item = {
+ scriptId: scriptId,
+ lineNumber: stepInPositionsV8[i].position.line,
+ columnNumber: stepInPositionsV8[i].position.column
+ };
+ stepInPositionsProtocol.push(item);
+ }
+ }
+ }
+ return JSON.stringify(stepInPositionsProtocol);
+ }
+
return {
"sourceID": sourceID,
"line": location ? location.line : 0,
@@ -359,7 +423,8 @@
"evaluate": evaluate,
"caller": callerFrame,
"restart": restart,
- "setVariableValue": setVariableValue
+ "setVariableValue": setVariableValue,
+ "stepInPositions": stepInPositions
};
}
diff --git a/Source/bindings/v8/ExceptionState.cpp b/Source/bindings/v8/ExceptionState.cpp
index 1fdb4f8..26ea567 100644
--- a/Source/bindings/v8/ExceptionState.cpp
+++ b/Source/bindings/v8/ExceptionState.cpp
@@ -42,7 +42,7 @@
m_exception.clear();
}
-void ExceptionState::throwDOMException(const ExceptionCode& ec, const char* message)
+void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& message)
{
ASSERT(ec);
m_code = ec;
@@ -59,7 +59,7 @@
m_exception.set(m_isolate, exception);
}
-void ExceptionState::throwTypeError(const char* message)
+void ExceptionState::throwTypeError(const String& message)
{
m_code = TypeError;
setException(V8ThrowException::createTypeError(message, m_isolate));
@@ -68,12 +68,12 @@
NonThrowExceptionState::NonThrowExceptionState()
: ExceptionState(0) { }
-void NonThrowExceptionState::throwDOMException(const ExceptionCode& ec, const char*)
+void NonThrowExceptionState::throwDOMException(const ExceptionCode& ec, const String&)
{
m_code = ec;
}
-void NonThrowExceptionState::throwTypeError(const char*)
+void NonThrowExceptionState::throwTypeError(const String&)
{
m_code = TypeError;
}
diff --git a/Source/bindings/v8/ExceptionState.h b/Source/bindings/v8/ExceptionState.h
index 98a77a3..c0bbd48 100644
--- a/Source/bindings/v8/ExceptionState.h
+++ b/Source/bindings/v8/ExceptionState.h
@@ -34,6 +34,7 @@
#include "bindings/v8/ScopedPersistent.h"
#include "bindings/v8/V8ThrowException.h"
#include "wtf/Noncopyable.h"
+#include "wtf/text/WTFString.h"
#include <v8.h>
namespace WebCore {
@@ -47,8 +48,8 @@
: m_code(0)
, m_isolate(isolate) { }
- virtual void throwDOMException(const ExceptionCode&, const char* message = 0);
- virtual void throwTypeError(const char* message = 0);
+ virtual void throwDOMException(const ExceptionCode&, const String& message = String());
+ virtual void throwTypeError(const String& message = String());
bool hadException() const { return !m_exception.isEmpty() || m_code; }
void clearException();
@@ -61,7 +62,7 @@
throwDOMException(m_code);
}
- V8ThrowException::throwError(m_exception.deprecatedGet());
+ V8ThrowException::throwError(m_exception.newLocal(m_isolate));
return true;
}
@@ -93,8 +94,8 @@
class NonThrowExceptionState : public ExceptionState {
public:
NonThrowExceptionState();
- virtual void throwDOMException(const ExceptionCode&, const char* = 0) OVERRIDE FINAL;
- virtual void throwTypeError(const char* = 0) OVERRIDE FINAL;
+ virtual void throwDOMException(const ExceptionCode&, const String& message = String()) OVERRIDE FINAL;
+ virtual void throwTypeError(const String& message = String()) OVERRIDE FINAL;
};
} // namespace WebCore
diff --git a/Source/bindings/v8/ExceptionStatePlaceholder.cpp b/Source/bindings/v8/ExceptionStatePlaceholder.cpp
index 352ba00..3c14826 100644
--- a/Source/bindings/v8/ExceptionStatePlaceholder.cpp
+++ b/Source/bindings/v8/ExceptionStatePlaceholder.cpp
@@ -40,12 +40,12 @@
, m_file(file)
, m_line(line) { }
-void NoExceptionStateAssertionChecker::throwDOMException(const ExceptionCode&, const char*)
+void NoExceptionStateAssertionChecker::throwDOMException(const ExceptionCode&, const String&)
{
ASSERT_AT(false, m_file, m_line, "");
}
-void NoExceptionStateAssertionChecker::throwTypeError(const char*)
+void NoExceptionStateAssertionChecker::throwTypeError(const String&)
{
ASSERT_AT(false, m_file, m_line, "");
}
diff --git a/Source/bindings/v8/ExceptionStatePlaceholder.h b/Source/bindings/v8/ExceptionStatePlaceholder.h
index 8a94c53..67206af 100644
--- a/Source/bindings/v8/ExceptionStatePlaceholder.h
+++ b/Source/bindings/v8/ExceptionStatePlaceholder.h
@@ -33,6 +33,7 @@
#include "bindings/v8/ExceptionState.h"
#include "wtf/Assertions.h"
+#include "wtf/text/WTFString.h"
namespace WebCore {
@@ -42,8 +43,8 @@
public:
IgnorableExceptionState(): ExceptionState(0) { }
ExceptionState& returnThis() { return *this; }
- virtual void throwDOMException(const ExceptionCode&, const char* message = 0) OVERRIDE FINAL { };
- virtual void throwTypeError(const char* message = 0) OVERRIDE FINAL { }
+ virtual void throwDOMException(const ExceptionCode&, const String& message = String()) OVERRIDE FINAL { };
+ virtual void throwTypeError(const String& message = String()) OVERRIDE FINAL { }
};
#define IGNORE_EXCEPTION_STATE (::WebCore::IgnorableExceptionState().returnThis())
@@ -58,8 +59,8 @@
public:
NoExceptionStateAssertionChecker(const char* file, int line);
ExceptionState& returnThis() { return *this; }
- virtual void throwDOMException(const ExceptionCode&, const char* message = 0) OVERRIDE FINAL;
- virtual void throwTypeError(const char* message = 0) OVERRIDE FINAL;
+ virtual void throwDOMException(const ExceptionCode&, const String& message = String()) OVERRIDE FINAL;
+ virtual void throwTypeError(const String& message = String()) OVERRIDE FINAL;
private:
const char* m_file;
diff --git a/Source/bindings/v8/PageScriptDebugServer.cpp b/Source/bindings/v8/PageScriptDebugServer.cpp
index 671567a..d1d2185 100644
--- a/Source/bindings/v8/PageScriptDebugServer.cpp
+++ b/Source/bindings/v8/PageScriptDebugServer.cpp
@@ -64,6 +64,14 @@
return toFrameIfNotDetached(context);
}
+ScriptController* PageScriptDebugServer::scriptController(v8::Handle<v8::Context> context)
+{
+ Frame* frame = retrieveFrameWithGlobalObjectCheck(context);
+ if (frame)
+ return frame->script();
+ return 0;
+}
+
PageScriptDebugServer& PageScriptDebugServer::shared()
{
DEFINE_STATIC_LOCAL(PageScriptDebugServer, server, ());
@@ -182,7 +190,7 @@
// The listener may have been removed in the nested loop.
if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedPage))
listener->didContinue();
-
+
m_pausedPage = 0;
}
diff --git a/Source/bindings/v8/PageScriptDebugServer.h b/Source/bindings/v8/PageScriptDebugServer.h
index 96a98a1..ab37474 100644
--- a/Source/bindings/v8/PageScriptDebugServer.h
+++ b/Source/bindings/v8/PageScriptDebugServer.h
@@ -38,6 +38,7 @@
namespace WebCore {
class Page;
+class ScriptController;
class PageScriptDebugServer : public ScriptDebugServer {
WTF_MAKE_NONCOPYABLE(PageScriptDebugServer);
@@ -58,11 +59,12 @@
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage);
virtual void clearCompiledScripts();
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage);
+ virtual ScriptController* scriptController(v8::Handle<v8::Context>);
private:
PageScriptDebugServer();
virtual ~PageScriptDebugServer() { }
-
+
virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Context>);
virtual void runMessageLoopOnPause(v8::Handle<v8::Context>);
virtual void quitMessageLoopOnPause();
diff --git a/Source/bindings/v8/ScopedPersistent.h b/Source/bindings/v8/ScopedPersistent.h
index a2ce885..faef97d 100644
--- a/Source/bindings/v8/ScopedPersistent.h
+++ b/Source/bindings/v8/ScopedPersistent.h
@@ -57,14 +57,6 @@
return v8::Local<T>::New(isolate, m_handle);
}
- // FIXME: This function does an unsafe handle access. Remove it. Do not add
- // code which calls this function.
- ALWAYS_INLINE v8::Handle<T> deprecatedGet() const
- {
- const v8::Handle<T>* handle = reinterpret_cast<const v8::Handle<T>*>(&m_handle);
- return *handle;
- }
-
template<typename P>
void makeWeak(P* parameters, void (*callback)(v8::Isolate*, v8::Persistent<T>*, P*))
{
@@ -72,11 +64,6 @@
}
bool isEmpty() const { return m_handle.IsEmpty(); }
- bool isNull() { return deprecatedGet()->IsNull(); }
- bool isUndefined() { return deprecatedGet()->IsUndefined(); }
- bool isFunction() { return deprecatedGet()->IsFunction(); }
- bool isObject() { return deprecatedGet()->IsObject(); }
- bool isString() { return deprecatedGet()->IsString(); }
void set(v8::Isolate* isolate, v8::Handle<T> handle)
{
diff --git a/Source/bindings/v8/ScriptController.cpp b/Source/bindings/v8/ScriptController.cpp
index 601214d..246c9f5 100644
--- a/Source/bindings/v8/ScriptController.cpp
+++ b/Source/bindings/v8/ScriptController.cpp
@@ -38,6 +38,7 @@
#include "bindings/v8/BindingSecurity.h"
#include "bindings/v8/NPV8Object.h"
#include "bindings/v8/ScriptCallStackFactory.h"
+#include "bindings/v8/ScriptPreprocessor.h"
#include "bindings/v8/ScriptSourceCode.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8Binding.h"
@@ -463,7 +464,7 @@
return createNoScriptObject();
v8::Context::Scope scope(v8Context);
- DOMWindow* window = frame->document()->domWindow();
+ DOMWindow* window = frame->domWindow();
v8::Handle<v8::Value> global = toV8(window, v8::Handle<v8::Object>(), v8Context->GetIsolate());
ASSERT(global->IsObject());
@@ -501,7 +502,7 @@
return createNoScriptObject();
v8::Context::Scope scope(v8Context);
- DOMWindow* window = m_frame->document()->domWindow();
+ DOMWindow* window = m_frame->domWindow();
v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Context->GetIsolate());
if (!v8plugin->IsObject())
return createNoScriptObject();
@@ -518,6 +519,7 @@
for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_isolatedWorlds.end(); ++iter)
iter->value->clearForNavigation();
V8GCController::hintForCollectGarbage();
+ clearScriptPreprocessor();
HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindowShell", (currentTime() - start) * 1000, 0, 10000, 50);
}
@@ -649,7 +651,7 @@
if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangePending())
return true;
-
+
// DocumentWriter::replaceDocument can cause the DocumentLoader to get deref'ed and possible destroyed,
// so protect it with a RefPtr.
if (RefPtr<DocumentLoader> loader = m_frame->document()->loader())
@@ -668,9 +670,12 @@
if (v8Context.IsEmpty())
return ScriptValue();
+ String processedString = preprocess(sourceCode.source(), sourceURL);
+ ScriptSourceCode processedSourceCode(processedString, sourceCode.url(), sourceCode.startPosition());
+
v8::Context::Scope scope(v8Context);
RefPtr<Frame> protect(m_frame);
- v8::Local<v8::Value> object = compileAndRunScript(sourceCode);
+ v8::Local<v8::Value> object = compileAndRunScript(processedSourceCode);
m_sourceURL = savedSourceURL;
@@ -714,4 +719,39 @@
}
}
+void ScriptController::setScriptPreprocessor(const String& preprocessorBody)
+{
+ // We delay the creation of the preprocess until just before the first JS from the
+ // Web page to ensure that the debugger's console initialization code has completed.
+ m_preprocessorSource = preprocessorBody;
+}
+
+void ScriptController::clearScriptPreprocessor()
+{
+ m_scriptPreprocessor.clear();
+ m_preprocessorSource = String();
+}
+
+// Source to Source processing iff debugger enabled and it has loaded a preprocessor.
+String ScriptController::preprocess(const String& scriptSource, const String& scriptName)
+{
+ if (m_preprocessorSource.isEmpty())
+ return scriptSource;
+
+ if (!m_frame->page())
+ return scriptSource;
+
+ if (!m_scriptPreprocessor)
+ m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(m_preprocessorSource, this, m_frame->page()->console()));
+
+ return m_scriptPreprocessor->preprocessSourceCode(scriptSource, scriptName);
+}
+
+void ScriptController::preprocessEval(ScriptDebugServer* debugServer, v8::Handle<v8::Object> eventData)
+{
+ if (!m_scriptPreprocessor.get())
+ return;
+ m_scriptPreprocessor->preprocessEval(debugServer, eventData);
+}
+
} // namespace WebCore
diff --git a/Source/bindings/v8/ScriptController.h b/Source/bindings/v8/ScriptController.h
index a2bd844..97b56d5 100644
--- a/Source/bindings/v8/ScriptController.h
+++ b/Source/bindings/v8/ScriptController.h
@@ -51,6 +51,8 @@
class HTMLDocument;
class HTMLPlugInElement;
class KURL;
+class ScriptDebugServer;
+class ScriptPreprocessor;
class ScriptSourceCode;
class ScriptState;
class SecurityOrigin;
@@ -64,10 +66,6 @@
NotAboutToExecuteScript
};
-enum IsolatedWorldConstants {
- EmbedderWorldIdLimit = (1 << 29)
-};
-
class ScriptController {
public:
ScriptController(Frame*);
@@ -159,6 +157,12 @@
static void registerExtensionIfNeeded(v8::Extension*);
static V8Extensions& registeredExtensions();
+ void setScriptPreprocessor(const String& preprocessorSource);
+ void clearScriptPreprocessor();
+ // Source to Source processing iff debugger enabled and it has loaded a preprocessor.
+ String preprocess(const String& scriptSource, const String& scriptName);
+ void preprocessEval(ScriptDebugServer* , v8::Handle<v8::Object> eventData);
+
bool setContextDebugId(int);
static int contextDebugId(v8::Handle<v8::Context>);
@@ -184,6 +188,11 @@
PluginObjectMap m_pluginObjects;
NPObject* m_windowScriptNPObject;
+
+ // Set by the PageDebuggerAgent on reload
+ String m_preprocessorSource;
+ // Set on the first JS compilation after m_preprocessorSource is set.
+ OwnPtr<ScriptPreprocessor> m_scriptPreprocessor;
};
} // namespace WebCore
diff --git a/Source/bindings/v8/ScriptDebugServer.cpp b/Source/bindings/v8/ScriptDebugServer.cpp
index 25e8474..6e70861 100644
--- a/Source/bindings/v8/ScriptDebugServer.cpp
+++ b/Source/bindings/v8/ScriptDebugServer.cpp
@@ -34,6 +34,7 @@
#include "DebuggerScriptSource.h"
#include "V8JavaScriptCallFrame.h"
#include "bindings/v8/ScopedPersistent.h"
+#include "bindings/v8/ScriptController.h"
#include "bindings/v8/ScriptObject.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8ScriptRunner.h"
@@ -67,64 +68,6 @@
return V8ScriptRunner::callInternalFunction(function, debuggerScript, argc, argv, m_isolate);
}
-class ScriptDebugServer::ScriptPreprocessor {
- WTF_MAKE_NONCOPYABLE(ScriptPreprocessor);
-public:
- ScriptPreprocessor(const String& preprocessorScript, v8::Isolate* isolate)
- : m_isolate(isolate)
- {
- v8::HandleScope scope(m_isolate);
-
- v8::Local<v8::Context> context = v8::Context::New(m_isolate);
- if (context.IsEmpty())
- return;
- v8::Context::Scope contextScope(context);
-
- String wrappedScript = "(" + preprocessorScript + ")";
- v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8().data(), wrappedScript.utf8().length());
-
- v8::Local<v8::Value> preprocessorFunction = V8ScriptRunner::compileAndRunInternalScript(preprocessor, m_isolate);
- if (preprocessorFunction.IsEmpty() || !preprocessorFunction->IsFunction())
- return;
-
- m_utilityContext.set(isolate, context);
- m_preprocessorFunction.set(isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction));
- }
-
- String preprocessSourceCode(const String& sourceCode, const String& sourceName)
- {
- v8::HandleScope handleScope(m_isolate);
-
- if (m_preprocessorFunction.isEmpty())
- return sourceCode;
-
- v8::Local<v8::Context> context = m_utilityContext.newLocal(m_isolate);
- v8::Context::Scope contextScope(context);
-
- v8::Handle<v8::String> sourceCodeString = v8::String::New(sourceCode.utf8().data(), sourceCode.utf8().length());
-
- v8::Handle<v8::String> sourceNameString = v8::String::New(sourceName.utf8().data(), sourceName.utf8().length());
- v8::Handle<v8::Value> argv[] = { sourceCodeString, sourceNameString };
- v8::Handle<v8::Value> resultValue = V8ScriptRunner::callInternalFunction(m_preprocessorFunction.newLocal(m_isolate), context->Global(), WTF_ARRAY_LENGTH(argv), argv, m_isolate);
-
- if (!resultValue.IsEmpty() && resultValue->IsString()) {
- v8::String::Utf8Value utf8Value(resultValue);
- return String::fromUTF8(*utf8Value, utf8Value.length());
- }
- return sourceCode;
- }
-
- ~ScriptPreprocessor()
- {
- }
-
-private:
- ScopedPersistent<v8::Context> m_utilityContext;
- String m_preprocessorBody;
- ScopedPersistent<v8::Function> m_preprocessorFunction;
- v8::Isolate* m_isolate;
-};
-
ScriptDebugServer::ScriptDebugServer(v8::Isolate* isolate)
: m_pauseOnExceptionsState(DontPauseOnExceptions)
, m_breakpointsActivated(true)
@@ -367,12 +310,9 @@
*callFrame = currentCallFrame();
}
-
-void ScriptDebugServer::setScriptPreprocessor(const String& preprocessorBody)
+ScriptController* ScriptDebugServer::scriptController(v8::Handle<v8::Context> context)
{
- m_scriptPreprocessor.clear();
- if (!preprocessorBody.isEmpty())
- m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(preprocessorBody, m_isolate));
+ return 0;
}
PassRefPtr<JavaScriptCallFrame> ScriptDebugServer::wrapCallFrames(v8::Handle<v8::Object> executionState, int maximumLimit)
@@ -416,7 +356,6 @@
void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
ASSERT(2 == args.Length());
-
ScriptDebugServer* thisPtr = toScriptDebugServer(args.Data());
v8::Handle<v8::Value> exception;
v8::Handle<v8::Array> hitBreakpoints;
@@ -481,28 +420,11 @@
ScriptDebugListener* listener = getDebugListenerForContext(eventContext);
if (listener) {
v8::HandleScope scope(m_isolate);
- v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate);
if (event == v8::BeforeCompile) {
-
- if (!m_scriptPreprocessor)
- return;
-
- OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release());
- v8::Context::Scope contextScope(debugContext);
- v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::New("getScriptSource")));
- v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> script = V8ScriptRunner::callInternalFunction(getScriptSourceFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate);
-
- v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::New("getScriptName")));
- v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> scriptName = V8ScriptRunner::callInternalFunction(getScriptNameFunction, debuggerScript, WTF_ARRAY_LENGTH(argv1), argv1, m_isolate);
- v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::New("setScriptSource")));
- String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(scriptName));
-
- v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8String(patchedScript, m_isolate) };
- V8ScriptRunner::callInternalFunction(setScriptSourceFunction, debuggerScript, WTF_ARRAY_LENGTH(argv2), argv2, m_isolate);
- m_scriptPreprocessor = preprocessor.release();
+ ScriptController* controller = scriptController(eventContext);
+ if (controller)
+ controller->preprocessEval(this, eventDetails.GetEventData());
} else if (event == v8::AfterCompile) {
v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
v8::Handle<v8::Function> getAfterCompileScript = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::NewSymbol("getAfterCompileScript")));
diff --git a/Source/bindings/v8/ScriptDebugServer.h b/Source/bindings/v8/ScriptDebugServer.h
index dd8189e..fb26eaa 100644
--- a/Source/bindings/v8/ScriptDebugServer.h
+++ b/Source/bindings/v8/ScriptDebugServer.h
@@ -45,6 +45,7 @@
namespace WebCore {
+class ScriptController;
class ScriptDebugListener;
class ScriptObject;
class ScriptState;
@@ -78,8 +79,6 @@
bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceError>&, ScriptValue* newCallFrames, ScriptObject* result);
void updateCallStack(ScriptValue* callFrame);
- void setScriptPreprocessor(const String& preprocessorBody);
-
class Task {
public:
virtual ~Task() { }
@@ -94,16 +93,16 @@
v8::Local<v8::Value> functionScopes(v8::Handle<v8::Function>);
v8::Local<v8::Value> getInternalProperties(v8::Handle<v8::Object>&);
v8::Handle<v8::Value> setFunctionVariableValue(v8::Handle<v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Handle<v8::Value> newValue);
-
+ v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc, v8::Handle<v8::Value> argv[]);
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage);
virtual void clearCompiledScripts();
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage);
+ virtual ScriptController* scriptController(v8::Handle<v8::Context>);
protected:
explicit ScriptDebugServer(v8::Isolate*);
virtual ~ScriptDebugServer();
-
ScriptValue currentCallFrame();
virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Context>) = 0;
@@ -121,10 +120,6 @@
void ensureDebuggerScriptCompiled();
- v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc, v8::Handle<v8::Value> argv[]);
-
- String preprocessSourceCode(const String& sourceCode);
-
PauseOnExceptionsState m_pauseOnExceptionsState;
ScopedPersistent<v8::Object> m_debuggerScript;
ScopedPersistent<v8::Object> m_executionState;
@@ -133,12 +128,8 @@
ScopedPersistent<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
HashMap<String, OwnPtr<ScopedPersistent<v8::Script> > > m_compiledScripts;
v8::Isolate* m_isolate;
-
private:
PassRefPtr<JavaScriptCallFrame> wrapCallFrames(v8::Handle<v8::Object> executionState, int maximumLimit);
-
- class ScriptPreprocessor;
- OwnPtr<ScriptPreprocessor> m_scriptPreprocessor;
bool m_runningNestedMessageLoop;
};
diff --git a/Source/bindings/v8/ScriptPreprocessor.cpp b/Source/bindings/v8/ScriptPreprocessor.cpp
new file mode 100644
index 0000000..c48de40
--- /dev/null
+++ b/Source/bindings/v8/ScriptPreprocessor.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "bindings/v8/ScriptPreprocessor.h"
+
+#include "bindings/v8/ScriptController.h"
+#include "bindings/v8/ScriptDebugServer.h"
+#include "bindings/v8/ScriptSourceCode.h"
+#include "bindings/v8/ScriptValue.h"
+#include "bindings/v8/V8Binding.h"
+#include "bindings/v8/V8ScriptRunner.h"
+#include "bindings/v8/V8WindowShell.h"
+#include "core/page/DOMWindow.h"
+#include "core/page/Frame.h"
+#include "core/page/Page.h"
+#include "core/page/PageConsole.h"
+#include "wtf/TemporaryChange.h"
+
+namespace WebCore {
+
+ScriptPreprocessor::ScriptPreprocessor(const String& preprocessorScript, ScriptController* controller, PageConsole* console)
+ : m_isPreprocessing(false)
+{
+ v8::TryCatch tryCatch;
+ tryCatch.SetVerbose(true);
+ ScriptSourceCode preprocessor(preprocessorScript);
+ Vector<ScriptSourceCode> sources;
+ sources.append(preprocessor);
+ Vector<ScriptValue> scriptResults;
+ controller->executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorldId, sources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults);
+
+ if (scriptResults.size() != 1) {
+ console->addMessage(JSMessageSource, ErrorMessageLevel, "ScriptPreprocessor internal error, one ScriptSourceCode must give exactly one result.");
+ return;
+ }
+
+ v8::Handle<v8::Value> preprocessorFunction = scriptResults[0].v8Value();
+ if (!preprocessorFunction->IsFunction()) {
+ console->addMessage(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function.");
+ return;
+ }
+
+ RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWorldId, DOMWrapperWorld::mainWorldExtensionGroup);
+ V8WindowShell* isolatedWorldShell = controller->windowShell(world.get());
+ v8::Local<v8::Context> context = isolatedWorldShell->context();
+ m_isolate = context->GetIsolate();
+
+ m_context.set(m_isolate, context);
+ m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction));
+}
+
+String ScriptPreprocessor::preprocessSourceCode(const String& sourceCode, const String& sourceName)
+{
+ if (m_preprocessorFunction.isEmpty())
+ return sourceCode;
+
+ v8::HandleScope handleScope(m_isolate);
+ v8::Context::Scope contextScope(m_context.newLocal(m_isolate));
+
+ v8::Handle<v8::String> sourceCodeString = v8String(sourceCode, m_isolate);
+ v8::Handle<v8::String> sourceNameString = v8String(sourceName, m_isolate);
+ v8::Handle<v8::Value> argv[] = { sourceCodeString, sourceNameString };
+
+ v8::TryCatch tryCatch;
+ tryCatch.SetVerbose(true);
+ TemporaryChange<bool> isPreprocessing(m_isPreprocessing, true);
+ v8::Handle<v8::Value> resultValue = V8ScriptRunner::callAsFunction(m_preprocessorFunction.newLocal(m_isolate), m_context.newLocal(m_isolate)->Global(), WTF_ARRAY_LENGTH(argv), argv);
+
+ if (!resultValue.IsEmpty() && resultValue->IsString())
+ return toWebCoreStringWithNullCheck(resultValue);
+
+ return sourceCode;
+}
+
+void ScriptPreprocessor::preprocessEval(ScriptDebugServer* debugServer, v8::Handle<v8::Object> eventData)
+{
+ if (m_isPreprocessing)
+ return;
+
+ v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
+ v8::Context::Scope contextScope(debugContext);
+
+ // <script> tag source and attribute value source are preprocessed before we enter V8.
+ // Avoid preprocessing any internal scripts by processing only eval source in this V8 event handler.
+ v8::Handle<v8::Value> argvEventData[] = { eventData };
+ String typeInfo = toWebCoreStringWithUndefinedOrNullCheck(debugServer->callDebuggerMethod("getScriptCompilationTypeInfo", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
+ if (!typeInfo.startsWith("eval"))
+ return;
+
+ // The name and source are in the JS event data.
+ String scriptName = toWebCoreStringWithUndefinedOrNullCheck(debugServer->callDebuggerMethod("getScriptName", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
+ String script = toWebCoreStringWithUndefinedOrNullCheck(debugServer->callDebuggerMethod("getScriptSource", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
+
+ String patchedScript = preprocessSourceCode(script, scriptName);
+
+ v8::Handle<v8::Value> argvPatchedScript[] = { eventData, v8String(patchedScript, debugContext->GetIsolate()) };
+ debugServer->callDebuggerMethod("setScriptSource", WTF_ARRAY_LENGTH(argvPatchedScript), argvPatchedScript);
+}
+
+
+} // namespace WebCore
diff --git a/Source/bindings/v8/ScriptPreprocessor.h b/Source/bindings/v8/ScriptPreprocessor.h
new file mode 100644
index 0000000..fbc5925
--- /dev/null
+++ b/Source/bindings/v8/ScriptPreprocessor.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef ScriptPreprocessor_h
+#define ScriptPreprocessor_h
+
+#include "bindings/v8/V8Binding.h"
+#include "wtf/RefCounted.h"
+#include "wtf/text/WTFString.h"
+#include <v8.h>
+
+namespace WebCore {
+
+class ScriptController;
+class ScriptDebugServer;
+class PageConsole;
+
+class ScriptPreprocessor {
+ WTF_MAKE_NONCOPYABLE(ScriptPreprocessor);
+public:
+ ScriptPreprocessor(const String& preprocessorScript, ScriptController*, PageConsole*);
+ String preprocessSourceCode(const String& sourceCode, const String& sourceName);
+ void preprocessEval(ScriptDebugServer* , v8::Handle<v8::Object> eventData);
+
+private:
+ String m_preprocessorBody;
+ ScriptController* m_controller;
+ ScopedPersistent<v8::Context> m_context;
+ v8::Isolate* m_isolate;
+ ScopedPersistent<v8::Function> m_preprocessorFunction;
+ bool m_isPreprocessing;
+};
+
+} // namespace WebCore
+
+#endif // ScriptPreprocessor_h
diff --git a/Source/bindings/v8/ScriptValue.cpp b/Source/bindings/v8/ScriptValue.cpp
index 13e3c29..6ac72a1 100644
--- a/Source/bindings/v8/ScriptValue.cpp
+++ b/Source/bindings/v8/ScriptValue.cpp
@@ -47,13 +47,13 @@
PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState)
{
ScriptScope scope(scriptState);
- return SerializedScriptValue::create(v8Value());
+ return SerializedScriptValue::create(v8Value(), scriptState->isolate());
}
PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow)
{
ScriptScope scope(scriptState);
- return SerializedScriptValue::create(v8Value(), messagePorts, arrayBuffers, didThrow);
+ return SerializedScriptValue::create(v8Value(), messagePorts, arrayBuffers, didThrow, scriptState->isolate());
}
ScriptValue ScriptValue::deserialize(ScriptState* scriptState, SerializedScriptValue* value)
@@ -67,11 +67,11 @@
if (hasNoValue())
return false;
- if (!m_value->isString())
- return false;
-
v8::HandleScope handleScope(isolate);
- result = toWebCoreString(v8Value());
+ v8::Handle<v8::Value> string = v8Value();
+ if (string.IsEmpty() || !string->IsString())
+ return false;
+ result = toWebCoreString(string);
return true;
}
diff --git a/Source/bindings/v8/ScriptValue.h b/Source/bindings/v8/ScriptValue.h
index 853ec12..7fc2a09 100644
--- a/Source/bindings/v8/ScriptValue.h
+++ b/Source/bindings/v8/ScriptValue.h
@@ -93,10 +93,13 @@
return operator==(value);
}
+ // Note: This creates a new local Handle; not to be used in cases where is
+ // is an efficiency problem.
bool isFunction() const
{
ASSERT(!hasNoValue());
- return m_value->isFunction();
+ v8::Handle<v8::Value> value = v8Value();
+ return !value.IsEmpty() && value->IsFunction();
}
bool operator!=(const ScriptValue& value) const
@@ -104,22 +107,31 @@
return !operator==(value);
}
+ // Note: This creates a new local Handle; not to be used in cases where is
+ // is an efficiency problem.
bool isNull() const
{
ASSERT(!hasNoValue());
- return m_value->isNull();
+ v8::Handle<v8::Value> value = v8Value();
+ return !value.IsEmpty() && value->IsNull();
}
+ // Note: This creates a new local Handle; not to be used in cases where is
+ // is an efficiency problem.
bool isUndefined() const
{
ASSERT(!hasNoValue());
- return m_value->isUndefined();
+ v8::Handle<v8::Value> value = v8Value();
+ return !value.IsEmpty() && value->IsUndefined();
}
+ // Note: This creates a new local Handle; not to be used in cases where is
+ // is an efficiency problem.
bool isObject() const
{
ASSERT(!hasNoValue());
- return m_value->isObject();
+ v8::Handle<v8::Value> value = v8Value();
+ return !value.IsEmpty() && value->IsObject();
}
bool hasNoValue() const
diff --git a/Source/bindings/v8/ScriptWrappable.h b/Source/bindings/v8/ScriptWrappable.h
index 0afa631..2a77062 100644
--- a/Source/bindings/v8/ScriptWrappable.h
+++ b/Source/bindings/v8/ScriptWrappable.h
@@ -75,6 +75,11 @@
ASSERT(containsWrapper());
}
+ v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const
+ {
+ return unsafePersistent().newLocal(isolate);
+ }
+
const WrapperTypeInfo* typeInfo()
{
if (containsTypeInfo())
diff --git a/Source/bindings/v8/SerializedScriptValue.cpp b/Source/bindings/v8/SerializedScriptValue.cpp
index 8f2a0f6..17256d3 100644
--- a/Source/bindings/v8/SerializedScriptValue.cpp
+++ b/Source/bindings/v8/SerializedScriptValue.cpp
@@ -2223,27 +2223,23 @@
} // namespace
-PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow)
-{
- return create(value, messagePorts, arrayBuffers, didThrow, v8::Isolate::GetCurrent());
-}
-
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Isolate* isolate)
{
return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, didThrow, isolate));
}
-PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value)
-{
- return create(value, v8::Isolate::GetCurrent());
-}
-
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, v8::Isolate* isolate)
{
bool didThrow;
return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate));
}
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExceptions(v8::Handle<v8::Value> value, v8::Isolate* isolate)
+{
+ bool didThrow;
+ return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate, DoNotThrowExceptions));
+}
+
PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const String& data)
{
return adoptRef(new SerializedScriptValue(data));
@@ -2425,7 +2421,7 @@
return contents.release();
}
-SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Isolate* isolate)
+SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Isolate* isolate, ExceptionPolicy policy)
: m_externallyAllocatedMemory(0)
{
didThrow = false;
@@ -2436,9 +2432,10 @@
Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tryCatch, isolate);
status = serializer.serialize(value);
if (status == Serializer::JSException) {
- // If there was a JS exception thrown, re-throw it.
didThrow = true;
- tryCatch.ReThrow();
+ // If there was a JS exception thrown, re-throw it.
+ if (policy == ThrowExceptions)
+ tryCatch.ReThrow();
return;
}
}
@@ -2448,11 +2445,13 @@
// If there was an input error, throw a new exception outside
// of the TryCatch scope.
didThrow = true;
- setDOMException(DataCloneError, isolate);
+ if (policy == ThrowExceptions)
+ setDOMException(DataCloneError, isolate);
return;
case Serializer::InvalidStateError:
didThrow = true;
- setDOMException(InvalidStateError, isolate);
+ if (policy == ThrowExceptions)
+ setDOMException(InvalidStateError, isolate);
return;
case Serializer::JSFailure:
// If there was a JS failure (but no exception), there's not
@@ -2488,7 +2487,12 @@
if (!m_data.impl())
return v8NullWithCheck(isolate);
COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes);
- Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->bloatedCharacters()), 2 * m_data.length(), isolate);
+ m_data.ensure16Bit();
+ // FIXME: SerializedScriptValue shouldn't use String for its underlying
+ // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
+ // information stored in m_data isn't even encoded in UTF-16. Instead,
+ // unicode characters are encoded as UTF-8 with two code units per UChar.
+ Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16()), 2 * m_data.length(), isolate);
Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.get());
// deserialize() can run arbitrary script (e.g., setters), which could result in |this| being destroyed.
diff --git a/Source/bindings/v8/SerializedScriptValue.h b/Source/bindings/v8/SerializedScriptValue.h
index 97cbaa9..b37e13d 100644
--- a/Source/bindings/v8/SerializedScriptValue.h
+++ b/Source/bindings/v8/SerializedScriptValue.h
@@ -58,9 +58,7 @@
// be thrown using v8::ThrowException(), and sets |didThrow|. In this case
// the caller must not invoke any V8 operations until control returns to
// V8. When serialization is successful, |didThrow| is false.
- static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, bool&);
- static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, bool&, v8::Isolate*);
- static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>);
+ static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*);
static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, v8::Isolate*);
static PassRefPtr<SerializedScriptValue> createFromWire(const String&);
static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<uint8_t>&);
@@ -68,6 +66,9 @@
static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*);
static PassRefPtr<SerializedScriptValue> create();
+ // Never throws exceptions.
+ static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Handle<v8::Value>, v8::Isolate*);
+
static PassRefPtr<SerializedScriptValue> nullValue();
static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*);
static PassRefPtr<SerializedScriptValue> undefinedValue();
@@ -104,10 +105,14 @@
StringValue,
WireData
};
+ enum ExceptionPolicy {
+ ThrowExceptions,
+ DoNotThrowExceptions
+ };
typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
SerializedScriptValue();
- SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*);
+ SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowExceptions);
explicit SerializedScriptValue(const String& wireData);
static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBufferArray&, bool& didThrow, v8::Isolate*);
diff --git a/Source/bindings/v8/SharedPersistent.h b/Source/bindings/v8/SharedPersistent.h
index 420f40d..52cc119 100644
--- a/Source/bindings/v8/SharedPersistent.h
+++ b/Source/bindings/v8/SharedPersistent.h
@@ -53,11 +53,6 @@
}
bool isEmpty() { return m_value.isEmpty(); }
- bool isNull() { return m_value.isNull(); }
- bool isUndefined() { return m_value.isUndefined(); }
- bool isFunction() { return m_value.isFunction(); }
- bool isString() { return m_value.isString(); }
- bool isObject() { return m_value.isObject(); }
bool operator==(const SharedPersistent<T>& other)
{
diff --git a/Source/bindings/v8/V8Binding.cpp b/Source/bindings/v8/V8Binding.cpp
index 7c79964..59dde88 100644
--- a/Source/bindings/v8/V8Binding.cpp
+++ b/Source/bindings/v8/V8Binding.cpp
@@ -71,17 +71,27 @@
return V8ThrowException::throwDOMException(exceptionCode, isolate);
}
-v8::Handle<v8::Value> throwError(V8ErrorType errorType, const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> setDOMException(int exceptionCode, const String& message, v8::Isolate* isolate)
+{
+ return V8ThrowException::throwDOMException(exceptionCode, message, isolate);
+}
+
+v8::Handle<v8::Value> throwError(V8ErrorType errorType, const String& message, v8::Isolate* isolate)
{
return V8ThrowException::throwError(errorType, message, isolate);
}
-v8::Handle<v8::Value> throwError(v8::Handle<v8::Value> exception, v8::Isolate* isolate)
+v8::Handle<v8::Value> throwError(v8::Handle<v8::Value> exception)
{
- return V8ThrowException::throwError(exception, isolate);
+ return V8ThrowException::throwError(exception);
}
-v8::Handle<v8::Value> throwTypeError(const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> throwTypeError(v8::Isolate* isolate)
+{
+ return V8ThrowException::throwTypeError(String(), isolate);
+}
+
+v8::Handle<v8::Value> throwTypeError(const String& message, v8::Isolate* isolate)
{
return V8ThrowException::throwTypeError(message, isolate);
}
@@ -538,8 +548,14 @@
return 0;
if (!DOMWrapperWorld::isolatedWorldsExist())
return 0;
- ASSERT(!v8::Context::GetEntered().IsEmpty());
- return DOMWrapperWorld::isolatedWorld(v8::Context::GetEntered());
+ ASSERT(v8::Context::InContext());
+ return DOMWrapperWorld::isolatedWorld(v8::Context::GetCurrent());
+}
+
+v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate* isolate, ScriptWrappable* wrappable, v8::Handle<v8::String> key)
+{
+ v8::Local<v8::Object> wrapper = wrappable->newLocalWrapper(isolate);
+ return wrapper.IsEmpty() ? v8::Local<v8::Value>() : wrapper->GetHiddenValue(key);
}
} // namespace WebCore
diff --git a/Source/bindings/v8/V8Binding.h b/Source/bindings/v8/V8Binding.h
index 315ea52..fd047e1 100644
--- a/Source/bindings/v8/V8Binding.h
+++ b/Source/bindings/v8/V8Binding.h
@@ -50,6 +50,7 @@
class Frame;
class NodeFilter;
class ScriptExecutionContext;
+ class ScriptWrappable;
class XPathNSResolver;
const int kMaxRecursionDepth = 22;
@@ -57,15 +58,17 @@
// Schedule a DOM exception to be thrown, if the exception code is different
// from zero.
v8::Handle<v8::Value> setDOMException(int, v8::Isolate*);
+ v8::Handle<v8::Value> setDOMException(int, const String&, v8::Isolate*);
// Schedule a JavaScript error to be thrown.
- v8::Handle<v8::Value> throwError(V8ErrorType, const char*, v8::Isolate*);
+ v8::Handle<v8::Value> throwError(V8ErrorType, const String&, v8::Isolate*);
// Schedule a JavaScript error to be thrown.
- v8::Handle<v8::Value> throwError(v8::Handle<v8::Value>, v8::Isolate*);
+ v8::Handle<v8::Value> throwError(v8::Handle<v8::Value>);
// A helper for throwing JavaScript TypeError.
- v8::Handle<v8::Value> throwTypeError(const char*, v8::Isolate*);
+ v8::Handle<v8::Value> throwTypeError(v8::Isolate*);
+ v8::Handle<v8::Value> throwTypeError(const String&, v8::Isolate*);
// A helper for throwing JavaScript TypeError for not enough arguments.
v8::Handle<v8::Value> throwNotEnoughArgumentsError(v8::Isolate*);
@@ -121,27 +124,31 @@
args.GetReturnValue().SetNull();
}
- enum TreatNullStringAs {
- NullStringAsEmpty,
- NullStringAsNull,
- NullStringAsUndefined,
- };
-
template <class CallbackInfo>
- inline void v8SetReturnValueString(const CallbackInfo& info, const String& string, v8::Isolate* isolate, TreatNullStringAs treatNullStringAs = NullStringAsEmpty)
+ inline void v8SetReturnValueString(const CallbackInfo& info, const String& string, v8::Isolate* isolate)
{
if (string.isNull()) {
- switch (treatNullStringAs) {
- case NullStringAsEmpty:
- v8SetReturnValue(info, v8::String::Empty(isolate));
- break;
- case NullStringAsNull:
- v8SetReturnValueNull(info);
- break;
- case NullStringAsUndefined:
- v8SetReturnValue(info, v8::Undefined(isolate));
- break;
- }
+ v8SetReturnValue(info, v8::String::Empty(isolate));
+ return;
+ }
+ V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString(info, string.impl(), isolate);
+ }
+
+ template <class CallbackInfo>
+ inline void v8SetReturnValueStringOrNull(const CallbackInfo& info, const String& string, v8::Isolate* isolate)
+ {
+ if (string.isNull()) {
+ v8SetReturnValueNull(info);
+ return;
+ }
+ V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString(info, string.impl(), isolate);
+ }
+
+ template <class CallbackInfo>
+ inline void v8SetReturnValueStringOrUndefined(const CallbackInfo& info, const String& string, v8::Isolate* isolate)
+ {
+ if (string.isNull()) {
+ v8SetReturnValue(info, v8::Undefined(isolate));
return;
}
V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString(info, string.impl(), isolate);
@@ -454,7 +461,7 @@
inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isolate* isolate)
{
if (!value->IsObject()) {
- throwTypeError(0, isolate);
+ throwTypeError(isolate);
return v8Undefined();
}
@@ -464,7 +471,7 @@
V8TRYCATCH(v8::Local<v8::Value>, lengthValue, object->Get(v8::String::NewSymbol("length")));
if (lengthValue->IsUndefined() || lengthValue->IsNull()) {
- throwTypeError(0, isolate);
+ throwTypeError(isolate);
return v8Undefined();
}
@@ -585,6 +592,8 @@
return v8::FunctionTemplate::New(function, environment)->GetFunction();
}
+ v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, ScriptWrappable*, v8::Handle<v8::String> key);
+
} // namespace WebCore
#endif // V8Binding_h
diff --git a/Source/bindings/v8/V8BindingMacros.h b/Source/bindings/v8/V8BindingMacros.h
index 3e97e42..53416e5 100644
--- a/Source/bindings/v8/V8BindingMacros.h
+++ b/Source/bindings/v8/V8BindingMacros.h
@@ -64,7 +64,7 @@
return block.ReThrow(); \
} \
if (UNLIKELY(!ok)) \
- return throwTypeError(0, isolate); \
+ return throwTypeError(isolate); \
}
#define V8TRYCATCH_WITH_TYPECHECK_VOID(type, var, value, isolate) \
@@ -80,7 +80,7 @@
} \
} \
if (UNLIKELY(!ok)) { \
- throwTypeError(0, isolate); \
+ throwTypeError(isolate); \
return; \
} \
}
diff --git a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
index baf8d90..070f9e9 100644
--- a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
+++ b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
@@ -110,7 +110,7 @@
if (!canInvokeCallback())
return;
- element->setIsUpgradedCustomElement();
+ element->setCustomElementState(Element::Upgraded);
v8::HandleScope handleScope;
v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get());
diff --git a/Source/bindings/v8/V8ErrorHandler.cpp b/Source/bindings/v8/V8ErrorHandler.cpp
index faa3311..035e9ce 100644
--- a/Source/bindings/v8/V8ErrorHandler.cpp
+++ b/Source/bindings/v8/V8ErrorHandler.cpp
@@ -56,13 +56,13 @@
if (!listener.IsEmpty() && listener->IsFunction()) {
v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener);
v8::Local<v8::Object> thisValue = v8::Context::GetCurrent()->Global();
- v8::Handle<v8::Value> parameters[3] = { v8String(errorEvent->message(), isolate), v8String(errorEvent->filename(), isolate), v8::Integer::New(errorEvent->lineno(), isolate) };
+ v8::Handle<v8::Value> parameters[4] = { v8String(errorEvent->message(), isolate), v8String(errorEvent->filename(), isolate), v8::Integer::New(errorEvent->lineno(), isolate), v8::Integer::New(errorEvent->column(), isolate) };
v8::TryCatch tryCatch;
tryCatch.SetVerbose(true);
if (worldType(isolate) == WorkerWorld)
returnValue = V8ScriptRunner::callFunction(callFunction, context, thisValue, WTF_ARRAY_LENGTH(parameters), parameters);
else
- returnValue = ScriptController::callFunctionWithInstrumentation(0, callFunction, thisValue, 3, parameters);
+ returnValue = ScriptController::callFunctionWithInstrumentation(0, callFunction, thisValue, WTF_ARRAY_LENGTH(parameters), parameters);
}
return returnValue;
}
diff --git a/Source/bindings/v8/V8Initializer.cpp b/Source/bindings/v8/V8Initializer.cpp
index cfa378a..390723e 100644
--- a/Source/bindings/v8/V8Initializer.cpp
+++ b/Source/bindings/v8/V8Initializer.cpp
@@ -94,7 +94,7 @@
v8::Handle<v8::Value> resourceName = message->GetScriptResourceName();
bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsString();
String resource = shouldUseDocumentURL ? firstWindow->document()->url() : toWebCoreString(resourceName);
- firstWindow->document()->reportException(errorMessage, message->GetLineNumber(), resource, callStack);
+ firstWindow->document()->reportException(errorMessage, message->GetLineNumber(), message->GetStartColumn(), resource, callStack);
}
static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data)
@@ -102,13 +102,14 @@
Frame* target = findFrame(host, data, v8::Isolate::GetCurrent());
if (!target)
return;
- DOMWindow* targetWindow = target->document()->domWindow();
- targetWindow->printErrorMessage(targetWindow->crossDomainAccessErrorMessage(activeDOMWindow()));
+ DOMWindow* targetWindow = target->domWindow();
// Throw an exception for failed-access checks against Location objects, otherwise write to the console.
WrapperTypeInfo* typeInfo = WrapperTypeInfo::unwrap(data);
if (V8Location::info.equals(typeInfo))
- setDOMException(SecurityError, v8::Isolate::GetCurrent());
+ setDOMException(SecurityError, targetWindow->crossDomainAccessErrorMessage(activeDOMWindow()), v8::Isolate::GetCurrent());
+ else
+ targetWindow->printErrorMessage(targetWindow->crossDomainAccessErrorMessage(activeDOMWindow()));
}
static bool codeGenerationCheckCallbackInMainThread(v8::Local<v8::Context> context)
@@ -167,8 +168,9 @@
if (ScriptExecutionContext* context = getScriptExecutionContext()) {
String errorMessage = toWebCoreString(message->Get());
int lineNumber = message->GetLineNumber();
+ int columnNumber = message->GetStartColumn();
String sourceURL = toWebCoreString(message->GetScriptResourceName());
- context->reportException(errorMessage, lineNumber, sourceURL, 0);
+ context->reportException(errorMessage, lineNumber, columnNumber, sourceURL, 0);
}
isReportingException = false;
diff --git a/Source/bindings/v8/V8LazyEventListener.cpp b/Source/bindings/v8/V8LazyEventListener.cpp
index f706d31..d255c61 100644
--- a/Source/bindings/v8/V8LazyEventListener.cpp
+++ b/Source/bindings/v8/V8LazyEventListener.cpp
@@ -135,6 +135,7 @@
return;
v8::Context::Scope scope(v8Context);
+ String listenerSource = frame->script()->preprocess(m_code, m_functionName);
// FIXME: Remove the following 'with' hack.
//
@@ -158,7 +159,7 @@
"with (this[1]) {"
"with (this[0]) {"
"return function(" + m_eventParameterName + ") {" +
- m_code + "\n" // Insert '\n' otherwise //-style comments could break the handler.
+ listenerSource + "\n" // Insert '\n' otherwise //-style comments could break the handler.
"};"
"}}}})";
diff --git a/Source/bindings/v8/V8ThrowException.cpp b/Source/bindings/v8/V8ThrowException.cpp
index 914fd5d..507507b 100644
--- a/Source/bindings/v8/V8ThrowException.cpp
+++ b/Source/bindings/v8/V8ThrowException.cpp
@@ -44,7 +44,7 @@
info.Data()->ToObject()->Set(v8::String::NewSymbol("stack"), value);
}
-v8::Handle<v8::Value> V8ThrowException::createDOMException(int ec, const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::createDOMException(int ec, const String& message, v8::Isolate* isolate)
{
if (ec <= 0 || v8::V8::IsExecutionTerminating())
return v8Undefined();
@@ -68,7 +68,7 @@
return exception;
}
-v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::throwDOMException(int ec, const String& message, v8::Isolate* isolate)
{
v8::Handle<v8::Value> exception = createDOMException(ec, message, isolate);
if (exception.IsEmpty())
@@ -77,7 +77,7 @@
return V8ThrowException::throwError(exception);
}
-v8::Handle<v8::Value> V8ThrowException::createError(V8ErrorType type, const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::createError(V8ErrorType type, const String& message, v8::Isolate* isolate)
{
switch (type) {
case v8RangeError:
@@ -96,7 +96,7 @@
}
}
-v8::Handle<v8::Value> V8ThrowException::throwError(V8ErrorType type, const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::throwError(V8ErrorType type, const String& message, v8::Isolate* isolate)
{
v8::Handle<v8::Value> exception = V8ThrowException::createError(type, message, isolate);
if (exception.IsEmpty())
@@ -104,12 +104,12 @@
return V8ThrowException::throwError(exception);
}
-v8::Handle<v8::Value> V8ThrowException::createTypeError(const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::createTypeError(const String& message, v8::Isolate* isolate)
{
- return v8::Exception::TypeError(v8String(message ? message : "Type error", isolate));
+ return v8::Exception::TypeError(v8String(message.isNull() ? "Type error" : message, isolate));
}
-v8::Handle<v8::Value> V8ThrowException::throwTypeError(const char* message, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::throwTypeError(const String& message, v8::Isolate* isolate)
{
v8::Handle<v8::Value> exception = V8ThrowException::createTypeError(message, isolate);
return V8ThrowException::throwError(exception);
@@ -121,7 +121,7 @@
return V8ThrowException::throwError(exception);
}
-v8::Handle<v8::Value> V8ThrowException::throwError(v8::Handle<v8::Value> exception, v8::Isolate* isolate)
+v8::Handle<v8::Value> V8ThrowException::throwError(v8::Handle<v8::Value> exception)
{
if (!v8::V8::IsExecutionTerminating())
v8::ThrowException(exception);
diff --git a/Source/bindings/v8/V8ThrowException.h b/Source/bindings/v8/V8ThrowException.h
index 891431d..ea12306 100644
--- a/Source/bindings/v8/V8ThrowException.h
+++ b/Source/bindings/v8/V8ThrowException.h
@@ -25,6 +25,7 @@
#ifndef V8ThrowException_h
#define V8ThrowException_h
+#include "wtf/text/WTFString.h"
#include <v8.h>
namespace WebCore {
@@ -42,22 +43,22 @@
static v8::Handle<v8::Value> createDOMException(int ec, v8::Isolate* isolate)
{
- return createDOMException(ec, 0, isolate);
+ return createDOMException(ec, String(), isolate);
}
- static v8::Handle<v8::Value> createDOMException(int, const char*, v8::Isolate*);
+ static v8::Handle<v8::Value> createDOMException(int, const String&, v8::Isolate*);
static v8::Handle<v8::Value> throwDOMException(int ec, v8::Isolate* isolate)
{
- return throwDOMException(ec, 0, isolate);
+ return throwDOMException(ec, String(), isolate);
}
- static v8::Handle<v8::Value> throwDOMException(int, const char*, v8::Isolate*);
+ static v8::Handle<v8::Value> throwDOMException(int, const String&, v8::Isolate*);
- static v8::Handle<v8::Value> createError(V8ErrorType, const char*, v8::Isolate* = 0);
- static v8::Handle<v8::Value> throwError(V8ErrorType, const char*, v8::Isolate* = 0);
- static v8::Handle<v8::Value> throwError(v8::Handle<v8::Value>, v8::Isolate* = 0);
+ static v8::Handle<v8::Value> createError(V8ErrorType, const String&, v8::Isolate*);
+ static v8::Handle<v8::Value> throwError(V8ErrorType, const String&, v8::Isolate*);
+ static v8::Handle<v8::Value> throwError(v8::Handle<v8::Value>);
- static v8::Handle<v8::Value> createTypeError(const char* = 0, v8::Isolate* = 0);
- static v8::Handle<v8::Value> throwTypeError(const char* = 0, v8::Isolate* = 0);
+ static v8::Handle<v8::Value> createTypeError(const String&, v8::Isolate*);
+ static v8::Handle<v8::Value> throwTypeError(const String&, v8::Isolate*);
static v8::Handle<v8::Value> throwNotEnoughArgumentsError(v8::Isolate*);
};
diff --git a/Source/bindings/v8/V8Utilities.cpp b/Source/bindings/v8/V8Utilities.cpp
index b470a43..f6cbd03 100644
--- a/Source/bindings/v8/V8Utilities.cpp
+++ b/Source/bindings/v8/V8Utilities.cpp
@@ -42,8 +42,10 @@
#include "core/dom/ScriptExecutionContext.h"
#include "core/page/Frame.h"
#include "core/workers/WorkerGlobalScope.h"
-#include <v8.h>
#include "wtf/ArrayBuffer.h"
+#include "wtf/text/WTFString.h"
+#include <v8.h>
+
namespace WebCore {
@@ -100,7 +102,7 @@
} else if (V8ArrayBuffer::HasInstance(transferrable, isolate, worldType(isolate)))
arrayBuffers.append(V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(transferrable)));
else {
- throwTypeError(0, isolate);
+ throwTypeError(isolate);
return false;
}
}
diff --git a/Source/bindings/v8/V8WindowShell.cpp b/Source/bindings/v8/V8WindowShell.cpp
index 8d2472a..96e6e70 100644
--- a/Source/bindings/v8/V8WindowShell.cpp
+++ b/Source/bindings/v8/V8WindowShell.cpp
@@ -308,7 +308,7 @@
bool V8WindowShell::installDOMWindow()
{
DOMWrapperWorld::setInitializingWindow(true);
- DOMWindow* window = m_frame->document()->domWindow();
+ DOMWindow* window = m_frame->domWindow();
v8::Local<v8::Object> windowWrapper = V8ObjectConstructor::newInstance(V8PerContextData::from(m_context.newLocal(m_isolate))->constructorForType(&V8Window::info));
if (windowWrapper.IsEmpty())
return false;
@@ -445,7 +445,7 @@
Node* node = items->item(0);
Frame* frame = 0;
if (node->hasTagName(HTMLNames::iframeTag) && (frame = toHTMLIFrameElement(node)->contentFrame()))
- return toV8(frame->document()->domWindow(), creationContext, isolate);
+ return toV8(frame->domWindow(), creationContext, isolate);
return toV8(node, creationContext, isolate);
}
return toV8(items.release(), creationContext, isolate);
diff --git a/Source/bindings/v8/WorkerScriptController.cpp b/Source/bindings/v8/WorkerScriptController.cpp
index eaf30e5..c95df01 100644
--- a/Source/bindings/v8/WorkerScriptController.cpp
+++ b/Source/bindings/v8/WorkerScriptController.cpp
@@ -165,8 +165,9 @@
state->hadException = true;
state->errorMessage = toWebCoreString(message->Get());
state->lineNumber = message->GetLineNumber();
+ state->columnNumber = message->GetStartColumn();
state->sourceURL = toWebCoreString(message->GetScriptResourceName());
- if (m_workerGlobalScope->sanitizeScriptError(state->errorMessage, state->lineNumber, state->sourceURL))
+ if (m_workerGlobalScope->sanitizeScriptError(state->errorMessage, state->lineNumber, state->columnNumber, state->sourceURL))
state->exception = throwError(v8GeneralError, state->errorMessage.utf8().data(), m_isolate);
else
state->exception = ScriptValue(block.Exception());
@@ -192,7 +193,7 @@
if (exception)
*exception = state.exception;
else
- m_workerGlobalScope->reportException(state.errorMessage, state.lineNumber, state.sourceURL, 0);
+ m_workerGlobalScope->reportException(state.errorMessage, state.lineNumber, state.columnNumber, state.sourceURL, 0);
}
}
@@ -234,7 +235,7 @@
void WorkerScriptController::setException(const ScriptValue& exception)
{
- throwError(exception.v8Value(), m_isolate);
+ throwError(exception.v8Value());
}
WorkerScriptController* WorkerScriptController::controllerForContext()
diff --git a/Source/bindings/v8/WorkerScriptController.h b/Source/bindings/v8/WorkerScriptController.h
index 22832f5..4e72f30 100644
--- a/Source/bindings/v8/WorkerScriptController.h
+++ b/Source/bindings/v8/WorkerScriptController.h
@@ -48,6 +48,7 @@
WorkerGlobalScopeExecutionState()
: hadException(false)
, lineNumber(0)
+ , columnNumber(0)
{
}
@@ -55,6 +56,7 @@
ScriptValue exception;
String errorMessage;
int lineNumber;
+ int columnNumber;
String sourceURL;
};
@@ -93,6 +95,11 @@
// Returns a local handle of the context.
v8::Local<v8::Context> context() { return m_context.newLocal(v8::Isolate::GetCurrent()); }
+ // Send a notification about current thread is going to be idle.
+ // Returns true if the embedder should stop calling idleNotification
+ // until real work has been done.
+ bool idleNotification() { return v8::V8::IdleNotification(); }
+
private:
bool initializeContextIfNeeded();
void disposeContext();
diff --git a/Source/bindings/v8/custom/V8ArrayBufferCustom.cpp b/Source/bindings/v8/custom/V8ArrayBufferCustom.cpp
index e5f9707..5689552 100644
--- a/Source/bindings/v8/custom/V8ArrayBufferCustom.cpp
+++ b/Source/bindings/v8/custom/V8ArrayBufferCustom.cpp
@@ -32,8 +32,6 @@
#include "bindings/v8/custom/V8ArrayBufferCustom.h"
#include "bindings/v8/V8Binding.h"
-#include "core/dom/ExceptionCode.h"
-
#include "wtf/ArrayBuffer.h"
#include "wtf/StdLibExtras.h"
@@ -67,7 +65,6 @@
static_cast<ArrayBuffer*>(object)->deref();
}
-
v8::Handle<v8::Object> V8ArrayBuffer::createWrapper(PassRefPtr<ArrayBuffer> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
ASSERT(impl.get());
@@ -103,5 +100,4 @@
return reinterpret_cast<ArrayBuffer*>(arraybufferPtr);
}
-
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8ArrayBufferViewCustom.h b/Source/bindings/v8/custom/V8ArrayBufferViewCustom.h
index 8d13795..98de7f5 100644
--- a/Source/bindings/v8/custom/V8ArrayBufferViewCustom.h
+++ b/Source/bindings/v8/custom/V8ArrayBufferViewCustom.h
@@ -151,7 +151,7 @@
if (args[0]->IsNull()) {
// Invalid first argument
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
diff --git a/Source/bindings/v8/custom/V8AudioBufferSourceNodeCustom.cpp b/Source/bindings/v8/custom/V8AudioBufferSourceNodeCustom.cpp
index 4fcfa79..d15ab4d 100644
--- a/Source/bindings/v8/custom/V8AudioBufferSourceNodeCustom.cpp
+++ b/Source/bindings/v8/custom/V8AudioBufferSourceNodeCustom.cpp
@@ -30,7 +30,6 @@
#include "V8AudioBuffer.h"
#include "bindings/v8/V8Binding.h"
-#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/AudioBuffer.h"
#include "modules/webaudio/AudioBufferSourceNode.h"
diff --git a/Source/bindings/v8/custom/V8BiquadFilterNodeCustom.cpp b/Source/bindings/v8/custom/V8BiquadFilterNodeCustom.cpp
index 64385e0..ccd5c35 100644
--- a/Source/bindings/v8/custom/V8BiquadFilterNodeCustom.cpp
+++ b/Source/bindings/v8/custom/V8BiquadFilterNodeCustom.cpp
@@ -29,7 +29,6 @@
#include "V8BiquadFilterNode.h"
#include "bindings/v8/V8Binding.h"
-#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/BiquadFilterNode.h"
namespace WebCore {
@@ -43,7 +42,7 @@
uint32_t type = toUInt32(value, ok);
ASSERT(ok);
if (!imp->setType(type))
- throwError(v8TypeError, "Illegal BiquadFilterNode type", info.GetIsolate());
+ throwTypeError("Illegal BiquadFilterNode type", info.GetIsolate());
return;
}
@@ -55,7 +54,7 @@
}
}
- throwError(v8TypeError, "Illegal BiquadFilterNode type", info.GetIsolate());
+ throwTypeError("Illegal BiquadFilterNode type", info.GetIsolate());
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp b/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
index 7064975..0582ea3 100644
--- a/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
+++ b/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
@@ -32,15 +32,14 @@
#include "V8CSSStyleDeclaration.h"
#include "CSSPropertyNames.h"
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/V8Binding.h"
#include "core/css/CSSParser.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSStyleDeclaration.h"
#include "core/css/CSSValue.h"
#include "core/dom/EventTarget.h"
#include "core/page/RuntimeCSSEnabled.h"
-
-#include "bindings/v8/V8Binding.h"
-
#include "wtf/ASCIICType.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
@@ -212,7 +211,7 @@
cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX));
return;
}
- v8SetReturnValueString(info, cssValue->cssText(), info.GetIsolate(), NullStringAsNull);
+ v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate());
return;
}
@@ -234,13 +233,11 @@
if (propInfo->hadPixelOrPosPrefix)
propertyValue.append("px");
- ExceptionCode ec = 0;
- imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), propertyValue, false, ec);
+ ExceptionState es(info.GetIsolate());
+ imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), propertyValue, false, es);
- if (ec) {
- setDOMException(ec, info.GetIsolate());
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(info, value);
}
diff --git a/Source/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp b/Source/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp
index 34fb677..a079037 100644
--- a/Source/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp
+++ b/Source/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp
@@ -31,13 +31,6 @@
#include "config.h"
#include "V8CanvasRenderingContext2D.h"
-#include "core/dom/ExceptionCode.h"
-#include "core/html/canvas/CanvasGradient.h"
-#include "core/html/canvas/CanvasPattern.h"
-#include "core/html/canvas/CanvasRenderingContext2D.h"
-#include "core/html/canvas/CanvasStyle.h"
-#include "core/platform/graphics/FloatRect.h"
-
#include "V8CanvasGradient.h"
#include "V8CanvasPattern.h"
#include "V8HTMLCanvasElement.h"
@@ -45,6 +38,11 @@
#include "V8HTMLVideoElement.h"
#include "V8ImageData.h"
#include "bindings/v8/V8Binding.h"
+#include "core/html/canvas/CanvasGradient.h"
+#include "core/html/canvas/CanvasPattern.h"
+#include "core/html/canvas/CanvasRenderingContext2D.h"
+#include "core/html/canvas/CanvasStyle.h"
+#include "core/platform/graphics/FloatRect.h"
namespace WebCore {
diff --git a/Source/bindings/v8/custom/V8CryptoCustom.cpp b/Source/bindings/v8/custom/V8CryptoCustom.cpp
index 1d44dee..569e9c3 100644
--- a/Source/bindings/v8/custom/V8CryptoCustom.cpp
+++ b/Source/bindings/v8/custom/V8CryptoCustom.cpp
@@ -26,11 +26,10 @@
#include "V8Crypto.h"
#include "V8ArrayBufferView.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Utilities.h"
-#include "core/dom/ExceptionCode.h"
#include "modules/crypto/Crypto.h"
-
#include "wtf/ArrayBufferView.h"
namespace WebCore {
@@ -54,13 +53,11 @@
ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(buffer));
ASSERT(arrayBufferView);
- ExceptionCode ec = 0;
- Crypto::getRandomValues(arrayBufferView, ec);
+ ExceptionState es(args.GetIsolate());
+ Crypto::getRandomValues(arrayBufferView, es);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, buffer);
}
diff --git a/Source/bindings/v8/custom/V8CustomEventCustom.cpp b/Source/bindings/v8/custom/V8CustomEventCustom.cpp
index d03eb67..8f30553 100644
--- a/Source/bindings/v8/custom/V8CustomEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8CustomEventCustom.cpp
@@ -34,12 +34,11 @@
#include "V8Event.h"
#include "bindings/v8/Dictionary.h"
#include "bindings/v8/ScriptState.h"
-#include "bindings/v8/ScriptValue.h"
+#include "bindings/v8/SerializedScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8DOMWrapper.h"
#include "bindings/v8/V8HiddenPropertyName.h"
#include "core/dom/ContextFeatures.h"
-#include "core/dom/ExceptionCode.h"
#include "core/page/Frame.h"
#include "RuntimeEnabledFeatures.h"
@@ -63,9 +62,16 @@
return;
}
- SerializedScriptValue* serialized = event->serializedScriptValue();
- if (serialized) {
- result = serialized->deserialize();
+ if (!event->serializedScriptValue()) {
+ // If we're in an isolated world and the event was created in the main world,
+ // we need to find the 'detail' property on the main world wrapper and clone it.
+ v8::Local<v8::Value> mainWorldDetail = getHiddenValueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenPropertyName::detail());
+ if (!mainWorldDetail.IsEmpty())
+ event->setSerializedDetail(SerializedScriptValue::createAndSwallowExceptions(mainWorldDetail, info.GetIsolate()));
+ }
+
+ if (event->serializedScriptValue()) {
+ result = event->serializedScriptValue()->deserialize();
v8SetReturnValue(info, cacheState(info.Holder(), result));
return;
}
@@ -83,8 +89,13 @@
V8TRYCATCH_VOID(bool, cancelableArg, args[2]->BooleanValue());
v8::Handle<v8::Value> detailsArg = args[3];
- args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detailsArg);
event->initEvent(typeArg, canBubbleArg, cancelableArg);
+
+ if (!detailsArg.IsEmpty()) {
+ args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detailsArg);
+ if (isolatedWorldForIsolate(args.GetIsolate()))
+ event->setSerializedDetail(SerializedScriptValue::createAndSwallowExceptions(detailsArg, args.GetIsolate()));
+ }
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8DataViewCustom.cpp b/Source/bindings/v8/custom/V8DataViewCustom.cpp
index 4988fdb..72b7af1 100644
--- a/Source/bindings/v8/custom/V8DataViewCustom.cpp
+++ b/Source/bindings/v8/custom/V8DataViewCustom.cpp
@@ -44,7 +44,7 @@
return;
}
if (args[0]->IsNull() || !V8ArrayBuffer::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
constructWebGLArrayWithArrayBufferArgument<DataView, char, V8DataView>(args, &info, v8::kExternalByteArray, false);
diff --git a/Source/bindings/v8/custom/V8DedicatedWorkerGlobalScopeCustom.cpp b/Source/bindings/v8/custom/V8DedicatedWorkerGlobalScopeCustom.cpp
index 677d7be..6f03688 100644
--- a/Source/bindings/v8/custom/V8DedicatedWorkerGlobalScopeCustom.cpp
+++ b/Source/bindings/v8/custom/V8DedicatedWorkerGlobalScopeCustom.cpp
@@ -32,6 +32,7 @@
#include "V8DedicatedWorkerGlobalScope.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Utilities.h"
#include "bindings/v8/V8WorkerGlobalScopeEventListener.h"
@@ -58,9 +59,9 @@
args.GetIsolate());
if (didThrow)
return;
- ExceptionCode ec = 0;
- workerGlobalScope->postMessage(message.release(), &ports, ec);
- setDOMException(ec, args.GetIsolate());
+ ExceptionState es(args.GetIsolate());
+ workerGlobalScope->postMessage(message.release(), &ports, es);
+ es.throwIfNeeded();
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp b/Source/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp
index 4e6cf41..2383f06 100644
--- a/Source/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp
@@ -27,7 +27,7 @@
#include "V8DeviceOrientationEvent.h"
#include "bindings/v8/V8Binding.h"
-#include "core/dom/DeviceOrientationData.h"
+#include "modules/device_orientation/DeviceOrientationData.h"
#include <v8.h>
diff --git a/Source/bindings/v8/custom/V8DocumentCustom.cpp b/Source/bindings/v8/custom/V8DocumentCustom.cpp
index 1df4fde..7431fd7 100644
--- a/Source/bindings/v8/custom/V8DocumentCustom.cpp
+++ b/Source/bindings/v8/custom/V8DocumentCustom.cpp
@@ -41,6 +41,7 @@
#include "V8WebGLRenderingContext.h"
#include "V8XPathNSResolver.h"
#include "V8XPathResult.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ScriptController.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8DOMWrapper.h"
@@ -62,7 +63,7 @@
void V8Document::evaluateMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
RefPtr<Document> document = V8Document::toNative(args.Holder());
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
String expression = toWebCoreString(args[0]);
RefPtr<Node> contextNode;
if (V8Node::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate())))
@@ -79,11 +80,9 @@
if (V8XPathResult::HasInstance(args[4], args.GetIsolate(), worldType(args.GetIsolate())))
inResult = V8XPathResult::toNative(v8::Handle<v8::Object>::Cast(args[4]));
- V8TRYCATCH_VOID(RefPtr<XPathResult>, result, DocumentXPathEvaluator::evaluate(document.get(), expression, contextNode.get(), resolver.get(), type, inResult.get(), ec));
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ V8TRYCATCH_VOID(RefPtr<XPathResult>, result, DocumentXPathEvaluator::evaluate(document.get(), expression, contextNode.get(), resolver.get(), type, inResult.get(), es));
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Fast(result.release(), args, document.get()));
}
diff --git a/Source/bindings/v8/custom/V8FileReaderCustom.cpp b/Source/bindings/v8/custom/V8FileReaderCustom.cpp
index 49ea526..dd8a88c 100644
--- a/Source/bindings/v8/custom/V8FileReaderCustom.cpp
+++ b/Source/bindings/v8/custom/V8FileReaderCustom.cpp
@@ -46,7 +46,7 @@
v8SetReturnValue(info, toV8Fast(imp->arrayBufferResult(), info, imp));
return;
}
- v8SetReturnValueString(info, imp->stringResult(), info.GetIsolate(), NullStringAsNull);
+ v8SetReturnValueStringOrNull(info, imp->stringResult(), info.GetIsolate());
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp b/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
index c12b6c2..0ecf92f 100644
--- a/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
+++ b/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
@@ -35,6 +35,7 @@
#include "V8CanvasRenderingContext2D.h"
#include "V8Node.h"
#include "V8WebGLRenderingContext.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "core/html/HTMLCanvasElement.h"
#include "core/html/canvas/Canvas2DContextAttributes.h"
@@ -127,7 +128,7 @@
{
v8::Handle<v8::Object> holder = args.Holder();
HTMLCanvasElement* canvas = V8HTMLCanvasElement::toNative(holder);
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
String type = toWebCoreString(args[0]);
double quality;
@@ -137,9 +138,9 @@
qualityPtr = &quality;
}
- String result = canvas->toDataURL(type, qualityPtr, ec);
- setDOMException(ec, args.GetIsolate());
- v8SetReturnValueString(args, result, args.GetIsolate(), NullStringAsUndefined);
+ String result = canvas->toDataURL(type, qualityPtr, es);
+ es.throwIfNeeded();
+ v8SetReturnValueStringOrUndefined(args, result, args.GetIsolate());
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp b/Source/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp
index 414ab57..7392172 100644
--- a/Source/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp
+++ b/Source/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp
@@ -31,16 +31,16 @@
#include "config.h"
#include "V8HTMLOptionsCollection.h"
+#include "V8HTMLOptionElement.h"
+#include "V8Node.h"
+#include "V8NodeList.h"
+#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/V8Binding.h"
+#include "bindings/v8/custom/V8HTMLSelectElementCustom.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/NamedNodesCollection.h"
#include "core/html/HTMLOptionElement.h"
#include "core/html/HTMLOptionsCollection.h"
-
-#include "V8HTMLOptionElement.h"
-#include "V8Node.h"
-#include "V8NodeList.h"
-#include "bindings/v8/V8Binding.h"
-#include "bindings/v8/custom/V8HTMLSelectElementCustom.h"
#include "core/html/HTMLSelectElement.h"
namespace WebCore {
@@ -86,21 +86,19 @@
HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(args.Holder());
HTMLOptionElement* option = V8HTMLOptionElement::toNative(v8::Handle<v8::Object>(v8::Handle<v8::Object>::Cast(args[0])));
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
if (args.Length() < 2)
- imp->add(option, ec);
+ imp->add(option, es);
else {
bool ok;
V8TRYCATCH_VOID(int, index, toInt32(args[1], ok));
if (!ok)
- ec = TypeMismatchError;
+ es.throwDOMException(TypeMismatchError);
else
- imp->add(option, index, ec);
+ imp->add(option, index, es);
}
- if (!ec)
- return;
- setDOMException(ec, args.GetIsolate());
+ es.throwIfNeeded();
}
void V8HTMLOptionsCollection::lengthAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
@@ -108,19 +106,20 @@
HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Holder());
double v = value->NumberValue();
unsigned newLength = 0;
- ExceptionCode ec = 0;
+ ExceptionState es(info.GetIsolate());
if (!std::isnan(v) && !std::isinf(v)) {
if (v < 0.0)
- ec = IndexSizeError;
+ es.throwDOMException(IndexSizeError);
else if (v > static_cast<double>(UINT_MAX))
newLength = UINT_MAX;
else
newLength = static_cast<unsigned>(v);
}
- if (!ec)
- imp->setLength(newLength, ec);
- setDOMException(ec, info.GetIsolate());
+ if (es.throwIfNeeded())
+ return;
+
+ imp->setLength(newLength, es);
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8HistoryCustom.cpp b/Source/bindings/v8/custom/V8HistoryCustom.cpp
index d3beab9..ca101ba 100644
--- a/Source/bindings/v8/custom/V8HistoryCustom.cpp
+++ b/Source/bindings/v8/custom/V8HistoryCustom.cpp
@@ -32,6 +32,7 @@
#include "V8History.h"
#include "V8Window.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/SerializedScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8HiddenPropertyName.h"
@@ -68,11 +69,11 @@
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, title, args[1]);
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, url, argumentOrNull(args, 2));
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
History* history = V8History::toNative(args.Holder());
- history->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, ec);
+ history->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, es);
args.Holder()->DeleteHiddenValue(V8HiddenPropertyName::state());
- v8SetReturnValue(args, setDOMException(ec, args.GetIsolate()));
+ es.throwIfNeeded();
}
void V8History::replaceStateMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -85,11 +86,11 @@
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, title, args[1]);
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, url, argumentOrNull(args, 2));
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
History* history = V8History::toNative(args.Holder());
- history->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec);
+ history->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, es);
args.Holder()->DeleteHiddenValue(V8HiddenPropertyName::state());
- v8SetReturnValue(args, setDOMException(ec, args.GetIsolate()));
+ es.throwIfNeeded();
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
index 5d67db1..1ac446e 100644
--- a/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
+++ b/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
@@ -63,9 +63,9 @@
Node* InjectedScriptHost::scriptValueAsNode(ScriptValue value)
{
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
if (!value.isObject() || value.isNull())
return 0;
- v8::HandleScope scope(v8::Isolate::GetCurrent());
return V8Node::toNative(v8::Handle<v8::Object>::Cast(value.v8Value()));
}
@@ -310,7 +310,7 @@
Database* database = V8Database::toNative(v8::Handle<v8::Object>::Cast(args[0]));
if (database) {
InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); {
- v8SetReturnValueString(args, host->databaseIdImpl(database), args.GetIsolate(), NullStringAsUndefined);
+ v8SetReturnValueStringOrUndefined(args, host->databaseIdImpl(database), args.GetIsolate());
return;
}
}
@@ -323,7 +323,7 @@
Storage* storage = V8Storage::toNative(v8::Handle<v8::Object>::Cast(args[0]));
if (storage) {
InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder());
- v8SetReturnValueString(args, host->storageIdImpl(storage), args.GetIsolate(), NullStringAsUndefined);
+ v8SetReturnValueStringOrUndefined(args, host->storageIdImpl(storage), args.GetIsolate());
return;
}
}
diff --git a/Source/bindings/v8/custom/V8MessageEventCustom.cpp b/Source/bindings/v8/custom/V8MessageEventCustom.cpp
index 00de25f..55ff7d1 100644
--- a/Source/bindings/v8/custom/V8MessageEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8MessageEventCustom.cpp
@@ -51,8 +51,19 @@
switch (event->dataType()) {
case MessageEvent::DataTypeScriptValue: {
result = info.Holder()->GetHiddenValue(V8HiddenPropertyName::data());
- if (result.IsEmpty())
- result = v8::Null(info.GetIsolate());
+ if (result.IsEmpty()) {
+ if (!event->dataAsSerializedScriptValue()) {
+ // If we're in an isolated world and the event was created in the main world,
+ // we need to find the 'data' property on the main world wrapper and clone it.
+ v8::Local<v8::Value> mainWorldData = getHiddenValueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenPropertyName::data());
+ if (!mainWorldData.IsEmpty())
+ event->setSerializedData(SerializedScriptValue::createAndSwallowExceptions(mainWorldData, info.GetIsolate()));
+ }
+ if (event->dataAsSerializedScriptValue())
+ result = event->dataAsSerializedScriptValue()->deserialize(info.GetIsolate());
+ else
+ result = v8::Null(info.GetIsolate());
+ }
break;
}
@@ -111,8 +122,13 @@
if (!getMessagePortArray(args[7], *portArray, args.GetIsolate()))
return;
}
- args.Holder()->SetHiddenValue(V8HiddenPropertyName::data(), dataArg);
event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, originArg, lastEventIdArg, sourceArg, portArray.release());
+
+ if (!dataArg.IsEmpty()) {
+ args.Holder()->SetHiddenValue(V8HiddenPropertyName::data(), dataArg);
+ if (isolatedWorldForIsolate(args.GetIsolate()))
+ event->setSerializedData(SerializedScriptValue::createAndSwallowExceptions(dataArg, args.GetIsolate()));
+ }
}
void V8MessageEvent::webkitInitMessageEventMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
diff --git a/Source/bindings/v8/custom/V8MessagePortCustom.cpp b/Source/bindings/v8/custom/V8MessagePortCustom.cpp
index d126142..ef3a1f1 100644
--- a/Source/bindings/v8/custom/V8MessagePortCustom.cpp
+++ b/Source/bindings/v8/custom/V8MessagePortCustom.cpp
@@ -31,10 +31,10 @@
#include "config.h"
#include "V8MessagePort.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/SerializedScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Utilities.h"
-#include "core/dom/ExceptionCode.h"
#include "core/dom/MessagePort.h"
#include "wtf/ArrayBuffer.h"
@@ -58,9 +58,9 @@
args.GetIsolate());
if (didThrow)
return;
- ExceptionCode ec = 0;
- messagePort->postMessage(message.release(), &portArray, ec);
- setDOMException(ec, args.GetIsolate());
+ ExceptionState es(args.GetIsolate());
+ messagePort->postMessage(message.release(), &portArray, es);
+ es.throwIfNeeded();
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8MutationObserverCustom.cpp b/Source/bindings/v8/custom/V8MutationObserverCustom.cpp
index 7547dac..6bb0cdc 100644
--- a/Source/bindings/v8/custom/V8MutationObserverCustom.cpp
+++ b/Source/bindings/v8/custom/V8MutationObserverCustom.cpp
@@ -36,7 +36,6 @@
#include "bindings/v8/V8DOMWrapper.h"
#include "bindings/v8/V8MutationCallback.h"
#include "bindings/v8/V8Utilities.h"
-#include "core/dom/ExceptionCode.h"
#include "core/dom/MutationObserver.h"
namespace WebCore {
diff --git a/Source/bindings/v8/custom/V8NodeCustom.cpp b/Source/bindings/v8/custom/V8NodeCustom.cpp
index 447fb77..73246e4 100644
--- a/Source/bindings/v8/custom/V8NodeCustom.cpp
+++ b/Source/bindings/v8/custom/V8NodeCustom.cpp
@@ -46,6 +46,7 @@
#include "V8SVGElement.h"
#include "V8ShadowRoot.h"
#include "V8Text.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8AbstractEventListener.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8EventListener.h"
@@ -65,14 +66,13 @@
CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
Node* newChild = V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
Node* refChild = V8Node::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0;
- imp->insertBefore(newChild, refChild, ec, AttachLazily);
- if (ec)
- setDOMException(ec, args.GetIsolate());
- else
- v8SetReturnValue(args, args[0]);
+ imp->insertBefore(newChild, refChild, es, AttachLazily);
+ if (es.throwIfNeeded())
+ return;
+ v8SetReturnValue(args, args[0]);
}
// This function is customized to take advantage of the optional 4th argument: AttachBehavior
@@ -83,14 +83,13 @@
CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
Node* newChild = V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
Node* oldChild = V8Node::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0;
- imp->replaceChild(newChild, oldChild, ec, AttachLazily);
- if (ec)
- setDOMException(ec, args.GetIsolate());
- else
- v8SetReturnValue(args, args[1]);
+ imp->replaceChild(newChild, oldChild, es, AttachLazily);
+ if (es.throwIfNeeded())
+ return;
+ v8SetReturnValue(args, args[1]);
}
void V8Node::removeChildMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -100,13 +99,12 @@
CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
Node* oldChild = V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
- imp->removeChild(oldChild, ec);
- if (ec)
- setDOMException(ec, args.GetIsolate());
- else
- v8SetReturnValue(args, args[0]);
+ imp->removeChild(oldChild, es);
+ if (es.throwIfNeeded())
+ return;
+ v8SetReturnValue(args, args[0]);
}
// This function is customized to take advantage of the optional 4th argument: AttachBehavior
@@ -117,13 +115,12 @@
CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
Node* newChild = V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
- imp->appendChild(newChild, ec, AttachLazily);
- if (ec)
- setDOMException(ec, args.GetIsolate());
- else
- v8SetReturnValue(args, args[0]);
+ imp->appendChild(newChild, es, AttachLazily);
+ if (es.throwIfNeeded())
+ return;
+ v8SetReturnValue(args, args[0]);
}
v8::Handle<v8::Object> wrap(Node* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
diff --git a/Source/bindings/v8/custom/V8OscillatorNodeCustom.cpp b/Source/bindings/v8/custom/V8OscillatorNodeCustom.cpp
index b1c0577..c1e892b 100644
--- a/Source/bindings/v8/custom/V8OscillatorNodeCustom.cpp
+++ b/Source/bindings/v8/custom/V8OscillatorNodeCustom.cpp
@@ -29,7 +29,6 @@
#include "V8OscillatorNode.h"
#include "bindings/v8/V8Binding.h"
-#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/OscillatorNode.h"
namespace WebCore {
@@ -43,7 +42,7 @@
bool ok = false;
uint32_t type = toUInt32(value, ok);
if (!ok || !imp->setType(type))
- throwError(v8TypeError, "Illegal OscillatorNode type", info.GetIsolate());
+ throwTypeError("Illegal OscillatorNode type", info.GetIsolate());
return;
}
@@ -55,7 +54,7 @@
}
}
- throwError(v8TypeError, "Illegal OscillatorNode type", info.GetIsolate());
+ throwTypeError("Illegal OscillatorNode type", info.GetIsolate());
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8PannerNodeCustom.cpp b/Source/bindings/v8/custom/V8PannerNodeCustom.cpp
index c0edba0..00b9c62 100644
--- a/Source/bindings/v8/custom/V8PannerNodeCustom.cpp
+++ b/Source/bindings/v8/custom/V8PannerNodeCustom.cpp
@@ -29,7 +29,6 @@
#include "V8PannerNode.h"
#include "bindings/v8/V8Binding.h"
-#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/PannerNode.h"
namespace WebCore {
@@ -43,7 +42,7 @@
uint32_t model = toUInt32(value, ok);
ASSERT(ok);
if (!imp->setPanningModel(model))
- throwError(v8TypeError, "Illegal panningModel", info.GetIsolate());
+ throwTypeError("Illegal panningModel", info.GetIsolate());
return;
}
@@ -55,7 +54,7 @@
}
}
- throwError(v8TypeError, "Illegal panningModel", info.GetIsolate());
+ throwTypeError("Illegal panningModel", info.GetIsolate());
}
void V8PannerNode::distanceModelAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
@@ -67,7 +66,7 @@
uint32_t model = toUInt32(value, ok);
ASSERT(ok);
if (!imp->setDistanceModel(model))
- throwError(v8TypeError, "Illegal distanceModel", info.GetIsolate());
+ throwTypeError("Illegal distanceModel", info.GetIsolate());
return;
}
@@ -79,7 +78,7 @@
}
}
- throwError(v8TypeError, "Illegal distanceModel", info.GetIsolate());
+ throwTypeError("Illegal distanceModel", info.GetIsolate());
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8PopStateEventCustom.cpp b/Source/bindings/v8/custom/V8PopStateEventCustom.cpp
index ba93201..91be6fe 100644
--- a/Source/bindings/v8/custom/V8PopStateEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8PopStateEventCustom.cpp
@@ -58,7 +58,18 @@
PopStateEvent* event = V8PopStateEvent::toNative(info.Holder());
History* history = event->history();
if (!history || !event->serializedState()) {
- v8SetReturnValue(info, cacheState(info.Holder(), v8::Null(info.GetIsolate())));
+ if (!event->serializedState()) {
+ // If we're in an isolated world and the event was created in the main world,
+ // we need to find the 'state' property on the main world wrapper and clone it.
+ v8::Local<v8::Value> mainWorldState = getHiddenValueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenPropertyName::state());
+ if (!mainWorldState.IsEmpty())
+ event->setSerializedState(SerializedScriptValue::createAndSwallowExceptions(mainWorldState, info.GetIsolate()));
+ }
+ if (event->serializedState())
+ result = event->serializedState()->deserialize();
+ else
+ result = v8::Null(info.GetIsolate());
+ v8SetReturnValue(info, cacheState(info.Holder(), result));
return;
}
@@ -81,8 +92,9 @@
}
result = event->serializedState()->deserialize(info.GetIsolate());
v8History->SetHiddenValue(V8HiddenPropertyName::state(), result);
- } else
+ } else {
result = event->serializedState()->deserialize(info.GetIsolate());
+ }
v8SetReturnValue(info, cacheState(info.Holder(), result));
}
diff --git a/Source/bindings/v8/custom/V8PromiseCustom.cpp b/Source/bindings/v8/custom/V8PromiseCustom.cpp
index 8253f04..77f5a81 100644
--- a/Source/bindings/v8/custom/V8PromiseCustom.cpp
+++ b/Source/bindings/v8/custom/V8PromiseCustom.cpp
@@ -40,7 +40,6 @@
#include "bindings/v8/V8ScriptRunner.h"
#include "bindings/v8/WrapperTypeInfo.h"
#include "core/dom/Document.h"
-#include "core/dom/ExceptionCode.h"
#include "core/page/DOMWindow.h"
#include "core/platform/Task.h"
#include "wtf/Functional.h"
diff --git a/Source/bindings/v8/custom/V8SQLTransactionCustom.cpp b/Source/bindings/v8/custom/V8SQLTransactionCustom.cpp
index 1c2787f..428226e 100644
--- a/Source/bindings/v8/custom/V8SQLTransactionCustom.cpp
+++ b/Source/bindings/v8/custom/V8SQLTransactionCustom.cpp
@@ -34,6 +34,7 @@
#include "V8SQLStatementCallback.h"
#include "V8SQLStatementErrorCallback.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "core/dom/ExceptionCode.h"
#include "core/platform/sql/SQLValue.h"
@@ -108,9 +109,9 @@
errorCallback = V8SQLStatementErrorCallback::create(args[3], scriptExecutionContext);
}
- ExceptionCode ec = 0;
- transaction->executeSQL(statement, sqlValues, callback, errorCallback, ec);
- setDOMException(ec, args.GetIsolate());
+ ExceptionState es(args.GetIsolate());
+ transaction->executeSQL(statement, sqlValues, callback, errorCallback, es);
+ es.throwIfNeeded();
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp b/Source/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp
index ab35678..66e6f6a 100644
--- a/Source/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp
+++ b/Source/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp
@@ -29,7 +29,6 @@
*/
#include "config.h"
-
#include "V8SQLTransactionSync.h"
#include "V8SQLResultSet.h"
diff --git a/Source/bindings/v8/custom/V8SVGLengthCustom.cpp b/Source/bindings/v8/custom/V8SVGLengthCustom.cpp
index 1202334..24f7524 100644
--- a/Source/bindings/v8/custom/V8SVGLengthCustom.cpp
+++ b/Source/bindings/v8/custom/V8SVGLengthCustom.cpp
@@ -28,10 +28,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <config.h>
-
+#include "config.h"
#include "V8SVGLength.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGLengthContext.h"
@@ -43,13 +43,11 @@
{
SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder());
SVGLength& imp = wrapper->propertyReference();
- ExceptionCode ec = 0;
+ ExceptionState es(info.GetIsolate());
SVGLengthContext lengthContext(wrapper->contextElement());
- float value = imp.value(lengthContext, ec);
- if (UNLIKELY(ec)) {
- setDOMException(ec, info.GetIsolate());
+ float value = imp.value(lengthContext, es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(info, value);
}
@@ -62,18 +60,17 @@
}
if (!isUndefinedOrNull(value) && !value->IsNumber() && !value->IsBoolean()) {
- throwTypeError(0, info.GetIsolate());
+ throwTypeError(info.GetIsolate());
return;
}
SVGLength& imp = wrapper->propertyReference();
- ExceptionCode ec = 0;
+ ExceptionState es(info.GetIsolate());
SVGLengthContext lengthContext(wrapper->contextElement());
- imp.setValue(static_cast<float>(value->NumberValue()), lengthContext, ec);
- if (UNLIKELY(ec))
- setDOMException(ec, info.GetIsolate());
- else
- wrapper->commitChange();
+ imp.setValue(static_cast<float>(value->NumberValue()), lengthContext, es);
+ if (es.throwIfNeeded())
+ return;
+ wrapper->commitChange();
}
void V8SVGLength::convertToSpecifiedUnitsMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -90,15 +87,12 @@
}
SVGLength& imp = wrapper->propertyReference();
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
V8TRYCATCH_VOID(int, unitType, toUInt32(args[0]));
SVGLengthContext lengthContext(wrapper->contextElement());
- imp.convertToSpecifiedUnits(unitType, lengthContext, ec);
- if (UNLIKELY(ec)) {
- setDOMException(ec, args.GetIsolate());
+ imp.convertToSpecifiedUnits(unitType, lengthContext, es);
+ if (es.throwIfNeeded())
return;
- }
-
wrapper->commitChange();
}
diff --git a/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp b/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
index 2e8923f..fa3532e 100644
--- a/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
+++ b/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
@@ -29,7 +29,6 @@
*/
#include "config.h"
-
#include "V8WebGLRenderingContext.h"
#include "V8ANGLEInstancedArrays.h"
@@ -70,6 +69,7 @@
#include "V8WebGLTexture.h"
#include "V8WebGLUniformLocation.h"
#include "V8WebGLVertexArrayObjectOES.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8HiddenPropertyName.h"
#include "core/dom/ExceptionCode.h"
@@ -267,33 +267,31 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
unsigned target = toInt32(args[0]);
unsigned pname = toInt32(args[1]);
WebGLGetInfo info;
switch (objectType) {
case kBuffer:
- info = context->getBufferParameter(target, pname, ec);
+ info = context->getBufferParameter(target, pname, es);
break;
case kRenderbuffer:
- info = context->getRenderbufferParameter(target, pname, ec);
+ info = context->getRenderbufferParameter(target, pname, es);
break;
case kTexture:
- info = context->getTexParameter(target, pname, ec);
+ info = context->getTexParameter(target, pname, es);
break;
case kVertexAttrib:
// target => index
- info = context->getVertexAttrib(target, pname, ec);
+ info = context->getVertexAttrib(target, pname, es);
break;
default:
notImplemented();
break;
}
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Object(info, args.Holder(), args.GetIsolate()));
}
@@ -319,17 +317,16 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLProgram::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
WebGLProgram* program = V8WebGLProgram::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
Vector<RefPtr<WebGLShader> > shaders;
- bool succeed = context->getAttachedShaders(program, shaders, ec);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ bool succeed = context->getAttachedShaders(program, shaders, es);
+ if (es.throwIfNeeded()) {
v8SetReturnValueNull(args);
return;
}
@@ -367,14 +364,13 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
unsigned target = toInt32(args[0]);
unsigned attachment = toInt32(args[1]);
unsigned pname = toInt32(args[2]);
- WebGLGetInfo info = context->getFramebufferAttachmentParameter(target, attachment, pname, ec);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ WebGLGetInfo info = context->getFramebufferAttachmentParameter(target, attachment, pname, es);
+ if (es.throwIfNeeded()) {
return;
}
v8SetReturnValue(args, toV8Object(info, args.Holder(), args.GetIsolate()));
@@ -387,14 +383,12 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
unsigned pname = toInt32(args[0]);
- WebGLGetInfo info = context->getParameter(pname, ec);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ WebGLGetInfo info = context->getParameter(pname, es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Object(info, args.Holder(), args.GetIsolate()));
}
@@ -405,19 +399,17 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLProgram::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
WebGLProgram* program = V8WebGLProgram::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
unsigned pname = toInt32(args[1]);
- WebGLGetInfo info = context->getProgramParameter(program, pname, ec);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ WebGLGetInfo info = context->getProgramParameter(program, pname, es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Object(info, args.Holder(), args.GetIsolate()));
}
@@ -433,19 +425,17 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLShader::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
WebGLShader* shader = V8WebGLShader::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8WebGLShader::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
unsigned pname = toInt32(args[1]);
- WebGLGetInfo info = context->getShaderParameter(shader, pname, ec);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ WebGLGetInfo info = context->getShaderParameter(shader, pname, es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Object(info, args.Holder(), args.GetIsolate()));
}
@@ -476,26 +466,24 @@
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLProgram::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
WebGLProgram* program = V8WebGLProgram::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8WebGLProgram::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
if (args.Length() > 1 && !isUndefinedOrNull(args[1]) && !V8WebGLUniformLocation::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
bool ok = false;
WebGLUniformLocation* location = toWebGLUniformLocation(args[1], ok, args.GetIsolate());
- WebGLGetInfo info = context->getUniform(program, location, ec);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
+ WebGLGetInfo info = context->getUniform(program, location, es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(args, toV8Object(info, args.Holder(), args.GetIsolate()));
}
@@ -556,7 +544,7 @@
index = toInt32(args[0]);
else {
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLUniformLocation::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
location = toWebGLUniformLocation(args[0], ok, args.GetIsolate());
@@ -567,27 +555,24 @@
if (V8Float32Array::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate()))) {
Float32Array* array = V8Float32Array::toNative(args[1]->ToObject());
ASSERT(array != NULL);
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
switch (functionToCall) {
- case kUniform1v: context->uniform1fv(location, array, ec); break;
- case kUniform2v: context->uniform2fv(location, array, ec); break;
- case kUniform3v: context->uniform3fv(location, array, ec); break;
- case kUniform4v: context->uniform4fv(location, array, ec); break;
- case kVertexAttrib1v: context->vertexAttrib1fv(index, array); break;
- case kVertexAttrib2v: context->vertexAttrib2fv(index, array); break;
- case kVertexAttrib3v: context->vertexAttrib3fv(index, array); break;
- case kVertexAttrib4v: context->vertexAttrib4fv(index, array); break;
- default: ASSERT_NOT_REACHED(); break;
+ case kUniform1v: context->uniform1fv(location, array, es); break;
+ case kUniform2v: context->uniform2fv(location, array, es); break;
+ case kUniform3v: context->uniform3fv(location, array, es); break;
+ case kUniform4v: context->uniform4fv(location, array, es); break;
+ case kVertexAttrib1v: context->vertexAttrib1fv(index, array); break;
+ case kVertexAttrib2v: context->vertexAttrib2fv(index, array); break;
+ case kVertexAttrib3v: context->vertexAttrib3fv(index, array); break;
+ case kVertexAttrib4v: context->vertexAttrib4fv(index, array); break;
+ default: ASSERT_NOT_REACHED(); break;
}
- if (ec) {
- setDOMException(ec, args.GetIsolate());
- return;
- }
+ es.throwIfNeeded();
return;
}
if (args[1].IsEmpty() || !args[1]->IsArray()) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
v8::Handle<v8::Array> array =
@@ -599,23 +584,20 @@
setDOMException(SyntaxError, args.GetIsolate());
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
switch (functionToCall) {
- case kUniform1v: context->uniform1fv(location, data, len, ec); break;
- case kUniform2v: context->uniform2fv(location, data, len, ec); break;
- case kUniform3v: context->uniform3fv(location, data, len, ec); break;
- case kUniform4v: context->uniform4fv(location, data, len, ec); break;
- case kVertexAttrib1v: context->vertexAttrib1fv(index, data, len); break;
- case kVertexAttrib2v: context->vertexAttrib2fv(index, data, len); break;
- case kVertexAttrib3v: context->vertexAttrib3fv(index, data, len); break;
- case kVertexAttrib4v: context->vertexAttrib4fv(index, data, len); break;
- default: ASSERT_NOT_REACHED(); break;
+ case kUniform1v: context->uniform1fv(location, data, len, es); break;
+ case kUniform2v: context->uniform2fv(location, data, len, es); break;
+ case kUniform3v: context->uniform3fv(location, data, len, es); break;
+ case kUniform4v: context->uniform4fv(location, data, len, es); break;
+ case kVertexAttrib1v: context->vertexAttrib1fv(index, data, len); break;
+ case kVertexAttrib2v: context->vertexAttrib2fv(index, data, len); break;
+ case kVertexAttrib3v: context->vertexAttrib3fv(index, data, len); break;
+ case kVertexAttrib4v: context->vertexAttrib4fv(index, data, len); break;
+ default: ASSERT_NOT_REACHED(); break;
}
fastFree(data);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
- return;
- }
+ es.throwIfNeeded();
}
static void uniformHelperi(const v8::FunctionCallbackInfo<v8::Value>& args, FunctionToCall functionToCall)
@@ -637,7 +619,7 @@
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLUniformLocation::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
bool ok = false;
@@ -646,23 +628,20 @@
if (V8Int32Array::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate()))) {
Int32Array* array = V8Int32Array::toNative(args[1]->ToObject());
ASSERT(array != NULL);
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
switch (functionToCall) {
- case kUniform1v: context->uniform1iv(location, array, ec); break;
- case kUniform2v: context->uniform2iv(location, array, ec); break;
- case kUniform3v: context->uniform3iv(location, array, ec); break;
- case kUniform4v: context->uniform4iv(location, array, ec); break;
- default: ASSERT_NOT_REACHED(); break;
+ case kUniform1v: context->uniform1iv(location, array, es); break;
+ case kUniform2v: context->uniform2iv(location, array, es); break;
+ case kUniform3v: context->uniform3iv(location, array, es); break;
+ case kUniform4v: context->uniform4iv(location, array, es); break;
+ default: ASSERT_NOT_REACHED(); break;
}
- if (ec) {
- setDOMException(ec, args.GetIsolate());
- return;
- }
+ es.throwIfNeeded();
return;
}
if (args[1].IsEmpty() || !args[1]->IsArray()) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
v8::Handle<v8::Array> array =
@@ -674,19 +653,16 @@
setDOMException(SyntaxError, args.GetIsolate());
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
switch (functionToCall) {
- case kUniform1v: context->uniform1iv(location, data, len, ec); break;
- case kUniform2v: context->uniform2iv(location, data, len, ec); break;
- case kUniform3v: context->uniform3iv(location, data, len, ec); break;
- case kUniform4v: context->uniform4iv(location, data, len, ec); break;
- default: ASSERT_NOT_REACHED(); break;
+ case kUniform1v: context->uniform1iv(location, data, len, es); break;
+ case kUniform2v: context->uniform2iv(location, data, len, es); break;
+ case kUniform3v: context->uniform3iv(location, data, len, es); break;
+ case kUniform4v: context->uniform4iv(location, data, len, es); break;
+ default: ASSERT_NOT_REACHED(); break;
}
fastFree(data);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
- return;
- }
+ es.throwIfNeeded();
}
void V8WebGLRenderingContext::uniform1fvMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -748,7 +724,7 @@
WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder());
if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLUniformLocation::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
bool ok = false;
@@ -758,22 +734,19 @@
if (V8Float32Array::HasInstance(args[2], args.GetIsolate(), worldType(args.GetIsolate()))) {
Float32Array* array = V8Float32Array::toNative(args[2]->ToObject());
ASSERT(array != NULL);
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
switch (matrixSize) {
- case 2: context->uniformMatrix2fv(location, transpose, array, ec); break;
- case 3: context->uniformMatrix3fv(location, transpose, array, ec); break;
- case 4: context->uniformMatrix4fv(location, transpose, array, ec); break;
- default: ASSERT_NOT_REACHED(); break;
+ case 2: context->uniformMatrix2fv(location, transpose, array, es); break;
+ case 3: context->uniformMatrix3fv(location, transpose, array, es); break;
+ case 4: context->uniformMatrix4fv(location, transpose, array, es); break;
+ default: ASSERT_NOT_REACHED(); break;
}
- if (ec) {
- setDOMException(ec, args.GetIsolate());
- return;
- }
+ es.throwIfNeeded();
return;
}
if (args[2].IsEmpty() || !args[2]->IsArray()) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
v8::Handle<v8::Array> array =
@@ -785,18 +758,15 @@
setDOMException(SyntaxError, args.GetIsolate());
return;
}
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
switch (matrixSize) {
- case 2: context->uniformMatrix2fv(location, transpose, data, len, ec); break;
- case 3: context->uniformMatrix3fv(location, transpose, data, len, ec); break;
- case 4: context->uniformMatrix4fv(location, transpose, data, len, ec); break;
- default: ASSERT_NOT_REACHED(); break;
+ case 2: context->uniformMatrix2fv(location, transpose, data, len, es); break;
+ case 3: context->uniformMatrix3fv(location, transpose, data, len, es); break;
+ case 4: context->uniformMatrix4fv(location, transpose, data, len, es); break;
+ default: ASSERT_NOT_REACHED(); break;
}
fastFree(data);
- if (ec) {
- setDOMException(ec, args.GetIsolate());
- return;
- }
+ es.throwIfNeeded();
}
void V8WebGLRenderingContext::uniformMatrix2fvMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
diff --git a/Source/bindings/v8/custom/V8WindowCustom.cpp b/Source/bindings/v8/custom/V8WindowCustom.cpp
index ae23d16..6f66d65 100644
--- a/Source/bindings/v8/custom/V8WindowCustom.cpp
+++ b/Source/bindings/v8/custom/V8WindowCustom.cpp
@@ -34,6 +34,7 @@
#include "V8HTMLCollection.h"
#include "V8Node.h"
#include "bindings/v8/BindingSecurity.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ScheduledAction.h"
#include "bindings/v8/ScriptController.h"
#include "bindings/v8/ScriptSourceCode.h"
@@ -55,6 +56,7 @@
#include "core/page/ContentSecurityPolicy.h"
#include "core/page/DOMTimer.h"
#include "core/page/DOMWindow.h"
+#include "core/page/DOMWindowTimers.h"
#include "core/page/Frame.h"
#include "core/page/FrameView.h"
#include "core/page/Location.h"
@@ -66,10 +68,13 @@
#include "core/storage/Storage.h"
#include "core/workers/SharedWorkerRepository.h"
#include "wtf/ArrayBuffer.h"
+#include "wtf/OwnArrayPtr.h"
namespace WebCore {
-void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot)
+// FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerGlobalScopeCustom.cpp.
+// We should refactor this.
+void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, DOMTimer::Type timerType)
{
int argumentCount = args.Length();
@@ -85,7 +90,7 @@
}
v8::Handle<v8::Value> function = args[0];
- WTF::String functionString;
+ String functionString;
if (!function->IsFunction()) {
if (function->IsString()) {
functionString = toWebCoreString(function);
@@ -105,19 +110,17 @@
return;
}
- int32_t timeout = 0;
- if (argumentCount >= 2)
- timeout = args[1]->Int32Value();
-
if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
return;
- int id;
+ ASSERT(imp->frame());
+
+ OwnPtr<ScheduledAction> action;
if (function->IsFunction()) {
int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0;
- v8::Local<v8::Value>* params = 0;
+ OwnArrayPtr<v8::Local<v8::Value> > params;
if (paramCount > 0) {
- params = new v8::Local<v8::Value>[paramCount];
+ params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]);
for (int i = 0; i < paramCount; i++) {
// parameters must be globalized
params[i] = args[i+2];
@@ -125,20 +128,24 @@
}
// params is passed to action, and released in action's destructor
- ASSERT(imp->frame());
- OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params, args.GetIsolate()));
-
- // FIXME: We should use OwnArrayPtr for params.
- delete[] params;
-
- id = DOMTimer::install(scriptContext, action.release(), timeout, singleShot);
+ action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(), args.GetIsolate()));
} else {
if (imp->document() && !imp->document()->contentSecurityPolicy()->allowEval()) {
v8SetReturnValue(args, 0);
return;
}
- ASSERT(imp->frame());
- id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp->frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolate())), timeout, singleShot);
+ action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolate()));
+ }
+
+ int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0;
+ int timerId;
+ switch (timerType) {
+ case DOMTimer::TimeoutType:
+ timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout);
+ break;
+ case DOMTimer::IntervalType:
+ timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout);
+ break;
}
// Try to do the idle notification before the timeout expires to get better
@@ -148,7 +155,7 @@
V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval);
}
- v8SetReturnValue(args, id);
+ v8SetReturnValue(args, timerId);
}
void V8Window::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
@@ -249,7 +256,7 @@
// If called directly by WebCore we don't have a calling context.
if (!source) {
- throwTypeError(0, args.GetIsolate());
+ throwTypeError(args.GetIsolate());
return;
}
@@ -279,9 +286,9 @@
if (didThrow)
return;
- ExceptionCode ec = 0;
- window->postMessage(message.release(), &portArray, targetOrigin, source, ec);
- setDOMException(ec, args.GetIsolate());
+ ExceptionState es(args.GetIsolate());
+ window->postMessage(message.release(), &portArray, targetOrigin, source, es);
+ es.throwIfNeeded();
}
// FIXME(fqian): returning string is cheating, and we should
@@ -390,7 +397,7 @@
AtomicString propName = toWebCoreAtomicString(name);
Frame* child = frame->tree()->scopedChild(propName);
if (child) {
- v8SetReturnValue(info, toV8Fast(child->document()->domWindow(), info, window));
+ v8SetReturnValue(info, toV8Fast(child->domWindow(), info, window));
return;
}
@@ -419,13 +426,13 @@
void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
- WindowSetTimeoutImpl(args, true);
+ WindowSetTimeoutImpl(args, DOMTimer::TimeoutType);
}
void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
- WindowSetTimeoutImpl(args, false);
+ WindowSetTimeoutImpl(args, DOMTimer::IntervalType);
}
bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
diff --git a/Source/bindings/v8/custom/V8WorkerCustom.cpp b/Source/bindings/v8/custom/V8WorkerCustom.cpp
index 79bbb21..74ec3f8 100644
--- a/Source/bindings/v8/custom/V8WorkerCustom.cpp
+++ b/Source/bindings/v8/custom/V8WorkerCustom.cpp
@@ -31,14 +31,12 @@
#include "config.h"
#include "V8Worker.h"
-
-#include "core/workers/Worker.h"
-
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/SerializedScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Utilities.h"
-#include "core/dom/ExceptionCode.h"
#include "core/page/Frame.h"
+#include "core/workers/Worker.h"
#include "core/workers/WorkerGlobalScope.h"
#include "wtf/ArrayBuffer.h"
@@ -62,9 +60,9 @@
args.GetIsolate());
if (didThrow)
return;
- ExceptionCode ec = 0;
- worker->postMessage(message.release(), &ports, ec);
- setDOMException(ec, args.GetIsolate());
+ ExceptionState es(args.GetIsolate());
+ worker->postMessage(message.release(), &ports, es);
+ es.throwIfNeeded();
}
} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8WorkerGlobalScopeCustom.cpp b/Source/bindings/v8/custom/V8WorkerGlobalScopeCustom.cpp
index 64c0952..f3d4e7d 100644
--- a/Source/bindings/v8/custom/V8WorkerGlobalScopeCustom.cpp
+++ b/Source/bindings/v8/custom/V8WorkerGlobalScopeCustom.cpp
@@ -29,24 +29,25 @@
*/
#include "config.h"
-
#include "V8WorkerGlobalScope.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ScheduledAction.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Utilities.h"
#include "bindings/v8/V8WorkerGlobalScopeEventListener.h"
#include "bindings/v8/WorkerScriptController.h"
-#include "core/dom/ExceptionCode.h"
#include "core/inspector/ScriptCallStack.h"
#include "core/page/ContentSecurityPolicy.h"
#include "core/page/DOMTimer.h"
+#include "core/page/DOMWindowTimers.h"
#include "core/workers/WorkerGlobalScope.h"
#include "modules/websockets/WebSocket.h"
+#include "wtf/OwnArrayPtr.h"
namespace WebCore {
-void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot)
+void SetTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& args, DOMTimer::Type timerType)
{
WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Holder());
@@ -55,13 +56,12 @@
return;
v8::Handle<v8::Value> function = args[0];
- int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0;
- int timerId;
WorkerScriptController* script = workerGlobalScope->script();
if (!script)
return;
+ OwnPtr<ScheduledAction> action;
v8::Handle<v8::Context> v8Context = script->context();
if (function->IsString()) {
if (ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPolicy()) {
@@ -70,24 +70,31 @@
return;
}
}
- WTF::String stringFunction = toWebCoreString(function);
- timerId = DOMTimer::install(workerGlobalScope, adoptPtr(new ScheduledAction(v8Context, stringFunction, workerGlobalScope->url(), args.GetIsolate())), timeout, singleShot);
+ action = adoptPtr(new ScheduledAction(v8Context, toWebCoreString(function), workerGlobalScope->url(), args.GetIsolate()));
} else if (function->IsFunction()) {
size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0;
- v8::Local<v8::Value>* params = 0;
+ OwnArrayPtr<v8::Local<v8::Value> > params;
if (paramCount > 0) {
- params = new v8::Local<v8::Value>[paramCount];
+ params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]);
for (size_t i = 0; i < paramCount; ++i)
params[i] = args[i+2];
}
// ScheduledAction takes ownership of actual params and releases them in its destructor.
- OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(v8Context, v8::Handle<v8::Function>::Cast(function), paramCount, params, args.GetIsolate()));
- // FIXME: We should use a OwnArrayPtr for params.
- delete [] params;
- timerId = DOMTimer::install(workerGlobalScope, action.release(), timeout, singleShot);
+ action = adoptPtr(new ScheduledAction(v8Context, v8::Handle<v8::Function>::Cast(function), paramCount, params.get(), args.GetIsolate()));
} else
return;
+ int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0;
+ int timerId;
+ switch (timerType) {
+ case DOMTimer::TimeoutType:
+ timerId = DOMWindowTimers::setTimeout(workerGlobalScope, action.release(), timeout);
+ break;
+ case DOMTimer::IntervalType:
+ timerId = DOMWindowTimers::setInterval(workerGlobalScope, action.release(), timeout);
+ break;
+ }
+
v8SetReturnValue(args, timerId);
}
@@ -106,22 +113,19 @@
WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(args.Holder());
- ExceptionCode ec = 0;
- workerGlobalScope->importScripts(urls, ec);
-
- if (!ec)
- return;
- setDOMException(ec, args.GetIsolate());
+ ExceptionState es(args.GetIsolate());
+ workerGlobalScope->importScripts(urls, es);
+ es.throwIfNeeded();
}
void V8WorkerGlobalScope::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
- return SetTimeoutOrInterval(args, true);
+ return SetTimeoutOrInterval(args, DOMTimer::TimeoutType);
}
void V8WorkerGlobalScope::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
- return SetTimeoutOrInterval(args, false);
+ return SetTimeoutOrInterval(args, DOMTimer::IntervalType);
}
v8::Handle<v8::Value> toV8(WorkerGlobalScope* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
diff --git a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
index 5f2526d..a5196e7 100644
--- a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
+++ b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
@@ -36,6 +36,7 @@
#include "V8Document.h"
#include "V8FormData.h"
#include "V8HTMLDocument.h"
+#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Utilities.h"
#include "bindings/v8/custom/V8ArrayBufferCustom.h"
@@ -68,12 +69,10 @@
void V8XMLHttpRequest::responseTextAttrGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
- ExceptionCode ec = 0;
- ScriptValue text = xmlHttpRequest->responseText(ec);
- if (ec) {
- setDOMException(ec, info.GetIsolate());
+ ExceptionState es(info.GetIsolate());
+ ScriptValue text = xmlHttpRequest->responseText(es);
+ if (es.throwIfNeeded())
return;
- }
if (text.hasNoValue()) {
v8SetReturnValueString(info, emptyString(), info.GetIsolate());
return;
@@ -93,36 +92,30 @@
case XMLHttpRequest::ResponseTypeDocument:
{
- ExceptionCode ec = 0;
- Document* document = xmlHttpRequest->responseXML(ec);
- if (ec) {
- setDOMException(ec, info.GetIsolate());
+ ExceptionState es(info.GetIsolate());
+ Document* document = xmlHttpRequest->responseXML(es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(info, toV8Fast(document, info, xmlHttpRequest));
return;
}
case XMLHttpRequest::ResponseTypeBlob:
{
- ExceptionCode ec = 0;
- Blob* blob = xmlHttpRequest->responseBlob(ec);
- if (ec) {
- setDOMException(ec, info.GetIsolate());
+ ExceptionState es(info.GetIsolate());
+ Blob* blob = xmlHttpRequest->responseBlob(es);
+ if (es.throwIfNeeded())
return;
- }
v8SetReturnValue(info, toV8Fast(blob, info, xmlHttpRequest));
return;
}
case XMLHttpRequest::ResponseTypeArrayBuffer:
{
- ExceptionCode ec = 0;
- ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(ec);
- if (ec) {
- setDOMException(ec, info.GetIsolate());
+ ExceptionState es(info.GetIsolate());
+ ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(es);
+ if (es.throwIfNeeded())
return;
- }
if (arrayBuffer && !arrayBuffer->hasDeallocationObserver()) {
arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instance());
v8::V8::AdjustAmountOfExternalAllocatedMemory(arrayBuffer->byteLength());
@@ -154,7 +147,7 @@
ScriptExecutionContext* context = getScriptExecutionContext();
KURL url = context->completeURL(urlstring);
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
if (args.Length() >= 3) {
bool async = args[2]->BooleanValue();
@@ -164,17 +157,18 @@
if (args.Length() >= 5 && !args[4]->IsUndefined()) {
String passwd = toWebCoreStringWithNullCheck(args[4]);
- xmlHttpRequest->open(method, url, async, user, passwd, ec);
- } else
- xmlHttpRequest->open(method, url, async, user, ec);
- } else
- xmlHttpRequest->open(method, url, async, ec);
- } else
- xmlHttpRequest->open(method, url, ec);
+ xmlHttpRequest->open(method, url, async, user, passwd, es);
+ } else {
+ xmlHttpRequest->open(method, url, async, user, es);
+ }
+ } else {
+ xmlHttpRequest->open(method, url, async, es);
+ }
+ } else {
+ xmlHttpRequest->open(method, url, es);
+ }
- if (!ec)
- return;
- setDOMException(ec, args.GetIsolate());
+ es.throwIfNeeded();
}
static bool isDocumentType(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType)
@@ -189,47 +183,44 @@
InspectorInstrumentation::willSendXMLHttpRequest(xmlHttpRequest->scriptExecutionContext(), xmlHttpRequest->url());
- ExceptionCode ec = 0;
+ ExceptionState es(args.GetIsolate());
if (args.Length() < 1)
- xmlHttpRequest->send(ec);
+ xmlHttpRequest->send(es);
else {
v8::Handle<v8::Value> arg = args[0];
WrapperWorldType currentWorldType = worldType(args.GetIsolate());
if (isUndefinedOrNull(arg))
- xmlHttpRequest->send(ec);
+ xmlHttpRequest->send(es);
else if (isDocumentType(arg, args.GetIsolate(), currentWorldType)) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
Document* document = V8Document::toNative(object);
ASSERT(document);
- xmlHttpRequest->send(document, ec);
+ xmlHttpRequest->send(document, es);
} else if (V8Blob::HasInstance(arg, args.GetIsolate(), currentWorldType)) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
Blob* blob = V8Blob::toNative(object);
ASSERT(blob);
- xmlHttpRequest->send(blob, ec);
+ xmlHttpRequest->send(blob, es);
} else if (V8FormData::HasInstance(arg, args.GetIsolate(), currentWorldType)) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
DOMFormData* domFormData = V8FormData::toNative(object);
ASSERT(domFormData);
- xmlHttpRequest->send(domFormData, ec);
+ xmlHttpRequest->send(domFormData, es);
} else if (V8ArrayBuffer::HasInstance(arg, args.GetIsolate(), currentWorldType)) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(object);
ASSERT(arrayBuffer);
- xmlHttpRequest->send(arrayBuffer, ec);
+ xmlHttpRequest->send(arrayBuffer, es);
} else if (V8ArrayBufferView::HasInstance(arg, args.GetIsolate(), currentWorldType)) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(object);
ASSERT(arrayBufferView);
- xmlHttpRequest->send(arrayBufferView, ec);
+ xmlHttpRequest->send(arrayBufferView, es);
} else
- xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), ec);
+ xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), es);
}
- if (!ec)
- return;
-
- setDOMException(ec, args.GetIsolate());
+ es.throwIfNeeded();
}
} // namespace WebCore