Commit 2fcbd0eb authored by dglazkov@chromium.org's avatar dglazkov@chromium.org

2009-04-15 Dimitri Glazkov <dglazkov@chromium.org>

        Reviewed by Darin Fisher.

        https://bugs.webkit.org/show_bug.cgi?id=25201
        Add ScriptFunctionCall/ScriptObject for V8.

        * bindings/v8/ScriptFunctionCall.cpp: Added.
        * bindings/v8/ScriptFunctionCall.h: Added.
        * bindings/v8/ScriptObject.cpp: Added.
        * bindings/v8/ScriptObject.h: Added.
        * bindings/v8/ScriptObjectQuarantine.cpp: Added.
        * bindings/v8/ScriptObjectQuarantine.h: Added.
        * bindings/v8/ScriptScope.cpp: Added.
        * bindings/v8/ScriptScope.h: Added.
        * bindings/v8/ScriptState.h:
        (WebCore::ScriptState::ScriptState): Added new constructors.
        (WebCore::ScriptState::frame): Added Frame ptr accessor.
        * bindings/v8/ScriptString.h:
        (WebCore::ScriptString::ScriptString): Added default constructor.
        * bindings/v8/ScriptValue.h:
        (WebCore::ScriptValue::isEqual): Added.

git-svn-id: svn://svn.chromium.org/blink/trunk@42568 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 5de57653
2009-04-15 Dimitri Glazkov <dglazkov@chromium.org>
Reviewed by Darin Fisher.
https://bugs.webkit.org/show_bug.cgi?id=25201
Add ScriptFunctionCall/ScriptObject for V8.
* bindings/v8/ScriptFunctionCall.cpp: Added.
* bindings/v8/ScriptFunctionCall.h: Added.
* bindings/v8/ScriptObject.cpp: Added.
* bindings/v8/ScriptObject.h: Added.
* bindings/v8/ScriptObjectQuarantine.cpp: Added.
* bindings/v8/ScriptObjectQuarantine.h: Added.
* bindings/v8/ScriptScope.cpp: Added.
* bindings/v8/ScriptScope.h: Added.
* bindings/v8/ScriptState.h:
(WebCore::ScriptState::ScriptState): Added new constructors.
(WebCore::ScriptState::frame): Added Frame ptr accessor.
* bindings/v8/ScriptString.h:
(WebCore::ScriptString::ScriptString): Added default constructor.
* bindings/v8/ScriptValue.h:
(WebCore::ScriptValue::isEqual): Added.
2009-04-15 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> 2009-04-15 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>
Unreviewed build fix. Add RenderSVGModelObject.* to GTK+'s build. Unreviewed build fix. Add RenderSVGModelObject.* to GTK+'s build.
/*
* Copyright (C) 2009 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
* 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 "ScriptFunctionCall.h"
#include "Document.h"
#include "Frame.h"
#include "ScriptScope.h"
#include "ScriptState.h"
#include "ScriptString.h"
#include "ScriptValue.h"
#include "V8Binding.h"
#include "V8Proxy.h"
#include <v8.h>
#include <wtf/OwnArrayPtr.h>
namespace WebCore {
static void reportException(ScriptState* scriptState, v8::TryCatch &exceptionCatcher)
{
v8::Local<v8::Message> message = exceptionCatcher.Message();
scriptState->frame()->document()->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName()));
exceptionCatcher.Reset();
}
ScriptFunctionCall::ScriptFunctionCall(ScriptState* scriptState, const ScriptObject& thisObject, const String& name)
: m_scriptState(scriptState)
, m_thisObject(thisObject)
, m_name(name)
{
}
void ScriptFunctionCall::appendArgument(const ScriptObject& argument)
{
m_arguments.append(argument);
}
void ScriptFunctionCall::appendArgument(const ScriptString& argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8String(argument));
}
void ScriptFunctionCall::appendArgument(const ScriptValue& argument)
{
m_arguments.append(argument);
}
void ScriptFunctionCall::appendArgument(const String& argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8String(argument));
}
void ScriptFunctionCall::appendArgument(long long argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
void ScriptFunctionCall::appendArgument(unsigned int argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
void ScriptFunctionCall::appendArgument(int argument)
{
ScriptScope scope(m_scriptState);
m_arguments.append(v8::Number::New(argument));
}
void ScriptFunctionCall::appendArgument(bool argument)
{
m_arguments.append(v8Boolean(argument));
}
ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions)
{
ScriptScope scope(m_scriptState, reportExceptions);
v8::Local<v8::Object> thisObject = m_thisObject.v8Object();
v8::Local<v8::Value> value = thisObject->Get(v8String(m_name));
if (!scope.success()) {
hadException = true;
return ScriptValue();
}
ASSERT(value->IsFunction());
v8::Local<v8::Function> function(v8::Function::Cast(*value));
OwnArrayPtr<v8::Handle<v8::Value> > args(new v8::Handle<v8::Value>[m_arguments.size()]);
for (size_t i = 0; i < m_arguments.size(); ++i)
args[i] = m_arguments[i].v8Value();
v8::Local<v8::Value> result = function->Call(thisObject, m_arguments.size(), args.get());
if (!scope.success()) {
hadException = true;
return ScriptValue();
}
return ScriptValue(result);
}
ScriptValue ScriptFunctionCall::call()
{
bool hadException = false;
return call(hadException);
}
ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExceptions)
{
ScriptScope scope(m_scriptState, reportExceptions);
v8::Local<v8::Object> thisObject = m_thisObject.v8Object();
v8::Local<v8::Value> value = thisObject->Get(v8String(m_name));
if (!scope.success()) {
hadException = true;
return ScriptObject();
}
ASSERT(value->IsFunction());
v8::Local<v8::Function> constructor(v8::Function::Cast(*value));
OwnArrayPtr<v8::Handle<v8::Value> > args(new v8::Handle<v8::Value>[m_arguments.size()]);
for (size_t i = 0; i < m_arguments.size(); ++i)
args[i] = m_arguments[i].v8Value();
v8::Local<v8::Object> result = SafeAllocation::NewInstance(constructor, m_arguments.size(), args.get());
if (!scope.success()) {
hadException = true;
return ScriptObject();
}
return ScriptObject(result);
}
} // namespace WebCore
/*
* Copyright (C) 2009 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
* 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 ScriptFunctionCall_h
#define ScriptFunctionCall_h
#include "PlatformString.h"
#include "ScriptObject.h"
#include <wtf/Vector.h>
namespace WebCore {
class ScriptValue;
class ScriptState;
class ScriptString;
class ScriptFunctionCall {
public:
ScriptFunctionCall(ScriptState* scriptState, const ScriptObject& thisObject, const String& name);
virtual ~ScriptFunctionCall() {};
void appendArgument(const ScriptObject&);
void appendArgument(const ScriptString&);
void appendArgument(const ScriptValue&);
void appendArgument(const String&);
void appendArgument(long long);
void appendArgument(unsigned int);
void appendArgument(int);
void appendArgument(bool);
ScriptValue call(bool& hadException, bool reportExceptions = true);
ScriptValue call();
ScriptObject construct(bool& hadException, bool reportExceptions = true);
protected:
ScriptState* m_scriptState;
ScriptObject m_thisObject;
String m_name;
Vector<ScriptValue> m_arguments;
};
} // namespace WebCore
#endif // ScriptFunctionCall
/*
* Copyright (C) 2009 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
* 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 "ScriptObject.h"
#include "ScriptScope.h"
#include "ScriptState.h"
#include "Document.h"
#include "Frame.h"
#include "V8Binding.h"
#include "V8Proxy.h"
#include <v8.h>
namespace WebCore {
ScriptObject::ScriptObject(v8::Handle<v8::Object> v8Object)
: ScriptValue(v8Object)
{
}
v8::Local<v8::Object> ScriptObject::v8Object() const
{
ASSERT(v8Value()->IsObject());
return v8::Local<v8::Object>(v8::Object::Cast(*v8Value()));
}
bool ScriptObject::set(ScriptState* scriptState, const String& name, const String& value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8String(name), v8String(value));
return scope.success();
}
bool ScriptObject::set(ScriptState* scriptState, const char* name, const ScriptObject& value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8::String::New(name), value.v8Value());
return scope.success();
}
bool ScriptObject::set(ScriptState* scriptState, const char* name, const String& value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8::String::New(name), v8String(value));
return scope.success();
}
bool ScriptObject::set(ScriptState* scriptState, const char* name, double value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8::String::New(name), v8::Number::New(value));
return scope.success();
}
bool ScriptObject::set(ScriptState* scriptState, const char* name, long long value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8::String::New(name), v8::Number::New(value));
return scope.success();
}
bool ScriptObject::set(ScriptState* scriptState, const char* name, int value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8::String::New(name), v8::Number::New(value));
return scope.success();
}
bool ScriptObject::set(ScriptState* scriptState, const char* name, bool value)
{
ScriptScope scope(scriptState);
v8Object()->Set(v8::String::New(name), v8Boolean(value));
return scope.success();
}
ScriptObject ScriptObject::createNew(ScriptState* scriptState)
{
ScriptScope scope(scriptState);
return ScriptObject(v8::Object::New());
}
bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, const ScriptObject& value)
{
ScriptScope scope(scriptState);
scope.global()->Set(v8::String::New(name), value.v8Value());
return scope.success();
}
bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, InspectorController* value)
{
ScriptScope scope(scriptState);
scope.global()->Set(v8::String::New(name), V8Proxy::ToV8Object(V8ClassIndex::INSPECTORCONTROLLER, value));
return scope.success();
}
bool ScriptGlobalObject::getObject(ScriptState* scriptState, const char* name, ScriptObject& value)
{
ScriptScope scope(scriptState);
v8::Local<v8::Value> v8Value = scope.global()->Get(v8::String::New(name));
if (v8Value.IsEmpty())
return false;
if (!v8Value->IsObject())
return false;
value = ScriptObject(v8::Handle<v8::Object>(v8::Object::Cast(*v8Value)));
return true;
}
} // namespace WebCore
/*
* Copyright (C) 2009 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
* 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 ScriptObject_h
#define ScriptObject_h
#include "ScriptValue.h"
#include <v8.h>
namespace WebCore {
class InspectorController;
class ScriptState;
class ScriptObject : public ScriptValue {
public:
ScriptObject(v8::Handle<v8::Object>);
ScriptObject() {}
virtual ~ScriptObject() {}
v8::Local<v8::Object> v8Object() const;
bool set(ScriptState*, const String& name, const String&);
bool set(ScriptState*, const char* name, const ScriptObject&);
bool set(ScriptState*, const char* name, const String&);
bool set(ScriptState*, const char* name, double);
bool set(ScriptState*, const char* name, long long);
bool set(ScriptState*, const char* name, int);
bool set(ScriptState*, const char* name, bool);
static ScriptObject createNew(ScriptState*);
};
class ScriptGlobalObject {
public:
static bool set(ScriptState*, const char* name, const ScriptObject&);
static bool set(ScriptState*, const char* name, InspectorController*);
static bool getObject(ScriptState*, const char* name, ScriptObject&);
private:
ScriptGlobalObject() { }
};
}
#endif // ScriptObject_h
/*
* Copyright (C) 2009 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
* 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 "ScriptObjectQuarantine.h"
#include "Database.h"
#include "Document.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "Page.h"
#include "ScriptObject.h"
#include "ScriptValue.h"
#include "V8Binding.h"
#include "V8Proxy.h"
#include <v8.h>
namespace WebCore {
ScriptValue quarantineValue(ScriptState* scriptState, const ScriptValue& value)
{
return value;
}
bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject)
{
ASSERT(database);
// FIXME: Implement when Database V8 bindings are enabled
ASSERT_NOT_REACHED();
quarantinedObject = ScriptObject();
return false;
}
bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject)
{
ASSERT(frame);
ASSERT(storage);
// FIXME: Implement when DOM Storage V8 bindings are enabled
ASSERT_NOT_REACHED();
quarantinedObject = ScriptObject();
return true;
}
bool getQuarantinedScriptObject(Node* node, ScriptObject& quarantinedObject)
{
ASSERT(node);
v8::HandleScope handleScope;
v8::Local<v8::Context> context = V8Proxy::GetContext(node->document()->page()->mainFrame());
v8::Context::Scope scope(context);
v8::Handle<v8::Value> v8Node = V8Proxy::NodeToV8Object(node);
quarantinedObject = ScriptObject(v8::Local<v8::Object>(v8::Object::Cast(*v8Node)));
return true;
}
bool getQuarantinedScriptObject(DOMWindow* domWindow, ScriptObject& quarantinedObject)
{
ASSERT(domWindow);
v8::HandleScope handleScope;
v8::Local<v8::Context> context = V8Proxy::GetContext(domWindow->frame());
v8::Context::Scope scope(context);
v8::Handle<v8::Value> v8DomWindow = V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, domWindow);
quarantinedObject = ScriptObject(v8::Local<v8::Object>(v8::Object::Cast(*v8DomWindow)));
return true;
}
} // namespace WebCore
/*
* Copyright (C) 2009 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
* 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.
*/
// ScriptObjectQuarantine is used in JSC for wrapping DOM objects of the page
// before they are passed to Inspector's front-end. The wrapping prevents
// malicious scripts from gaining privileges. For V8, we are currently just
// passing the object itself, without any wrapping.
#ifndef ScriptObjectQuarantine_h
#define ScriptObjectQuarantine_h
#include "ScriptState.h"
namespace WebCore {
class Database;
class DOMWindow;
class Frame;
class Node;
class ScriptObject;
class ScriptValue;
class Storage;
ScriptValue quarantineValue(ScriptState*, const ScriptValue&);
bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject);
bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject);
bool getQuarantinedScriptObject(Node* node, ScriptObject& quarantinedObject);
bool getQuarantinedScriptObject(DOMWindow* domWindow, ScriptObject& quarantinedObject);
}
#endif // ScriptObjectQuarantine_h
/*
* Copyright (C) 2009 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
* 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 "ScriptScope.h"
#include "ScriptState.h"
#include "Document.h"
#include "Frame.h"
#include "V8Binding.h"
#include "V8Proxy.h"
#include <v8.h>
namespace WebCore {
ScriptScope::ScriptScope(ScriptState* scriptState, bool reportExceptions)
: m_context(V8Proxy::GetContext(scriptState->frame()))
, m_scope(m_context)
, m_scriptState(scriptState)
, m_reportExceptions(reportExceptions)
{
ASSERT(!m_context.IsEmpty());
}
bool ScriptScope::success()
{
if (!m_exceptionCatcher.HasCaught())
return true;
v8::Local<v8::Message> message = m_exceptionCatcher.Message();
if (m_reportExceptions)
m_scriptState->frame()->document()->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName()));
m_exceptionCatcher.Reset();
return false;
}
} // namespace WebCore
/*
* Copyright (C) 2009 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
* 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 ScriptScope_h
#define ScriptScope_h
#include <v8.h>
namespace WebCore {
class ScriptState;
class ScriptScope {
public:
ScriptScope(ScriptState* scriptState, bool reportExceptions = true);
bool success();
v8::Local<v8::Object> global() const { return m_context->Global(); }
private:
v8::HandleScope m_handleScope;
v8::Local<v8::Context> m_context;
v8::Context::Scope m_scope;
v8::TryCatch m_exceptionCatcher;
ScriptState* m_scriptState;
bool m_reportExceptions;
};
}
#endif // ScriptScope_h
/*
* Copyright (C) 2009 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
* 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 "ScriptState.h"
#include "Frame.h"
#include "Page.h"
#include "ScriptController.h"
namespace WebCore {
ScriptState::ScriptState(Frame* frame)
: m_frame(frame)
{
}
ScriptState* scriptStateFromPage(Page* page)
{
return page->mainFrame()->script()->state();
}
}
...@@ -34,8 +34,14 @@ ...@@ -34,8 +34,14 @@
#include <v8.h> #include <v8.h>
namespace WebCore { namespace WebCore {
class Page;
class Frame;
class ScriptState { class ScriptState {
public: public:
ScriptState() { }
ScriptState(Frame* frame);
bool hadException() { return !m_exception.IsEmpty(); } bool hadException() { return !m_exception.IsEmpty(); }
void setException(v8::Local<v8::Value> exception) void setException(v8::Local<v8::Value> exception)
{ {
...@@ -43,9 +49,14 @@ namespace WebCore { ...@@ -43,9 +49,14 @@ namespace WebCore {
} }
v8::Local<v8::Value> exception() { return m_exception; } v8::Local<v8::Value> exception() { return m_exception; }
Frame* frame() const { return m_frame; }
private: private:
v8::Local<v8::Value> m_exception; v8::Local<v8::Value> m_exception;
Frame* m_frame;
}; };
ScriptState* scriptStateFromPage(Page* page);
} }
#endif // ScriptState_h #endif // ScriptState_h
...@@ -37,6 +37,7 @@ namespace WebCore { ...@@ -37,6 +37,7 @@ namespace WebCore {
class ScriptString { class ScriptString {
public: public:
ScriptString() {}
ScriptString(const String& s) : m_str(s) {} ScriptString(const String& s) : m_str(s) {}
ScriptString(const char* s) : m_str(s) {} ScriptString(const char* s) : m_str(s) {}
......
...@@ -91,6 +91,11 @@ public: ...@@ -91,6 +91,11 @@ public:
return m_value == value.m_value; return m_value == value.m_value;
} }
bool isEqual(ScriptState*, const ScriptValue& value) const
{
return m_value == value.m_value;
}
bool operator!=(const ScriptValue value) const bool operator!=(const ScriptValue value) const
{ {
return !operator==(value); return !operator==(value);
......
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