diff options
Diffstat (limited to 'Source/WebCore/bridge/c/c_instance.cpp')
-rw-r--r-- | Source/WebCore/bridge/c/c_instance.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/Source/WebCore/bridge/c/c_instance.cpp b/Source/WebCore/bridge/c/c_instance.cpp index 441c20ed7..e69d7a06e 100644 --- a/Source/WebCore/bridge/c/c_instance.cpp +++ b/Source/WebCore/bridge/c/c_instance.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2003, 2006, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. 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 @@ -45,6 +45,7 @@ #include <runtime/JSLock.h> #include <runtime/PropertyNameArray.h> #include <wtf/Assertions.h> +#include <wtf/NeverDestroyed.h> #include <wtf/StdLibExtras.h> #include <wtf/StringExtras.h> #include <wtf/Vector.h> @@ -56,7 +57,7 @@ namespace Bindings { static String& globalExceptionString() { - DEFINE_STATIC_LOCAL(String, exceptionStr, ()); + static NeverDestroyed<String> exceptionStr; return exceptionStr; } @@ -71,15 +72,17 @@ void CInstance::moveGlobalExceptionToExecState(ExecState* exec) return; { - JSLockHolder lock(exec); - exec->vm().throwException(exec, createError(exec, globalExceptionString())); + VM& vm = exec->vm(); + JSLockHolder lock(vm); + auto scope = DECLARE_THROW_SCOPE(vm); + throwException(exec, scope, createError(exec, globalExceptionString())); } globalExceptionString() = String(); } -CInstance::CInstance(NPObject* o, PassRefPtr<RootObject> rootObject) - : Instance(rootObject) +CInstance::CInstance(NPObject* o, RefPtr<RootObject>&& rootObject) + : Instance(WTFMove(rootObject)) { _object = _NPN_RetainObject(o); _class = 0; @@ -138,12 +141,12 @@ private: void finishCreation(VM& vm, const String& name) { Base::finishCreation(vm, name); - ASSERT(inherits(info())); + ASSERT(inherits(vm, info())); } }; -const ClassInfo CRuntimeMethod::s_info = { "CRuntimeMethod", &RuntimeMethod::s_info, 0, 0, CREATE_METHOD_TABLE(CRuntimeMethod) }; +const ClassInfo CRuntimeMethod::s_info = { "CRuntimeMethod", &RuntimeMethod::s_info, 0, CREATE_METHOD_TABLE(CRuntimeMethod) }; JSValue CInstance::getMethod(ExecState* exec, PropertyName propertyName) { @@ -153,8 +156,11 @@ JSValue CInstance::getMethod(ExecState* exec, PropertyName propertyName) JSValue CInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod) { - if (!asObject(runtimeMethod)->inherits(CRuntimeMethod::info())) - return exec->vm().throwException(exec, createTypeError(exec, "Attempt to invoke non-plug-in method on plug-in object.")); + VM& vm = exec->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (!asObject(runtimeMethod)->inherits(vm, CRuntimeMethod::info())) + return throwTypeError(exec, scope, ASCIILiteral("Attempt to invoke non-plug-in method on plug-in object.")); CMethod* method = static_cast<CMethod*>(runtimeMethod->method()); ASSERT(method); @@ -183,7 +189,7 @@ JSValue CInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod) } if (!retval) - exec->vm().throwException(exec, createError(exec, ASCIILiteral("Error calling method on NPObject."))); + throwException(exec, scope, createError(exec, ASCIILiteral("Error calling method on NPObject."))); for (i = 0; i < count; i++) _NPN_ReleaseVariantValue(&cArgs[i]); @@ -196,6 +202,9 @@ JSValue CInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod) JSValue CInstance::invokeDefaultMethod(ExecState* exec) { + VM& vm = exec->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + if (!_object->_class->invokeDefault) return jsUndefined(); @@ -218,7 +227,7 @@ JSValue CInstance::invokeDefaultMethod(ExecState* exec) } if (!retval) - exec->vm().throwException(exec, createError(exec, ASCIILiteral("Error calling method on NPObject."))); + throwException(exec, scope, createError(exec, ASCIILiteral("Error calling method on NPObject."))); for (i = 0; i < count; i++) _NPN_ReleaseVariantValue(&cArgs[i]); @@ -235,6 +244,9 @@ bool CInstance::supportsConstruct() const JSValue CInstance::invokeConstruct(ExecState* exec, const ArgList& args) { + VM& vm = exec->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + if (!_object->_class->construct) return jsUndefined(); @@ -257,7 +269,7 @@ JSValue CInstance::invokeConstruct(ExecState* exec, const ArgList& args) } if (!retval) - exec->vm().throwException(exec, createError(exec, ASCIILiteral("Error calling method on NPObject."))); + throwException(exec, scope, createError(exec, ASCIILiteral("Error calling method on NPObject."))); for (i = 0; i < count; i++) _NPN_ReleaseVariantValue(&cArgs[i]); @@ -310,6 +322,9 @@ JSValue CInstance::valueOf(ExecState* exec) const bool CInstance::toJSPrimitive(ExecState* exec, const char* name, JSValue& resultValue) const { + VM& vm = exec->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + NPIdentifier ident = _NPN_GetStringIdentifier(name); if (!_object->_class->hasMethod(_object, ident)) return false; @@ -327,7 +342,7 @@ bool CInstance::toJSPrimitive(ExecState* exec, const char* name, JSValue& result } if (!retval) - exec->vm().throwException(exec, createError(exec, ASCIILiteral("Error calling method on NPObject."))); + throwException(exec, scope, createError(exec, ASCIILiteral("Error calling method on NPObject."))); resultValue = convertNPVariantToValue(exec, &resultVariant, m_rootObject.get()); _NPN_ReleaseVariantValue(&resultVariant); |