Commit 85ab424b authored by dglazkov@chromium.org's avatar dglazkov@chromium.org

2009-07-27 Dimitri Glazkov <dglazkov@chromium.org>

        Reviewed by Dave Levin.

        [V8] Remove parameterless frame/window retrieval methods from V8Proxy.
        https://bugs.webkit.org/show_bug.cgi?id=27737

        Refactoring, no new behavior, covered by existing tests.

        * bindings/v8/ScriptCallStack.cpp:
        (WebCore::ScriptCallStack::ScriptCallStack):
        * bindings/v8/V8NPUtils.cpp:
        (convertV8ObjectToNPVariant): Ditto.
        * bindings/v8/V8Proxy.cpp:
        (WebCore::V8Proxy::retrieve): Ditto.
        (WebCore::V8Proxy::canAccessPrivate): Ditto.
        * bindings/v8/V8Proxy.h: Removed parameterless retrieveWindow/retrieveProxy decls.
        * bindings/v8/custom/V8DatabaseCustom.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Changed to use V8Proxy::retrieveFrameForCurrentContext().
        * bindings/v8/custom/V8HTMLAudioElementConstructor.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.
        * bindings/v8/custom/V8HTMLImageElementConstructor.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.
        * bindings/v8/custom/V8HTMLOptionElementConstructor.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.
        * bindings/v8/custom/V8MessageChannelConstructor.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.
        * bindings/v8/custom/V8SQLTransactionCustom.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.
        * bindings/v8/custom/V8WorkerCustom.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.
        * bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
        (WebCore::CALLBACK_FUNC_DECL): Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46435 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 08dd08e1
2009-07-27 Dimitri Glazkov <dglazkov@chromium.org>
Reviewed by Dave Levin.
[V8] Remove parameterless frame/window retrieval methods from V8Proxy.
https://bugs.webkit.org/show_bug.cgi?id=27737
Refactoring, no new behavior, covered by existing tests.
* bindings/v8/ScriptCallStack.cpp:
(WebCore::ScriptCallStack::ScriptCallStack):
* bindings/v8/V8NPUtils.cpp:
(convertV8ObjectToNPVariant): Ditto.
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::retrieve): Ditto.
(WebCore::V8Proxy::canAccessPrivate): Ditto.
* bindings/v8/V8Proxy.h: Removed parameterless retrieveWindow/retrieveProxy decls.
* bindings/v8/custom/V8DatabaseCustom.cpp:
(WebCore::CALLBACK_FUNC_DECL): Changed to use V8Proxy::retrieveFrameForCurrentContext().
* bindings/v8/custom/V8HTMLAudioElementConstructor.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
* bindings/v8/custom/V8HTMLImageElementConstructor.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
* bindings/v8/custom/V8HTMLOptionElementConstructor.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
* bindings/v8/custom/V8MessageChannelConstructor.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
* bindings/v8/custom/V8SQLTransactionCustom.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
* bindings/v8/custom/V8WorkerCustom.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
* bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
(WebCore::CALLBACK_FUNC_DECL): Ditto.
2009-07-27 Nikolas Zimmermann <nikolas.zimmermann@torchmobile.com>
Reviewed by George Staikos.
......
......@@ -40,7 +40,7 @@ namespace WebCore {
ScriptCallStack::ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount)
: m_lastCaller(String(), V8Proxy::sourceName(), V8Proxy::sourceLineNumber() + 1, arguments, skipArgumentCount)
, m_scriptState(new ScriptState(V8Proxy::retrieveFrame()))
, m_scriptState(new ScriptState(V8Proxy::retrieveFrameForCurrentContext()))
{
}
......
......@@ -68,7 +68,7 @@ void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NP
char* utf8_chars = strdup(*utf8);
STRINGN_TO_NPVARIANT(utf8_chars, utf8.length(), *result);
} else if (object->IsObject()) {
WebCore::DOMWindow* window = WebCore::V8Proxy::retrieveWindow();
WebCore::DOMWindow* window = WebCore::V8Proxy::retrieveWindow(WebCore::V8Proxy::currentContext());
NPObject* npobject = npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(object), window);
if (npobject)
_NPN_RegisterObject(npobject, owner);
......
......@@ -493,14 +493,6 @@ bool V8Proxy::isContextInitialized()
return !m_context.IsEmpty();
}
DOMWindow* V8Proxy::retrieveWindow()
{
// FIXME: This seems very fragile. How do we know that the global object
// from the current context is something sensible? Do we need to use the
// last entered here? Who calls this?
return retrieveWindow(v8::Context::GetCurrent());
}
DOMWindow* V8Proxy::retrieveWindow(v8::Handle<v8::Context> context)
{
v8::Handle<v8::Object> global = context->Global();
......@@ -539,15 +531,9 @@ Frame* V8Proxy::retrieveFrameForCallingContext()
return retrieveFrame(context);
}
Frame* V8Proxy::retrieveFrame()
{
DOMWindow* window = retrieveWindow();
return window ? window->frame() : 0;
}
V8Proxy* V8Proxy::retrieve()
{
DOMWindow* window = retrieveWindow();
DOMWindow* window = retrieveWindow(currentContext());
ASSERT(window);
return retrieve(window->frame());
}
......@@ -820,7 +806,7 @@ bool V8Proxy::canAccessPrivate(DOMWindow* targetWindow)
String message;
DOMWindow* originWindow = retrieveWindow();
DOMWindow* originWindow = retrieveWindow(currentContext());
if (originWindow == targetWindow)
return true;
......
......@@ -237,8 +237,6 @@ namespace WebCore {
// This is faster than going through the full object creation process.
v8::Local<v8::Object> createWrapperFromCache(V8ClassIndex::V8WrapperType);
// Returns the window object of the currently executing context.
static DOMWindow* retrieveWindow();
// Returns the window object associated with a context.
static DOMWindow* retrieveWindow(v8::Handle<v8::Context>);
// Returns V8Proxy object of the currently executing context.
......@@ -248,9 +246,6 @@ namespace WebCore {
// Returns V8Proxy object associated with a script execution context.
static V8Proxy* retrieve(ScriptExecutionContext*);
// Returns the frame object of the window object associated
// with the currently executing context.
static Frame* retrieveFrame();
// Returns the frame object of the window object associated with
// a context.
static Frame* retrieveFrame(v8::Handle<v8::Context>);
......
......@@ -52,37 +52,33 @@ CALLBACK_FUNC_DECL(DatabaseTransaction)
{
INC_STATS("DOM.Database.transaction()");
if (args.Length() == 0) {
V8Proxy::throwError(V8Proxy::SyntaxError, "Transaction callback is required.");
return v8::Undefined();
}
if (!args.Length())
return throwError("Transaction callback is required.", V8Proxy::SyntaxError);
if (!args[0]->IsObject()) {
V8Proxy::throwError(V8Proxy::TypeError, "Transaction callback must be of valid type.");
return v8::Undefined();
}
if (!args[0]->IsObject())
return throwError("Transaction callback must be of valid type.");
Database* database = V8DOMWrapper::convertToNativeObject<Database>(V8ClassIndex::DATABASE, args.Holder());
Frame* frame = V8Proxy::retrieveFrame();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return v8::Undefined();
RefPtr<V8CustomSQLTransactionCallback> callback = V8CustomSQLTransactionCallback::create(args[0], frame);
RefPtr<V8CustomSQLTransactionErrorCallback> errorCallback;
if (args.Length() > 1) {
if (!args[1]->IsObject()) {
V8Proxy::throwError(V8Proxy::TypeError, "Transaction error callback must be of valid type.");
return v8::Undefined();
}
if (!args[1]->IsObject())
return throwError("Transaction error callback must be of valid type.");
errorCallback = V8CustomSQLTransactionErrorCallback::create(args[1], frame);
}
RefPtr<V8CustomVoidCallback> successCallback;
if (args.Length() > 2) {
if (!args[1]->IsObject()) {
V8Proxy::throwError(V8Proxy::TypeError, "Transaction success callback must be of valid type.");
return v8::Undefined();
}
if (!args[1]->IsObject())
return throwError("Transaction success callback must be of valid type.");
successCallback = V8CustomVoidCallback::create(args[2], frame);
}
......
......@@ -49,7 +49,11 @@ CALLBACK_FUNC_DECL(HTMLAudioElementConstructor)
if (!args.IsConstructCall())
return throwError("DOM object constructor cannot be called as a function.");
Document* document = V8Proxy::retrieveFrame()->document();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return throwError("Audio constructor associated frame is unavailable", V8Proxy::ReferenceError);
Document* document = frame->document();
if (!document)
return throwError("Audio constructor associated document is unavailable", V8Proxy::ReferenceError);
......@@ -57,7 +61,7 @@ CALLBACK_FUNC_DECL(HTMLAudioElementConstructor)
// may end up being the only node in the map and get garbage-ccollected prematurely.
V8DOMWrapper::convertNodeToV8Object(document);
RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, V8Proxy::retrieveFrame()->document());
RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, document);
if (args.Length() > 0)
audio->setSrc(toWebCoreString(args[0]));
......
......@@ -49,7 +49,11 @@ CALLBACK_FUNC_DECL(HTMLImageElementConstructor)
if (!args.IsConstructCall())
return throwError("DOM object constructor cannot be called as a function.");
Document* document = V8Proxy::retrieveFrame()->document();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return throwError("Image constructor associated frame is unavailable", V8Proxy::ReferenceError);
Document* document = frame->document();
if (!document)
return throwError("Image constructor associated document is unavailable", V8Proxy::ReferenceError);
......@@ -57,7 +61,7 @@ CALLBACK_FUNC_DECL(HTMLImageElementConstructor)
// may end up being the only node in the map and get garbage-ccollected prematurely.
V8DOMWrapper::convertNodeToV8Object(document);
RefPtr<HTMLImageElement> image = new HTMLImageElement(HTMLNames::imgTag, V8Proxy::retrieveFrame()->document());
RefPtr<HTMLImageElement> image = new HTMLImageElement(HTMLNames::imgTag, document);
if (args.Length() > 0) {
image->setWidth(toInt32(args[0]));
if (args.Length() > 1)
......
......@@ -50,11 +50,15 @@ CALLBACK_FUNC_DECL(HTMLOptionElementConstructor)
if (!args.IsConstructCall())
return throwError("DOM object constructor cannot be called as a function.");
Document* document = V8Proxy::retrieveFrame()->document();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return throwError("Option constructor associated frame is unavailable", V8Proxy::ReferenceError);
Document* document = frame->document();
if (!document)
return throwError("Option constructor associated document is unavailable", V8Proxy::ReferenceError);
RefPtr<HTMLOptionElement> option = new HTMLOptionElement(HTMLNames::optionTag, V8Proxy::retrieveFrame()->document());
RefPtr<HTMLOptionElement> option = new HTMLOptionElement(HTMLNames::optionTag, document);
ExceptionCode ec = 0;
RefPtr<Text> text = document->createTextNode("");
......
......@@ -57,7 +57,7 @@ CALLBACK_FUNC_DECL(MessageChannelConstructor)
if (proxy)
context = proxy->workerContext();
else {
Frame* frame = V8Proxy::retrieveFrame();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return v8::Undefined();
context = frame->document();
......
......@@ -81,7 +81,7 @@ CALLBACK_FUNC_DECL(SQLTransactionExecuteSql)
SQLTransaction* transaction = V8DOMWrapper::convertToNativeObject<SQLTransaction>(V8ClassIndex::SQLTRANSACTION, args.Holder());
Frame* frame = V8Proxy::retrieveFrame();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
RefPtr<SQLStatementCallback> callback;
if (args.Length() > 2) {
......
......@@ -70,7 +70,7 @@ CALLBACK_FUNC_DECL(WorkerConstructor)
if (proxy)
context = proxy->workerContext();
else {
Frame* frame = V8Proxy::retrieveFrame();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return v8::Undefined();
context = frame->document();
......
......@@ -55,9 +55,15 @@ CALLBACK_FUNC_DECL(XMLHttpRequestConstructor)
WorkerContextExecutionProxy* proxy = WorkerContextExecutionProxy::retrieve();
if (proxy)
context = proxy->workerContext();
else
else {
#endif
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return throwError("XMLHttpRequest constructor's associated frame is not available", V8Proxy::ReferenceError);
context = frame->document();
#if ENABLE(WORKERS)
}
#endif
context = V8Proxy::retrieveFrame()->document();
RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context);
V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::XMLHTTPREQUEST), xmlHttpRequest.get());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment