Title: [125995] trunk/Source/WebCore
Revision
125995
Author
[email protected]
Date
2012-08-19 21:39:48 -0700 (Sun, 19 Aug 2012)

Log Message

[V8] Rename SafeAllocation to V8ObjectConstructor
https://bugs.webkit.org/show_bug.cgi?id=94436

Reviewed by Adam Barth.

For clarification.

No tests. No change in behavior.

* UseV8.cmake:
* WebCore.gypi:
* bindings/v8/ScriptFunctionCall.cpp:
(WebCore::ScriptFunctionCall::construct):
* bindings/v8/V8Binding.cpp:
(WebCore::createRawTemplate):
* bindings/v8/V8Binding.h:
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::installDOMWindow):
* bindings/v8/V8DOMWrapper.cpp:
(WebCore::V8DOMWrapper::instantiateV8Object):
* bindings/v8/V8NPObject.cpp:
(WebCore::createV8ObjectForNPObject):
* bindings/v8/V8ObjectConstructor.cpp: Renamed from Source/WebCore/bindings/v8/SafeAllocation.cpp.
(WebCore):
(WebCore::V8ObjectConstructor::isValidConstructorMode):
* bindings/v8/V8ObjectConstructor.h: Renamed from Source/WebCore/bindings/v8/SafeAllocation.h.
(WebCore):
(ConstructorMode):
(WebCore::ConstructorMode::ConstructorMode):
(WebCore::ConstructorMode::~ConstructorMode):
(WebCore::ConstructorMode::current):
(V8ObjectConstructor):
(WebCore::V8ObjectConstructor::newInstance):
* bindings/v8/V8PerContextData.cpp:
(WebCore::V8PerContextData::createWrapperFromCacheSlowCase):
* bindings/v8/WorkerContextExecutionProxy.cpp:
(WebCore::WorkerContextExecutionProxy::initContextIfNeeded):
* bindings/v8/custom/V8InjectedScriptManager.cpp:
(WebCore::createInjectedScriptHostV8Wrapper):
* bindings/v8/custom/V8ScriptProfileCustom.cpp:
(WebCore::toV8):
* bindings/v8/custom/V8ScriptProfileNodeCustom.cpp:
(WebCore::toV8):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125994 => 125995)


--- trunk/Source/WebCore/ChangeLog	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/ChangeLog	2012-08-20 04:39:48 UTC (rev 125995)
@@ -1,5 +1,51 @@
 2012-08-19  Kentaro Hara  <[email protected]>
 
+        [V8] Rename SafeAllocation to V8ObjectConstructor
+        https://bugs.webkit.org/show_bug.cgi?id=94436
+
+        Reviewed by Adam Barth.
+
+        For clarification.
+
+        No tests. No change in behavior.
+
+        * UseV8.cmake:
+        * WebCore.gypi:
+        * bindings/v8/ScriptFunctionCall.cpp:
+        (WebCore::ScriptFunctionCall::construct):
+        * bindings/v8/V8Binding.cpp:
+        (WebCore::createRawTemplate):
+        * bindings/v8/V8Binding.h:
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::installDOMWindow):
+        * bindings/v8/V8DOMWrapper.cpp:
+        (WebCore::V8DOMWrapper::instantiateV8Object):
+        * bindings/v8/V8NPObject.cpp:
+        (WebCore::createV8ObjectForNPObject):
+        * bindings/v8/V8ObjectConstructor.cpp: Renamed from Source/WebCore/bindings/v8/SafeAllocation.cpp.
+        (WebCore):
+        (WebCore::V8ObjectConstructor::isValidConstructorMode):
+        * bindings/v8/V8ObjectConstructor.h: Renamed from Source/WebCore/bindings/v8/SafeAllocation.h.
+        (WebCore):
+        (ConstructorMode):
+        (WebCore::ConstructorMode::ConstructorMode):
+        (WebCore::ConstructorMode::~ConstructorMode):
+        (WebCore::ConstructorMode::current):
+        (V8ObjectConstructor):
+        (WebCore::V8ObjectConstructor::newInstance):
+        * bindings/v8/V8PerContextData.cpp:
+        (WebCore::V8PerContextData::createWrapperFromCacheSlowCase):
+        * bindings/v8/WorkerContextExecutionProxy.cpp:
+        (WebCore::WorkerContextExecutionProxy::initContextIfNeeded):
+        * bindings/v8/custom/V8InjectedScriptManager.cpp:
+        (WebCore::createInjectedScriptHostV8Wrapper):
+        * bindings/v8/custom/V8ScriptProfileCustom.cpp:
+        (WebCore::toV8):
+        * bindings/v8/custom/V8ScriptProfileNodeCustom.cpp:
+        (WebCore::toV8):
+
+2012-08-19  Kentaro Hara  <[email protected]>
+
         [V8] Move m_windowShell from V8Proxy to ScriptController
         https://bugs.webkit.org/show_bug.cgi?id=94438
 

Modified: trunk/Source/WebCore/UseV8.cmake (125994 => 125995)


--- trunk/Source/WebCore/UseV8.cmake	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/UseV8.cmake	2012-08-20 04:39:48 UTC (rev 125995)
@@ -28,7 +28,6 @@
     bindings/v8/Dictionary.cpp
     bindings/v8/PageScriptDebugServer.cpp
     bindings/v8/RetainedDOMInfo.cpp
-    bindings/v8/SafeAllocation.cpp
     bindings/v8/ScheduledAction.cpp
     bindings/v8/ScopedDOMDataStore.cpp
     bindings/v8/ScriptCachedFrameData.cpp
@@ -59,6 +58,7 @@
     bindings/v8/V8IsolatedContext.cpp
     bindings/v8/V8LazyEventListener.cpp
     bindings/v8/V8NodeFilterCondition.cpp
+    bindings/v8/V8ObjectConstructor.cpp
     bindings/v8/V8PerContextData.cpp
     bindings/v8/V8PerIsolateData.cpp
     bindings/v8/V8Proxy.cpp

Modified: trunk/Source/WebCore/WebCore.gypi (125994 => 125995)


--- trunk/Source/WebCore/WebCore.gypi	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/WebCore.gypi	2012-08-20 04:39:48 UTC (rev 125995)
@@ -2196,8 +2196,6 @@
             'bindings/v8/RetainedDOMInfo.cpp',
             'bindings/v8/RetainedDOMInfo.h',
             'bindings/v8/RetainedObjectInfo.h',
-            'bindings/v8/SafeAllocation.cpp',
-            'bindings/v8/SafeAllocation.h',
             'bindings/v8/ScheduledAction.cpp',
             'bindings/v8/ScheduledAction.h',
             'bindings/v8/ScopedDOMDataStore.cpp',
@@ -2278,6 +2276,8 @@
             'bindings/v8/V8NPUtils.h',
             'bindings/v8/V8NodeFilterCondition.cpp',
             'bindings/v8/V8NodeFilterCondition.h',
+            'bindings/v8/V8ObjectConstructor.cpp',
+            'bindings/v8/V8ObjectConstructor.h',
             'bindings/v8/V8PerContextData.cpp',
             'bindings/v8/V8PerContextData.h',
             'bindings/v8/V8PerIsolateData.cpp',

Deleted: trunk/Source/WebCore/bindings/v8/SafeAllocation.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/SafeAllocation.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/SafeAllocation.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2012 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:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  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.
- * 
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "SafeAllocation.h"
-
-#include "V8Binding.h"
-
-namespace WebCore {
-
-v8::Handle<v8::Value> SafeAllocation::isValidConstructorMode(const v8::Arguments& args)
-{
-    if (ConstructorMode::current() == ConstructorMode::CreateNewObject)
-        return throwTypeError("Illegal constructor", args.GetIsolate());
-    return args.This();
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/bindings/v8/SafeAllocation.h (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/SafeAllocation.h	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/SafeAllocation.h	2012-08-20 04:39:48 UTC (rev 125995)
@@ -1,105 +0,0 @@
-/*
-* Copyright (C) 2012 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 SafeAllocation_h
-#define SafeAllocation_h
-
-#include "V8PerIsolateData.h"
-#include "V8RecursionScope.h"
-
-#include <v8.h>
-
-namespace WebCore {
-
-class ConstructorMode {
-public:
-    enum Mode {
-        WrapExistingObject,
-        CreateNewObject
-    };
-
-    ConstructorMode()
-    {
-        V8PerIsolateData* data = ""
-        m_previous = data->m_constructorMode;
-        data->m_constructorMode = WrapExistingObject;
-    }
-
-    ~ConstructorMode()
-    {
-        V8PerIsolateData* data = ""
-        data->m_constructorMode = m_previous;
-    }
-
-    static bool current() { return V8PerIsolateData::current()->m_constructorMode; }
-
-private:
-    bool m_previous;
-};
-
-class SafeAllocation {
-public:
-    static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
-    static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
-    static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
-
-    static v8::Handle<v8::Value> isValidConstructorMode(const v8::Arguments&);
-};
-
-v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function)
-{
-    if (function.IsEmpty())
-        return v8::Local<v8::Object>();
-    ConstructorMode constructorMode;
-    V8RecursionScope::MicrotaskSuppression scope;
-    return function->NewInstance();
-}
-
-v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
-{
-    if (objectTemplate.IsEmpty())
-        return v8::Local<v8::Object>();
-    ConstructorMode constructorMode;
-    V8RecursionScope::MicrotaskSuppression scope;
-    return objectTemplate->NewInstance();
-}
-
-v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
-{
-    if (function.IsEmpty())
-        return v8::Local<v8::Object>();
-    ConstructorMode constructorMode;
-    V8RecursionScope::MicrotaskSuppression scope;
-    return function->NewInstance(argc, argv);
-}
-
-} // namespace WebCore
-
-#endif // SafeAllocation_h

Modified: trunk/Source/WebCore/bindings/v8/ScriptFunctionCall.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/ScriptFunctionCall.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/ScriptFunctionCall.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -31,11 +31,11 @@
 #include "config.h"
 #include "ScriptFunctionCall.h"
 
-#include "SafeAllocation.h"
 #include "ScriptScope.h"
 #include "ScriptState.h"
 #include "ScriptValue.h"
 #include "V8Binding.h"
+#include "V8ObjectConstructor.h"
 #include "V8Proxy.h"
 #include "V8RecursionScope.h"
 #include "V8Utilities.h"
@@ -168,7 +168,7 @@
     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());
+    v8::Local<v8::Object> result = V8ObjectConstructor::newInstance(constructor, m_arguments.size(), args.get());
     if (!scope.success()) {
         hadException = true;
         return ScriptObject();

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -37,9 +37,9 @@
 #include "MemoryInstrumentation.h"
 #include "PlatformString.h"
 #include "QualifiedName.h"
-#include "SafeAllocation.h"
 #include "V8DOMStringList.h"
 #include "V8Element.h"
+#include "V8ObjectConstructor.h"
 #include "V8Proxy.h"
 
 #include <wtf/MathExtras.h>
@@ -317,7 +317,7 @@
 v8::Persistent<v8::FunctionTemplate> createRawTemplate()
 {
     v8::HandleScope scope;
-    v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(SafeAllocation::isValidConstructorMode);
+    v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8ObjectConstructor::isValidConstructorMode);
     return v8::Persistent<v8::FunctionTemplate>::New(result);
 }        
 

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-08-20 04:39:48 UTC (rev 125995)
@@ -33,12 +33,12 @@
 
 #include "BindingSecurity.h"
 #include "Document.h"
-#include "SafeAllocation.h"
 #include "V8BindingMacros.h"
 #include "V8DOMConfiguration.h"
 #include "V8DOMWindowShell.h"
 #include "V8DOMWrapper.h"
 #include "V8HiddenPropertyName.h"
+#include "V8ObjectConstructor.h"
 #include "V8PerIsolateData.h"
 #include "V8Proxy.h"
 #include "V8ThrowException.h"

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -42,7 +42,6 @@
 #include "PageGroup.h"
 #include "PlatformSupport.h"
 #include "RuntimeEnabledFeatures.h"
-#include "SafeAllocation.h"
 #include "ScriptCallStack.h"
 #include "ScriptCallStackFactory.h"
 #include "ScriptProfiler.h"
@@ -59,6 +58,7 @@
 #include "V8HiddenPropertyName.h"
 #include "V8History.h"
 #include "V8Location.h"
+#include "V8ObjectConstructor.h"
 #include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include "WorkerContextExecutionProxy.h"
@@ -410,7 +410,7 @@
 {
     // Create a new JS window object and use it as the prototype for the  shadow global object.
     v8::Handle<v8::Function> windowConstructor = V8DOMWrapper::constructorForType(&V8DOMWindow::info, window);
-    v8::Local<v8::Object> jsWindow = SafeAllocation::newInstance(windowConstructor);
+    v8::Local<v8::Object> jsWindow = V8ObjectConstructor::newInstance(windowConstructor);
     // Bail out if allocation failed.
     if (jsWindow.IsEmpty())
         return false;

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -37,7 +37,6 @@
 #include "EventTargetInterfaces.h"
 #include "Frame.h"
 #include "FrameLoaderClient.h"
-#include "SafeAllocation.h"
 #include "StylePropertySet.h"
 #include "V8AbstractEventListener.h"
 #include "V8Binding.h"
@@ -51,6 +50,7 @@
 #include "V8NamedNodeMap.h"
 #include "V8NodeFilterCondition.h"
 #include "V8NodeList.h"
+#include "V8ObjectConstructor.h"
 #include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include "V8StyleSheet.h"
@@ -205,7 +205,7 @@
         instance = contextData->createWrapperFromCache(type);
     else {
         v8::Local<v8::Function> function = type->getTemplate()->GetFunction();
-        instance = SafeAllocation::newInstance(function);
+        instance = V8ObjectConstructor::newInstance(function);
     }
 
     if (!instance.IsEmpty()) {

Modified: trunk/Source/WebCore/bindings/v8/V8NPObject.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8NPObject.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/V8NPObject.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -34,13 +34,13 @@
 
 #include "HTMLPlugInElement.h"
 #include "NPV8Object.h"
-#include "SafeAllocation.h"
 #include "V8Binding.h"
 #include "V8DOMMap.h"
 #include "V8HTMLAppletElement.h"
 #include "V8HTMLEmbedElement.h"
 #include "V8HTMLObjectElement.h"
 #include "V8NPUtils.h"
+#include "V8ObjectConstructor.h"
 #include "V8Proxy.h"
 #include "npruntime_impl.h"
 #include "npruntime_priv.h"
@@ -407,7 +407,7 @@
     }
 
     v8::Handle<v8::Function> v8Function = npObjectDesc->GetFunction();
-    v8::Local<v8::Object> value = SafeAllocation::newInstance(v8Function);
+    v8::Local<v8::Object> value = V8ObjectConstructor::newInstance(v8Function);
 
     // If we were unable to allocate the instance, we avoid wrapping and registering the NP object.
     if (value.IsEmpty())

Copied: trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.cpp (from rev 125994, trunk/Source/WebCore/bindings/v8/SafeAllocation.cpp) (0 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  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.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "V8ObjectConstructor.h"
+
+#include "V8Binding.h"
+
+namespace WebCore {
+
+v8::Handle<v8::Value> V8ObjectConstructor::isValidConstructorMode(const v8::Arguments& args)
+{
+    if (ConstructorMode::current() == ConstructorMode::CreateNewObject)
+        return throwTypeError("Illegal constructor", args.GetIsolate());
+    return args.This();
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.h (from rev 125994, trunk/Source/WebCore/bindings/v8/SafeAllocation.h) (0 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8ObjectConstructor.h	2012-08-20 04:39:48 UTC (rev 125995)
@@ -0,0 +1,105 @@
+/*
+* Copyright (C) 2012 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 V8ObjectConstructor_h
+#define V8ObjectConstructor_h
+
+#include "V8PerIsolateData.h"
+#include "V8RecursionScope.h"
+
+#include <v8.h>
+
+namespace WebCore {
+
+class ConstructorMode {
+public:
+    enum Mode {
+        WrapExistingObject,
+        CreateNewObject
+    };
+
+    ConstructorMode()
+    {
+        V8PerIsolateData* data = ""
+        m_previous = data->m_constructorMode;
+        data->m_constructorMode = WrapExistingObject;
+    }
+
+    ~ConstructorMode()
+    {
+        V8PerIsolateData* data = ""
+        data->m_constructorMode = m_previous;
+    }
+
+    static bool current() { return V8PerIsolateData::current()->m_constructorMode; }
+
+private:
+    bool m_previous;
+};
+
+class V8ObjectConstructor {
+public:
+    static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
+    static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
+    static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
+
+    static v8::Handle<v8::Value> isValidConstructorMode(const v8::Arguments&);
+};
+
+v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::Function> function)
+{
+    if (function.IsEmpty())
+        return v8::Local<v8::Object>();
+    ConstructorMode constructorMode;
+    V8RecursionScope::MicrotaskSuppression scope;
+    return function->NewInstance();
+}
+
+v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
+{
+    if (objectTemplate.IsEmpty())
+        return v8::Local<v8::Object>();
+    ConstructorMode constructorMode;
+    V8RecursionScope::MicrotaskSuppression scope;
+    return objectTemplate->NewInstance();
+}
+
+v8::Local<v8::Object> V8ObjectConstructor::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
+{
+    if (function.IsEmpty())
+        return v8::Local<v8::Object>();
+    ConstructorMode constructorMode;
+    V8RecursionScope::MicrotaskSuppression scope;
+    return function->NewInstance(argc, argv);
+}
+
+} // namespace WebCore
+
+#endif // V8ObjectConstructor_h

Modified: trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -31,7 +31,7 @@
 #include "config.h"
 #include "V8PerContextData.h"
 
-#include "SafeAllocation.h"
+#include "V8ObjectConstructor.h"
 
 namespace WebCore {
 
@@ -92,7 +92,7 @@
 
     v8::Context::Scope scope(m_context);
     v8::Local<v8::Function> function = constructorForType(type);
-    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+    v8::Local<v8::Object> instance = V8ObjectConstructor::newInstance(function);
     if (!instance.IsEmpty()) {
         m_wrapperBoilerplates.set(type, v8::Persistent<v8::Object>::New(instance));
         return instance->Clone();

Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -37,7 +37,6 @@
 
 #include "DedicatedWorkerContext.h"
 #include "Event.h"
-#include "SafeAllocation.h"
 #include "ScriptCallStack.h"
 #include "SharedWorker.h"
 #include "SharedWorkerContext.h"
@@ -45,6 +44,7 @@
 #include "V8DOMMap.h"
 #include "V8DOMWindowShell.h"
 #include "V8DedicatedWorkerContext.h"
+#include "V8ObjectConstructor.h"
 #include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include "V8RecursionScope.h"
@@ -173,7 +173,7 @@
         contextType = &V8SharedWorkerContext::info;
 #endif
     v8::Handle<v8::Function> workerContextConstructor = m_perContextData->constructorForType(contextType);
-    v8::Local<v8::Object> jsWorkerContext = SafeAllocation::newInstance(workerContextConstructor);
+    v8::Local<v8::Object> jsWorkerContext = V8ObjectConstructor::newInstance(workerContextConstructor);
     // Bail out if allocation failed.
     if (jsWorkerContext.IsEmpty()) {
         dispose();

Modified: trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptManager.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptManager.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptManager.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -35,7 +35,6 @@
 #include "BindingState.h"
 #include "DOMWindow.h"
 #include "InjectedScriptHost.h"
-#include "SafeAllocation.h"
 #include "ScriptObject.h"
 #include "V8Binding.h"
 #include "V8DOMWindow.h"
@@ -59,7 +58,7 @@
         // Return if allocation failed.
         return v8::Local<v8::Object>();
     }
-    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+    v8::Local<v8::Object> instance = V8ObjectConstructor::newInstance(function);
     if (instance.IsEmpty()) {
         // Avoid setting the wrapper if allocation failed.
         return v8::Local<v8::Object>();

Modified: trunk/Source/WebCore/bindings/v8/custom/V8ScriptProfileCustom.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/custom/V8ScriptProfileCustom.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/custom/V8ScriptProfileCustom.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -32,7 +32,6 @@
 #if ENABLE(_javascript__DEBUGGER)
 #include "V8ScriptProfile.h"
 
-#include "SafeAllocation.h"
 #include "ScriptProfile.h"
 #include "V8Binding.h"
 #include "V8Proxy.h"
@@ -50,7 +49,7 @@
         // Return if allocation failed.
         return v8Undefined();
     }
-    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+    v8::Local<v8::Object> instance = V8ObjectConstructor::newInstance(function);
     if (instance.IsEmpty()) {
         // Avoid setting the wrapper if allocation failed.
         return v8Undefined();

Modified: trunk/Source/WebCore/bindings/v8/custom/V8ScriptProfileNodeCustom.cpp (125994 => 125995)


--- trunk/Source/WebCore/bindings/v8/custom/V8ScriptProfileNodeCustom.cpp	2012-08-20 04:32:37 UTC (rev 125994)
+++ trunk/Source/WebCore/bindings/v8/custom/V8ScriptProfileNodeCustom.cpp	2012-08-20 04:39:48 UTC (rev 125995)
@@ -32,7 +32,6 @@
 #if ENABLE(_javascript__DEBUGGER)
 #include "V8ScriptProfileNode.h"
 
-#include "SafeAllocation.h"
 #include "ScriptProfileNode.h"
 #include "V8Binding.h"
 #include "V8Proxy.h"
@@ -57,7 +56,7 @@
         // Return if allocation failed.
         return v8Undefined();
     }
-    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+    v8::Local<v8::Object> instance = V8ObjectConstructor::newInstance(function);
     if (instance.IsEmpty()) {
         // Avoid setting the wrapper if allocation failed.
         return v8::Local<v8::Object>();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to