Commit c2cc39ca authored by darin@chromium.org's avatar darin@chromium.org
Browse files

2010-05-19 Darin Fisher <darin@chromium.org>

        Revert r59790 due to failing Chromium npruntime tests.

        * bindings/v8/NPV8Object.cpp:
        (v8ObjectToNPObject):
        (npCreateV8ScriptObject):
        (_NPN_Invoke):
        (_NPN_InvokeDefault):
        (_NPN_Evaluate):
        (_NPN_EvaluateHelper):
        (_NPN_GetProperty):
        (_NPN_SetProperty):
        (_NPN_RemoveProperty):
        (_NPN_HasProperty):
        (_NPN_HasMethod):
        (_NPN_SetException):
        (_NPN_Enumerate):
        (_NPN_Construct):
        * bindings/v8/NPV8Object.h:
        * bindings/v8/V8NPObject.cpp:
        (forgetV8ObjectForNPObject):
        * bindings/v8/V8NPObject.h:
        * bindings/v8/V8NPUtils.cpp:
        (convertV8ObjectToNPVariant):
        (getStringIdentifier):
        * bindings/v8/V8NPUtils.h:
        * bindings/v8/npruntime.cpp:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@59814 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 48ade0ed
2010-05-19 Darin Fisher <darin@chromium.org>
Revert r59790 due to failing Chromium npruntime tests.
* bindings/v8/NPV8Object.cpp:
(v8ObjectToNPObject):
(npCreateV8ScriptObject):
(_NPN_Invoke):
(_NPN_InvokeDefault):
(_NPN_Evaluate):
(_NPN_EvaluateHelper):
(_NPN_GetProperty):
(_NPN_SetProperty):
(_NPN_RemoveProperty):
(_NPN_HasProperty):
(_NPN_HasMethod):
(_NPN_SetException):
(_NPN_Enumerate):
(_NPN_Construct):
* bindings/v8/NPV8Object.h:
* bindings/v8/V8NPObject.cpp:
(forgetV8ObjectForNPObject):
* bindings/v8/V8NPObject.h:
* bindings/v8/V8NPUtils.cpp:
(convertV8ObjectToNPVariant):
(getStringIdentifier):
* bindings/v8/V8NPUtils.h:
* bindings/v8/npruntime.cpp:
2010-05-19 Gavin Barraclough <barraclough@apple.com>
 
Rubber Stamped by Sam Weinig.
......@@ -52,7 +52,13 @@
#include <v8.h>
#include <wtf/StringExtras.h>
using namespace WebCore;
using WebCore::npObjectInternalFieldCount;
using WebCore::toV8Context;
using WebCore::toV8Proxy;
using WebCore::V8DOMWrapper;
using WebCore::V8GCController;
using WebCore::V8Proxy;
using WebCore::WrapperTypeInfo;
namespace WebCore {
......@@ -62,6 +68,8 @@ WrapperTypeInfo* npObjectTypeInfo()
return &typeInfo;
}
}
// FIXME: Comments on why use malloc and free.
static NPObject* allocV8NPObject(NPP, NPClass*)
{
......@@ -102,7 +110,7 @@ static v8::Local<v8::String> npIdentifierToV8Identifier(NPIdentifier name)
NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object)
{
return reinterpret_cast<NPObject*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex));
return reinterpret_cast<NPObject*>(object->GetPointerFromInternalField(WebCore::v8DOMWrapperObjectIndex));
}
static NPClass V8NPObjectClass = { NP_CLASS_STRUCT_VERSION,
......@@ -113,12 +121,12 @@ static NPClass V8NPObjectClass = { NP_CLASS_STRUCT_VERSION,
// NPAPI's npruntime functions.
NPClass* npScriptObjectClass = &V8NPObjectClass;
NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, DOMWindow* root)
NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore::DOMWindow* root)
{
// Check to see if this object is already wrapped.
if (object->InternalFieldCount() == npObjectInternalFieldCount) {
WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(object->GetPointerFromInternalField(v8DOMWrapperTypeIndex));
if (typeInfo == npObjectTypeInfo()) {
WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(object->GetPointerFromInternalField(WebCore::v8DOMWrapperTypeIndex));
if (typeInfo == WebCore::npObjectTypeInfo()) {
NPObject* returnValue = v8ObjectToNPObject(object);
_NPN_RetainObject(returnValue);
......@@ -129,14 +137,12 @@ NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, DOMWind
V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp, &V8NPObjectClass));
v8npObject->v8Object = v8::Persistent<v8::Object>::New(object);
#ifndef NDEBUG
V8GCController::registerGlobalHandle(NPOBJECT, v8npObject, v8npObject->v8Object);
V8GCController::registerGlobalHandle(WebCore::NPOBJECT, v8npObject, v8npObject->v8Object);
#endif
v8npObject->rootObject = root;
return reinterpret_cast<NPObject*>(v8npObject);
}
} // namespace WebCore
bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result)
{
if (!npObject)
......@@ -156,14 +162,6 @@ bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPV
if (!identifier->isString)
return false;
if (!strcmp(identifier->value.string, "eval")) {
if (argumentCount != 1)
return false;
if (arguments[0].type != NPVariantType_String)
return false;
return _NPN_Evaluate(npp, npObject, const_cast<NPString*>(&arguments[0].value.stringValue), result);
}
v8::HandleScope handleScope;
// FIXME: should use the plugin's owner frame as the security context.
v8::Handle<v8::Context> context = toV8Context(npp, npObject);
......@@ -171,7 +169,14 @@ bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPV
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
if (methodName == _NPN_GetStringIdentifier("eval")) {
if (argumentCount != 1)
return false;
if (arguments[0].type != NPVariantType_String)
return false;
return _NPN_Evaluate(npp, npObject, const_cast<NPString*>(&arguments[0].value.stringValue), result);
}
v8::Handle<v8::Value> functionObject = v8NpObject->v8Object->Get(v8::String::New(identifier->value.string));
if (functionObject.IsEmpty() || functionObject->IsNull()) {
......@@ -224,7 +229,6 @@ bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments,
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
// Lookup the function object and call it.
v8::Handle<v8::Object> functionObject(v8NpObject->v8Object);
......@@ -251,7 +255,7 @@ bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments,
bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* result)
{
bool popupsAllowed = PlatformBridge::popupsAllowed(npp);
bool popupsAllowed = WebCore::PlatformBridge::popupsAllowed(npp);
return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result);
}
......@@ -273,14 +277,13 @@ bool _NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npObject, NPStri
ASSERT(proxy);
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
String filename;
WebCore::String filename;
if (!popupsAllowed)
filename = "npscript";
String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length);
v8::Local<v8::Value> v8result = proxy->evaluate(ScriptSourceCode(script, KURL(ParsedURLString, filename)), 0);
WebCore::String script = WebCore::String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length);
v8::Local<v8::Value> v8result = proxy->evaluate(WebCore::ScriptSourceCode(script, WebCore::KURL(WebCore::ParsedURLString, filename)), 0);
if (v8result.IsEmpty())
return false;
......@@ -303,7 +306,6 @@ bool _NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NP
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
v8::Handle<v8::Object> obj(object->v8Object);
v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(propertyName));
......@@ -338,7 +340,6 @@ bool _NPN_SetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, co
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
v8::Handle<v8::Object> obj(object->v8Object);
obj->Set(npIdentifierToV8Identifier(propertyName),
......@@ -366,7 +367,6 @@ bool _NPN_RemoveProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName)
if (context.IsEmpty())
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
v8::Handle<v8::Object> obj(object->v8Object);
// FIXME: Verify that setting to undefined is right.
......@@ -387,7 +387,6 @@ bool _NPN_HasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName)
if (context.IsEmpty())
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
v8::Handle<v8::Object> obj(object->v8Object);
return obj->Has(npIdentifierToV8Identifier(propertyName));
......@@ -411,7 +410,6 @@ bool _NPN_HasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName)
if (context.IsEmpty())
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
v8::Handle<v8::Object> obj(object->v8Object);
v8::Handle<v8::Value> prop = obj->Get(npIdentifierToV8Identifier(methodName));
......@@ -437,8 +435,6 @@ void _NPN_SetException(NPObject* npObject, const NPUTF8 *message)
return;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
V8Proxy::throwError(V8Proxy::GeneralError, message);
}
......@@ -455,7 +451,6 @@ bool _NPN_Enumerate(NPP npp, NPObject* npObject, NPIdentifier** identifier, uint
if (context.IsEmpty())
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
v8::Handle<v8::Object> obj(object->v8Object);
......@@ -510,7 +505,6 @@ bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uin
if (context.IsEmpty())
return false;
v8::Context::Scope scope(context);
ExceptionCatcher exceptionCatcher;
// Lookup the constructor function.
v8::Handle<v8::Object> ctorObj(object->v8Object);
......
......@@ -45,12 +45,12 @@
#include <v8.h>
namespace WebCore {
class DOMWindow;
class DOMWindow;
static const int npObjectInternalFieldCount = v8DefaultWrapperInternalFieldCount + 0;
static const int npObjectInternalFieldCount = v8DefaultWrapperInternalFieldCount + 0;
WrapperTypeInfo* npObjectTypeInfo();
WrapperTypeInfo* npObjectTypeInfo();
}
extern NPClass* npScriptObjectClass;
......@@ -59,7 +59,7 @@ extern NPClass* npScriptObjectClass;
struct V8NPObject {
NPObject object;
v8::Persistent<v8::Object> v8Object;
DOMWindow* rootObject;
WebCore::DOMWindow* rootObject;
};
struct PrivateIdentifier {
......@@ -70,10 +70,8 @@ struct PrivateIdentifier {
bool isString;
};
NPObject* npCreateV8ScriptObject(NPP, v8::Handle<v8::Object>, DOMWindow*);
NPObject* npCreateV8ScriptObject(NPP, v8::Handle<v8::Object>, WebCore::DOMWindow*);
NPObject* v8ObjectToNPObject(v8::Handle<v8::Object>);
} // namespace WebCore
#endif // NPV8Object_h
......@@ -45,7 +45,7 @@
#include "npruntime_priv.h"
#include <wtf/OwnArrayPtr.h>
namespace WebCore {
using namespace WebCore;
enum InvokeFunctionType {
InvokeMethod = 1,
......@@ -409,5 +409,3 @@ void forgetV8ObjectForNPObject(NPObject* object)
_NPN_ReleaseObject(object);
}
}
} // namespace WebCore
......@@ -39,8 +39,6 @@
#include <v8.h>
namespace WebCore {
// These functions can be replaced by normal JS operation.
// Getters
v8::Handle<v8::Value> npObjectNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo&);
......@@ -67,6 +65,4 @@ v8::Local<v8::Object> createV8ObjectForNPObject(NPObject*, NPObject* root);
// cannot be referred to.
void forgetV8ObjectForNPObject(NPObject*);
} // namespace WebCore
#endif // V8NPObject_h
......@@ -29,18 +29,19 @@
*/
#include "config.h"
#include "V8NPUtils.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "PlatformString.h"
#include "npruntime_impl.h"
#include "npruntime_priv.h"
#undef LOG
#include "NPV8Object.h"
#include "V8NPObject.h"
#include "V8Proxy.h"
namespace WebCore {
#include "npruntime_impl.h"
#include "npruntime_priv.h"
void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NPVariant* result)
{
......@@ -68,7 +69,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()) {
DOMWindow* window = V8Proxy::retrieveWindow(V8Proxy::currentContext());
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);
......@@ -76,6 +77,7 @@ void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NP
}
}
v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* npobject)
{
NPVariantType type = variant->type;
......@@ -126,41 +128,3 @@ NPIdentifier getStringIdentifier(v8::Handle<v8::String> str)
v8::String::Utf8Value utf8(str);
return _NPN_GetStringIdentifier(*utf8);
}
struct ExceptionHandlerInfo {
ExceptionHandlerInfo* previous;
ExceptionHandler handler;
void* data;
};
static ExceptionHandlerInfo* topHandler;
void pushExceptionHandler(ExceptionHandler handler, void* data)
{
ExceptionHandlerInfo* info = new ExceptionHandlerInfo;
info->previous = topHandler;
info->handler = handler;
info->data = data;
topHandler = info;
}
void popExceptionHandler()
{
ASSERT(topHandler);
ExceptionHandlerInfo* doomed = topHandler;
topHandler = topHandler->previous;
delete doomed;
}
ExceptionCatcher::~ExceptionCatcher()
{
if (!m_tryCatch.HasCaught())
return;
if (topHandler)
topHandler->handler(topHandler->data, *v8::String::Utf8Value(m_tryCatch.Exception()));
else
m_tryCatch.ReThrow();
}
} // namespace WebCore
......@@ -38,8 +38,6 @@
#include <v8.h>
namespace WebCore {
// Convert a V8 Value of any type (string, bool, object, etc) to a NPVariant.
void convertV8ObjectToNPVariant(v8::Local<v8::Value>, NPObject*, NPVariant*);
......@@ -50,21 +48,4 @@ v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant*, NPObject*);
// Helper function to create an NPN String Identifier from a v8 string.
NPIdentifier getStringIdentifier(v8::Handle<v8::String>);
// The ExceptionHandler will be notified of any exceptions thrown while
// operating on a NPObject.
typedef void (*ExceptionHandler)(void* data, const NPUTF8* message);
void pushExceptionHandler(ExceptionHandler, void* data);
void popExceptionHandler();
// Upon destruction, an ExceptionCatcher will pass a caught exception to the
// current ExceptionHandler.
class ExceptionCatcher {
public:
~ExceptionCatcher();
private:
v8::TryCatch m_tryCatch;
};
} // namespace WebCore
#endif // V8NPUtils_h
......@@ -35,8 +35,6 @@
#include <wtf/HashSet.h>
#include <wtf/Assertions.h>
using namespace WebCore;
// FIXME: Consider removing locks if we're singlethreaded already.
// The static initializer here should work okay, but we want to avoid
// static initialization in general.
......
2010-05-19 Darin Fisher <darin@chromium.org>
Revert r59790 due to failing Chromium npruntime tests.
* public/WebBindings.h:
* src/WebBindings.cpp:
2010-05-19 Darin Fisher <darin@chromium.org>
Reviewed by Nate Chapin.
......
......@@ -117,7 +117,7 @@ public:
// NPN_UTF8FromIdentifier
WEBKIT_API static NPUTF8* utf8FromIdentifier(NPIdentifier);
// Miscellaneous utility functions ----------------------------------------
// Miscellaneous utility functions ------------------------------------
// Complement to NPN_Get___Identifier functions. Extracts data from the NPIdentifier data
// structure. If isString is true upon return, string will be set but number's value is
......@@ -138,15 +138,6 @@ public:
// Return true (success) if the given npobj is a range object.
// If so, return that range as a WebRange object.
WEBKIT_API static bool getRange(NPObject* range, WebRange*);
// Exceptions -------------------------------------------------------------
typedef void (ExceptionHandler)(void* data, const NPUTF8* message);
// The exception handler will be notified of any exceptions thrown while
// operating on a NPObject.
WEBKIT_API static void pushExceptionHandler(ExceptionHandler, void* data);
WEBKIT_API static void popExceptionHandler();
};
} // namespace WebKit
......
......@@ -45,7 +45,6 @@
#include "V8DOMWrapper.h"
#include "V8Event.h"
#include "V8Helpers.h"
#include "V8NPUtils.h"
#include "V8Proxy.h"
#include "V8Range.h"
#elif USE(JSC)
......@@ -323,14 +322,4 @@ bool WebBindings::getRange(NPObject* range, WebRange* webrange)
#endif
}
void WebBindings::pushExceptionHandler(ExceptionHandler handler, void* data)
{
WebCore::pushExceptionHandler(handler, data);
}
void WebBindings::popExceptionHandler()
{
WebCore::popExceptionHandler();
}
} // namespace WebKit
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