https://bugs.webkit.org/show_bug.cgi?id=52871
Reviewed by Adam Barth and Oliver Hunt.
Source/WebCore:
Test: http/tests/workers/worker-importScriptsOnError.html
* bindings/js/WorkerScriptController.cpp:
(WebCore::WorkerScriptController::evaluate): Use sanitizeScriptError
to determine when to create a clean exception.
* bindings/v8/WorkerContextExecutionProxy.cpp:
(WebCore::WorkerContextExecutionProxy::evaluate): Ditto.
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::sanitizeScriptError): Figure out
if the error needs to be cleaned up.
(WebCore::ScriptExecutionContext::dispatchErrorEvent): Extracted
sanitizeScriptError for use by other places.
* dom/ScriptExecutionContext.h:
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::importScripts): Use the reponse url when
telling the evaluate where the script came fro.
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::responseURL): Expose the url that
the script was loaded from (which may be different from url() due
to redirects).
(WebCore::WorkerScriptLoader::didReceiveResponse): Capture the reponse url.
* workers/WorkerScriptLoader.h:
LayoutTests:
* http/tests/workers/resources/worker-importScripts-error.js: Added.
* http/tests/workers/resources/worker-importScripts-throw.js: Added.
* http/tests/workers/worker-importScriptsOnError.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77563
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2011-02-03 David Levin <levin@chromium.org>
+
+ Reviewed by Adam Barth.
+
+ Worker.importScript() should clean errors for cross origin imports.
+ https://bugs.webkit.org/show_bug.cgi?id=52871
+
+ * http/tests/workers/resources/worker-importScripts-error.js: Added.
+ * http/tests/workers/resources/worker-importScripts-throw.js: Added.
+ * http/tests/workers/worker-importScriptsOnError.html: Added.
+
2011-02-03 Mihai Parparita <mihaip@chromium.org>
Reviewed by Alexey Proskuryakov.
--- /dev/null
+var differentRedirectOrigin = "/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-importScripts-throw.js";
+importScripts(differentRedirectOrigin)
--- /dev/null
+throw("This is a custom error message.");
--- /dev/null
+Test importScripts with error.
+
+
+AT_TARGET: 2,
+BLUR: 8192,
+BUBBLING_PHASE: 3,
+CAPTURING_PHASE: 1,
+CHANGE: 32768,
+CLICK: 64,
+DBLCLICK: 128,
+DRAGDROP: 2048,
+FOCUS: 4096,
+KEYDOWN: 256,
+KEYPRESS: 1024,
+KEYUP: 512,
+MOUSEDOWN: 1,
+MOUSEDRAG: 32,
+MOUSEMOVE: 16,
+MOUSEOUT: 8,
+MOUSEOVER: 4,
+MOUSEUP: 2,
+SELECT: 16384,
+bubbles: false,
+cancelBubble: false,
+cancelable: true,
+clipboardData: undefined,
+currentTarget: [object Worker],
+defaultPrevented: false,
+eventPhase: 2,
+filename: http://127.0.0.1:8000/workers/resources/worker-importScripts-error.js,
+initErrorEvent: function initErrorEvent() { [native code] },
+initEvent: function initEvent() { [native code] },
+lineno: 2,
+message: Error: Script error.,
+preventDefault: function preventDefault() { [native code] },
+returnValue: true,
+srcElement: [object Worker],
+stopImmediatePropagation: function stopImmediatePropagation() { [native code] },
+stopPropagation: function stopPropagation() { [native code] },
+target: [object Worker],
+type: error
+
--- /dev/null
+<body>
+<p>Test importScripts with error.</p>
+<div id=result></div>
+<script>
+function log(message)
+{
+ document.getElementById("result").innerHTML += message + "<br>";
+}
+
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ layoutTestController.waitUntilDone();
+}
+
+var worker = new Worker('resources/worker-importScripts-error.js');
+
+worker.onerror = function(error)
+{
+ var properties = [];
+ for (property in error) {
+ if (property == 'timeStamp')
+ continue;
+ properties.push('<br/>' + property + ': ' + error[property]);
+ }
+ properties.sort();
+ log(properties);
+ if (window.layoutTestController)
+ layoutTestController.notifyDone();
+}
+</script>
+</body>
+</html>
+2011-02-03 David Levin <levin@chromium.org>
+
+ Reviewed by Adam Barth and Oliver Hunt.
+
+ Worker.importScript() should clean errors for cross origin imports.
+ https://bugs.webkit.org/show_bug.cgi?id=52871
+
+ Test: http/tests/workers/worker-importScriptsOnError.html
+
+ * bindings/js/WorkerScriptController.cpp:
+ (WebCore::WorkerScriptController::evaluate): Use sanitizeScriptError
+ to determine when to create a clean exception.
+ * bindings/v8/WorkerContextExecutionProxy.cpp:
+ (WebCore::WorkerContextExecutionProxy::evaluate): Ditto.
+ * dom/ScriptExecutionContext.cpp:
+ (WebCore::ScriptExecutionContext::sanitizeScriptError): Figure out
+ if the error needs to be cleaned up.
+ (WebCore::ScriptExecutionContext::dispatchErrorEvent): Extracted
+ sanitizeScriptError for use by other places.
+ * dom/ScriptExecutionContext.h:
+ * workers/WorkerContext.cpp:
+ (WebCore::WorkerContext::importScripts): Use the reponse url when
+ telling the evaluate where the script came fro.
+ * workers/WorkerScriptLoader.cpp:
+ (WebCore::WorkerScriptLoader::responseURL): Expose the url that
+ the script was loaded from (which may be different from url() due
+ to redirects).
+ (WebCore::WorkerScriptLoader::didReceiveResponse): Capture the reponse url.
+ * workers/WorkerScriptLoader.h:
+
2011-02-03 Mark Mentovai <mark@chromium.org>
Reviewed by Dimitri Glazkov.
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2011 Google Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
if (comp.complType() == Normal || comp.complType() == ReturnValue)
return comp.value();
- if (comp.complType() == Throw)
- *exception = comp.value();
+ if (comp.complType() == Throw) {
+ String errorMessage;
+ int lineNumber = 0;
+ String sourceURL = sourceCode.url().string();
+ if (m_workerContext->sanitizeScriptError(errorMessage, lineNumber, sourceURL))
+ *exception = ScriptValue(throwError(exec, createError(exec, errorMessage.impl())));
+ else
+ *exception = comp.value();
+ }
return JSValue();
}
/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
if (exceptionCatcher.HasCaught()) {
v8::Local<v8::Message> message = exceptionCatcher.Message();
state->hadException = true;
- state->exception = ScriptValue(exceptionCatcher.Exception());
state->errorMessage = toWebCoreString(message->Get());
state->lineNumber = message->GetLineNumber();
state->sourceURL = toWebCoreString(message->GetScriptResourceName());
+ if (m_workerContext->sanitizeScriptError(state->errorMessage, state->lineNumber, state->sourceURL))
+ state->exception = V8Proxy::throwError(V8Proxy::GeneralError, state->errorMessage.utf8().data());
+ else
+ state->exception = ScriptValue(exceptionCatcher.Exception());
+
exceptionCatcher.Reset();
} else
state->hadException = false;
m_securityOrigin = securityOrigin;
}
+bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& lineNumber, String& sourceURL)
+{
+ KURL targetURL = completeURL(sourceURL);
+ if (securityOrigin()->canRequest(targetURL))
+ return false;
+ errorMessage = "Script error.";
+ sourceURL = String();
+ lineNumber = 0;
+ return true;
+}
+
void ScriptExecutionContext::reportException(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack)
{
if (m_inDispatchErrorEvent) {
if (!target)
return false;
- String message;
- int line;
- String sourceName;
- KURL targetUrl = completeURL(sourceURL);
- if (securityOrigin()->canRequest(targetUrl)) {
- message = errorMessage;
- line = lineNumber;
- sourceName = sourceURL;
- } else {
- message = "Script error.";
- sourceName = String();
- line = 0;
- }
+ String message = errorMessage;
+ int line = lineNumber;
+ String sourceName = sourceURL;
+ sanitizeScriptError(message, line, sourceName);
ASSERT(!m_inDispatchErrorEvent);
m_inDispatchErrorEvent = true;
SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
+ bool sanitizeScriptError(String& errorMessage, int& lineNumber, String& sourceURL);
void reportException(const String& errorMessage, int lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>);
virtual void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>) = 0;
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
- * Copyright (C) 2009 Google Inc. All Rights Reserved.
+ * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
InspectorInstrumentation::scriptImported(scriptExecutionContext(), scriptLoader.identifier(), scriptLoader.script());
ScriptValue exception;
- m_script->evaluate(ScriptSourceCode(scriptLoader.script(), *it), &exception);
+ m_script->evaluate(ScriptSourceCode(scriptLoader.script(), scriptLoader.responseURL()), &exception);
if (!exception.hasNoValue()) {
m_script->setException(exception);
return;
/*
* Copyright (C) 2009 Apple Inc. All Rights Reserved.
- * Copyright (C) 2009 Google Inc. All Rights Reserved.
+ * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, this, *request, options);
}
+const KURL& WorkerScriptLoader::responseURL() const
+{
+ ASSERT(!failed());
+ return m_responseURL;
+}
+
PassOwnPtr<ResourceRequest> WorkerScriptLoader::createResourceRequest()
{
OwnPtr<ResourceRequest> request(new ResourceRequest(m_url));
m_failed = true;
return;
}
+ m_responseURL = response.url();
m_responseEncoding = response.textEncodingName();
if (m_client)
m_client->didReceiveResponse(response);
/*
* Copyright (C) 2009 Apple Inc. All Rights Reserved.
- * Copyright (C) 2009 Google Inc. All Rights Reserved.
+ * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
const String& script() const { return m_script; }
const KURL& url() const { return m_url; }
+ const KURL& responseURL() const;
bool failed() const { return m_failed; }
unsigned long identifier() const { return m_identifier; }
RefPtr<TextResourceDecoder> m_decoder;
String m_script;
KURL m_url;
+ KURL m_responseURL;
bool m_failed;
unsigned long m_identifier;
ResourceRequestBase::TargetType m_targetType;