Title: [178696] trunk
Revision
178696
Author
msab...@apple.com
Date
2015-01-19 21:28:04 -0800 (Mon, 19 Jan 2015)

Log Message

A "cached" null setter should throw a TypeException when called in strict mode and doesn't
https://bugs.webkit.org/show_bug.cgi?id=139418

Reviewed by Filip Pizlo.

Source/_javascript_Core:

Made a new NullSetterFunction class similar to NullGetterFunction.  The difference is that 
NullSetterFunction will throw a TypeError per the ECMA262 spec for a strict mode caller.

* CMakeLists.txt:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
* _javascript_Core.xcodeproj/project.pbxproj:
Added new files NullSetterFunction.cpp and NullSetterFunction.h.

* runtime/GetterSetter.h:
(JSC::GetterSetter::GetterSetter):
(JSC::GetterSetter::isSetterNull):
(JSC::GetterSetter::setSetter):
Change setter instances from using NullGetterFunction to using NullSetterFunction.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::nullSetterFunction):
Added m_nullSetterFunction and accessor.

* runtime/NullSetterFunction.cpp: Added.
(JSC::GetCallerStrictnessFunctor::GetCallerStrictnessFunctor):
(JSC::GetCallerStrictnessFunctor::operator()):
(JSC::GetCallerStrictnessFunctor::callerIsStrict):
(JSC::callerIsStrict):
Method to determine if the caller is in strict mode.

(JSC::callReturnUndefined):
(JSC::constructReturnUndefined):
(JSC::NullSetterFunction::getCallData):
(JSC::NullSetterFunction::getConstructData):
* runtime/NullSetterFunction.h: Added.
(JSC::NullSetterFunction::create):
(JSC::NullSetterFunction::createStructure):
(JSC::NullSetterFunction::NullSetterFunction):
Class with handlers for a null setter.

LayoutTests:

New regression test.

* js/regress-139418-expected.txt: Added.
* js/regress-139418.html: Added.
* js/script-tests/regress-139418.js: Added.
(InnerObjectNoSetter):
(InnerObjectNoSetter.prototype.get enabled):
(StrictOuterObject):
(StrictOuterObject.prototype.get enabled):
(StrictOuterObject.prototype.set enabled):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (178695 => 178696)


--- trunk/LayoutTests/ChangeLog	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/LayoutTests/ChangeLog	2015-01-20 05:28:04 UTC (rev 178696)
@@ -1,3 +1,21 @@
+2015-01-19  Michael Saboff  <msab...@apple.com>
+
+        A "cached" null setter should throw a TypeException when called in strict mode and doesn't
+        https://bugs.webkit.org/show_bug.cgi?id=139418
+
+        Reviewed by Filip Pizlo.
+
+        New regression test.
+
+        * js/regress-139418-expected.txt: Added.
+        * js/regress-139418.html: Added.
+        * js/script-tests/regress-139418.js: Added.
+        (InnerObjectNoSetter):
+        (InnerObjectNoSetter.prototype.get enabled):
+        (StrictOuterObject):
+        (StrictOuterObject.prototype.get enabled):
+        (StrictOuterObject.prototype.set enabled):
+
 2015-01-19  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [SVG -> OTF Converter] Flip the switch on

Added: trunk/LayoutTests/js/regress-139418-expected.txt (0 => 178696)


--- trunk/LayoutTests/js/regress-139418-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/regress-139418-expected.txt	2015-01-20 05:28:04 UTC (rev 178696)
@@ -0,0 +1,9 @@
+Regression test for https://webkit.org/b/139418.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/regress-139418.html (0 => 178696)


--- trunk/LayoutTests/js/regress-139418.html	                        (rev 0)
+++ trunk/LayoutTests/js/regress-139418.html	2015-01-20 05:28:04 UTC (rev 178696)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/js/script-tests/regress-139418.js (0 => 178696)


--- trunk/LayoutTests/js/script-tests/regress-139418.js	                        (rev 0)
+++ trunk/LayoutTests/js/script-tests/regress-139418.js	2015-01-20 05:28:04 UTC (rev 178696)
@@ -0,0 +1,54 @@
+description(
+"Regression test for https://webkit.org/b/139418."
+);
+
+function InnerObjectNoSetter()
+{
+    this._enabled = false;
+}
+
+InnerObjectNoSetter.prototype = {
+    get enabled()
+    {
+        return this._enabled;
+    }
+}
+
+function StrictOuterObject(inner)
+{
+    this._innerObject = inner;
+}
+
+StrictOuterObject.prototype = {
+    get enabled()
+    {
+        "use strict";
+        return this._innerObject.enabled;
+    },
+
+    set enabled(x)
+    {
+        "use strict";
+        this._innerObject.enabled = x;
+    }
+}
+
+var innerNoSetter = new InnerObjectNoSetter;
+var strictOuterNoInnerSetter = new StrictOuterObject(innerNoSetter);
+
+for (var i = 0; i < 1000; ++i) {
+    var  noExceptionWithMissingSetter = "Missing setter called with strict mode should throw exception and didn't!";
+    try {
+        strictOuterNoInnerSetter.enabled = true;
+        throw  noExceptionWithMissingSetter;
+    } catch (e) {
+        if (e instanceof TypeError)
+            ; // This is the expected exception
+        else if (!((e instanceof String) && (e ==  noExceptionWithMissingSetter)))
+            throw e // rethrow "missing exception" exception
+        else
+            throw "Missing setter called with strict mode threw wrong exception: " + e;
+    }
+    if (strictOuterNoInnerSetter.enabled)
+        throw "Setter unexpectedly modified value";
+}

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (178695 => 178696)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2015-01-20 05:28:04 UTC (rev 178696)
@@ -514,6 +514,7 @@
     runtime/NativeErrorConstructor.cpp
     runtime/NativeErrorPrototype.cpp
     runtime/NullGetterFunction.cpp
+    runtime/NullSetterFunction.cpp
     runtime/NumberConstructor.cpp
     runtime/NumberObject.cpp
     runtime/NumberPrototype.cpp

Modified: trunk/Source/_javascript_Core/ChangeLog (178695 => 178696)


--- trunk/Source/_javascript_Core/ChangeLog	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-01-20 05:28:04 UTC (rev 178696)
@@ -1,3 +1,48 @@
+2015-01-19  Michael Saboff  <msab...@apple.com>
+
+        A "cached" null setter should throw a TypeException when called in strict mode and doesn't
+        https://bugs.webkit.org/show_bug.cgi?id=139418
+
+        Reviewed by Filip Pizlo.
+
+        Made a new NullSetterFunction class similar to NullGetterFunction.  The difference is that 
+        NullSetterFunction will throw a TypeError per the ECMA262 spec for a strict mode caller.
+
+        * CMakeLists.txt:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        Added new files NullSetterFunction.cpp and NullSetterFunction.h.
+
+        * runtime/GetterSetter.h:
+        (JSC::GetterSetter::GetterSetter):
+        (JSC::GetterSetter::isSetterNull):
+        (JSC::GetterSetter::setSetter):
+        Change setter instances from using NullGetterFunction to using NullSetterFunction.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::nullSetterFunction):
+        Added m_nullSetterFunction and accessor.
+
+        * runtime/NullSetterFunction.cpp: Added.
+        (JSC::GetCallerStrictnessFunctor::GetCallerStrictnessFunctor):
+        (JSC::GetCallerStrictnessFunctor::operator()):
+        (JSC::GetCallerStrictnessFunctor::callerIsStrict):
+        (JSC::callerIsStrict):
+        Method to determine if the caller is in strict mode.
+
+        (JSC::callReturnUndefined):
+        (JSC::constructReturnUndefined):
+        (JSC::NullSetterFunction::getCallData):
+        (JSC::NullSetterFunction::getConstructData):
+        * runtime/NullSetterFunction.h: Added.
+        (JSC::NullSetterFunction::create):
+        (JSC::NullSetterFunction::createStructure):
+        (JSC::NullSetterFunction::NullSetterFunction):
+        Class with handlers for a null setter.
+
 2015-01-19  Saam Barati  <saambara...@gmail.com>
 
         Web Inspector: Provide a front end for JSC's Control Flow Profiler

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj (178695 => 178696)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2015-01-20 05:28:04 UTC (rev 178696)
@@ -779,6 +779,7 @@
     <ClCompile Include="..\runtime\NativeErrorConstructor.cpp" />
     <ClCompile Include="..\runtime\NativeErrorPrototype.cpp" />
     <ClCompile Include="..\runtime\NullGetterFunction.cpp" />
+    <ClCompile Include="..\runtime\NullSetterFunction.cpp" />
     <ClCompile Include="..\runtime\NumberConstructor.cpp" />
     <ClCompile Include="..\runtime\NumberObject.cpp" />
     <ClCompile Include="..\runtime\NumberPrototype.cpp" />
@@ -1573,6 +1574,7 @@
     <ClInclude Include="..\runtime\NativeErrorConstructor.h" />
     <ClInclude Include="..\runtime\NativeErrorPrototype.h" />
     <ClInclude Include="..\runtime\NullGetterFunction.h" />
+    <ClInclude Include="..\runtime\NullSetterFunction.h" />
     <ClInclude Include="..\runtime\NumberConstructor.h" />
     <ClInclude Include="..\runtime\NumberObject.h" />
     <ClInclude Include="..\runtime\NumberPrototype.h" />

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters (178695 => 178696)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2015-01-20 05:28:04 UTC (rev 178696)
@@ -759,6 +759,9 @@
     <ClCompile Include="..\runtime\NullGetterFunction.cpp">
       <Filter>runtime</Filter>
     </ClCompile>
+    <ClCompile Include="..\runtime\NullSetterFunction.cpp">
+      <Filter>runtime</Filter>
+    </ClCompile>
     <ClCompile Include="..\runtime\NumberConstructor.cpp">
       <Filter>runtime</Filter>
     </ClCompile>
@@ -2774,6 +2777,9 @@
     <ClInclude Include="..\runtime\NullGetterFunction.h">
       <Filter>runtime</Filter>
     </ClInclude>
+    <ClInclude Include="..\runtime\NullSetterFunction.h">
+      <Filter>runtime</Filter>
+    </ClInclude>
     <ClInclude Include="..\runtime\NumberConstructor.h">
       <Filter>runtime</Filter>
     </ClInclude>

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (178695 => 178696)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2015-01-20 05:28:04 UTC (rev 178696)
@@ -918,6 +918,7 @@
 		6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */ = {isa = PBXBuildFile; fileRef = 6514F21718B3E1670098FF8B /* Bytecodes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		65303D641447B9E100D3F904 /* ParserTokens.h in Headers */ = {isa = PBXBuildFile; fileRef = 65303D631447B9E100D3F904 /* ParserTokens.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6546F5211A32B313006F07D5 /* NullGetterFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6546F51F1A32A59C006F07D5 /* NullGetterFunction.cpp */; };
+		65525FC51A6DD801007B5495 /* NullSetterFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65525FC31A6DD3B3007B5495 /* NullSetterFunction.cpp */; };
 		6553A33117A1F1EE008CF6F3 /* CommonSlowPathsExceptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6553A32F17A1F1EE008CF6F3 /* CommonSlowPathsExceptions.cpp */; };
 		6553A33217A1F1EE008CF6F3 /* CommonSlowPathsExceptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6553A33017A1F1EE008CF6F3 /* CommonSlowPathsExceptions.h */; };
 		655EB29B10CE2581001A990E /* NodesCodegen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 655EB29A10CE2581001A990E /* NodesCodegen.cpp */; };
@@ -2565,6 +2566,8 @@
 		65400C100A69BAF200509887 /* PropertyNameArray.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PropertyNameArray.h; sourceTree = "<group>"; };
 		6546F51F1A32A59C006F07D5 /* NullGetterFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = NullGetterFunction.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
 		6546F5201A32A59C006F07D5 /* NullGetterFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NullGetterFunction.h; sourceTree = "<group>"; };
+		65525FC31A6DD3B3007B5495 /* NullSetterFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NullSetterFunction.cpp; sourceTree = "<group>"; };
+		65525FC41A6DD3B3007B5495 /* NullSetterFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NullSetterFunction.h; sourceTree = "<group>"; };
 		6553A32F17A1F1EE008CF6F3 /* CommonSlowPathsExceptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommonSlowPathsExceptions.cpp; sourceTree = "<group>"; };
 		6553A33017A1F1EE008CF6F3 /* CommonSlowPathsExceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonSlowPathsExceptions.h; sourceTree = "<group>"; };
 		655EB29A10CE2581001A990E /* NodesCodegen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NodesCodegen.cpp; sourceTree = "<group>"; };
@@ -4444,6 +4447,8 @@
 				BC02E90B0E1839DB000F9297 /* NativeErrorPrototype.h */,
 				6546F51F1A32A59C006F07D5 /* NullGetterFunction.cpp */,
 				6546F5201A32A59C006F07D5 /* NullGetterFunction.h */,
+				65525FC31A6DD3B3007B5495 /* NullSetterFunction.cpp */,
+				65525FC41A6DD3B3007B5495 /* NullSetterFunction.h */,
 				BC2680C20E16D4E900A06E92 /* NumberConstructor.cpp */,
 				BC2680C30E16D4E900A06E92 /* NumberConstructor.h */,
 				F692A8700255597D01FF60F7 /* NumberObject.cpp */,
@@ -7179,6 +7184,7 @@
 				148F21B7107EC5470042EC2C /* Nodes.cpp in Sources */,
 				655EB29B10CE2581001A990E /* NodesCodegen.cpp in Sources */,
 				6546F5211A32B313006F07D5 /* NullGetterFunction.cpp in Sources */,
+				65525FC51A6DD801007B5495 /* NullSetterFunction.cpp in Sources */,
 				14469DE2107EC7E700650446 /* NumberConstructor.cpp in Sources */,
 				14469DE3107EC7E700650446 /* NumberObject.cpp in Sources */,
 				14469DE4107EC7E700650446 /* NumberPrototype.cpp in Sources */,

Modified: trunk/Source/_javascript_Core/runtime/GetterSetter.h (178695 => 178696)


--- trunk/Source/_javascript_Core/runtime/GetterSetter.h	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/runtime/GetterSetter.h	2015-01-20 05:28:04 UTC (rev 178696)
@@ -28,6 +28,7 @@
 #include "CallFrame.h"
 #include "JSGlobalObject.h"
 #include "NullGetterFunction.h"
+#include "NullSetterFunction.h"
 #include "Structure.h"
 
 namespace JSC {
@@ -48,7 +49,7 @@
         : JSCell(vm, vm.getterSetterStructure.get())
     {
         m_getter.set(vm, this, globalObject->nullGetterFunction());
-        m_setter.set(vm, this, globalObject->nullGetterFunction());
+        m_setter.set(vm, this, globalObject->nullSetterFunction());
     }
 
 public:
@@ -73,7 +74,7 @@
     }
 
     bool isGetterNull() const { return !!jsDynamicCast<NullGetterFunction*>(m_getter.get()); }
-    bool isSetterNull() const { return !!jsDynamicCast<NullGetterFunction*>(m_setter.get()); }
+    bool isSetterNull() const { return !!jsDynamicCast<NullSetterFunction*>(m_setter.get()); }
 
     // Set the getter. It's only valid to call this if you've never set the getter on this
     // object.
@@ -101,7 +102,7 @@
     void setSetter(VM& vm, JSGlobalObject* globalObject, JSObject* setter)
     {
         if (!setter)
-            setter = jsCast<JSObject*>(globalObject->nullGetterFunction());
+            setter = jsCast<JSObject*>(globalObject->nullSetterFunction());
 
         RELEASE_ASSERT(isSetterNull());
         WTF::storeStoreFence();

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (178695 => 178696)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2015-01-20 05:28:04 UTC (rev 178696)
@@ -100,6 +100,7 @@
 #include "NativeErrorConstructor.h"
 #include "NativeErrorPrototype.h"
 #include "NullGetterFunction.h"
+#include "NullSetterFunction.h"
 #include "NumberConstructor.h"
 #include "NumberPrototype.h"
 #include "ObjCCallbackFunction.h"
@@ -234,6 +235,7 @@
     m_callFunction.set(vm, this, callFunction);
     m_applyFunction.set(vm, this, applyFunction);
     m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
+    m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
     GetterSetter* protoAccessor = GetterSetter::create(vm, this);
     protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoGetter));

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (178695 => 178696)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2015-01-20 05:17:07 UTC (rev 178695)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2015-01-20 05:28:04 UTC (rev 178696)
@@ -80,6 +80,7 @@
 class RegExpPrototype;
 class SourceCode;
 class NullGetterFunction;
+class NullSetterFunction;
 struct ActivationStackNode;
 struct HashTable;
 
@@ -175,6 +176,7 @@
     WriteBarrier<ObjectConstructor> m_objectConstructor;
 
     WriteBarrier<NullGetterFunction> m_nullGetterFunction;
+    WriteBarrier<NullSetterFunction> m_nullSetterFunction;
 
     WriteBarrier<JSFunction> m_evalFunction;
     WriteBarrier<JSFunction> m_callFunction;
@@ -374,6 +376,7 @@
 #endif
 
     NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
+    NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
 
     JSFunction* evalFunction() const { return m_evalFunction.get(); }
     JSFunction* callFunction() const { return m_callFunction.get(); }

Added: trunk/Source/_javascript_Core/runtime/NullSetterFunction.cpp (0 => 178696)


--- trunk/Source/_javascript_Core/runtime/NullSetterFunction.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/NullSetterFunction.cpp	2015-01-20 05:28:04 UTC (rev 178696)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2015 Apple 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. ``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
+ * 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 "NullSetterFunction.h"
+
+#include "Error.h"
+#include "JSCInlines.h"
+#include "JSCJSValueInlines.h"
+#include "StackVisitor.h"
+
+namespace JSC {
+
+const ClassInfo NullSetterFunction::s_info = { "Function", &Base::s_info, 0, CREATE_METHOD_TABLE(NullSetterFunction) };
+
+
+class GetCallerStrictnessFunctor {
+public:
+    GetCallerStrictnessFunctor()
+        : m_iterations(0)
+        , m_callerIsStrict(false)
+    {
+    }
+
+    StackVisitor::Status operator()(StackVisitor& visitor)
+    {
+        ++m_iterations;
+        if (m_iterations < 2)
+            return StackVisitor::Continue;
+
+        CodeBlock* codeBlock = visitor->codeBlock();
+        m_callerIsStrict = codeBlock && codeBlock->isStrictMode();
+        return StackVisitor::Done;
+    }
+
+    bool callerIsStrict() const { return m_callerIsStrict; }
+
+private:
+    int m_iterations;
+    bool m_callerIsStrict;
+};
+
+static bool callerIsStrict(ExecState* exec)
+{
+    GetCallerStrictnessFunctor iter;
+    exec->iterate(iter);
+    return iter.callerIsStrict();
+}
+
+static EncodedJSValue JSC_HOST_CALL callReturnUndefined(ExecState* exec)
+{
+    if (callerIsStrict(exec))
+        return JSValue::encode(throwTypeError(exec, ASCIILiteral("Setting a property that has only a getter")));
+    return JSValue::encode(jsUndefined());
+}
+
+static EncodedJSValue JSC_HOST_CALL constructReturnUndefined(ExecState* exec)
+{
+    if (callerIsStrict(exec))
+        return JSValue::encode(throwTypeError(exec, ASCIILiteral("Setting a property that has only a getter")));
+    return JSValue::encode(jsUndefined());
+}
+
+CallType NullSetterFunction::getCallData(JSCell*, CallData& callData)
+{
+    callData.native.function = callReturnUndefined;
+    return CallTypeHost;
+}
+
+ConstructType NullSetterFunction::getConstructData(JSCell*, ConstructData& constructData)
+{
+    constructData.native.function = constructReturnUndefined;
+    return ConstructTypeHost;
+}
+
+}

Added: trunk/Source/_javascript_Core/runtime/NullSetterFunction.h (0 => 178696)


--- trunk/Source/_javascript_Core/runtime/NullSetterFunction.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/NullSetterFunction.h	2015-01-20 05:28:04 UTC (rev 178696)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2015 Apple 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. ``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
+ * 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 NullSetterFunction_h
+#define NullSetterFunction_h
+
+#include "InternalFunction.h"
+
+namespace JSC {
+
+class NullSetterFunction : public InternalFunction {
+public:
+    typedef InternalFunction Base;
+
+    static NullSetterFunction* create(VM& vm, Structure* structure)
+    {
+        NullSetterFunction* function = new (NotNull, allocateCell< NullSetterFunction>(vm.heap))  NullSetterFunction(vm, structure);
+        function->finishCreation(vm, String());
+        return function;
+    }
+
+    DECLARE_EXPORT_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+private:
+    NullSetterFunction(VM& vm, Structure* structure)
+        : Base(vm, structure)
+    {
+    }
+    static ConstructType getConstructData(JSCell*, ConstructData&);
+    static CallType getCallData(JSCell*, CallData&);
+};
+
+}
+
+#endif // NullSetterFunction_h
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to