Explorar el Código

[MERGE #5411 @pleath] OS#16092623: When we have an accessor cache hit on a setter, we still need to check for exception conditions such as undefined setter in strict mode

Merge pull request #5411 from pleath:16092623
Paul Leathers hace 7 años
padre
commit
23533190d3
Se han modificado 3 ficheros con 48 adiciones y 2 borrados
  1. 12 2
      lib/Runtime/Language/InlineCache.inl
  2. 5 0
      test/es5/rlexe.xml
  3. 31 0
      test/es5/strictdefaultsetter.js

+ 12 - 2
lib/Runtime/Language/InlineCache.inl

@@ -340,7 +340,12 @@ namespace Js
             }
 
             Assert(setterValue == nullptr || setterValue == function);
-            Js::JavascriptOperators::CallSetter(function, object, propertyValue, requestContext);
+
+            if (!JavascriptError::ThrowIfStrictModeUndefinedSetter(propertyOperationFlags, function, requestContext) &&
+                !JavascriptError::ThrowIfNotExtensibleUndefinedSetter(propertyOperationFlags, function, requestContext))
+            {
+                Js::JavascriptOperators::CallSetter(function, object, propertyValue, requestContext);
+            }
 
             if (ReturnOperationInfo)
             {
@@ -366,7 +371,12 @@ namespace Js
             }
 
             Assert(setterValue == nullptr || setterValue == function);
-            Js::JavascriptOperators::CallSetter(function, object, propertyValue, requestContext);
+
+            if (!JavascriptError::ThrowIfStrictModeUndefinedSetter(propertyOperationFlags, function, requestContext) &&
+                !JavascriptError::ThrowIfNotExtensibleUndefinedSetter(propertyOperationFlags, function, requestContext))
+            {
+                Js::JavascriptOperators::CallSetter(function, object, propertyValue, requestContext);
+            }
 
             if (ReturnOperationInfo)
             {

+ 5 - 0
test/es5/rlexe.xml

@@ -362,4 +362,9 @@
       <files>es5_defineProperty_arrayLength.js</files>
     </default>
   </test>
+  <test>
+    <default>
+      <files>strictdefaultsetter.js</files>
+    </default>
+  </test>
 </regress-exe>

+ 31 - 0
test/es5/strictdefaultsetter.js

@@ -0,0 +1,31 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+'use strict';
+
+function f(o) {
+    o.x = 'me';
+}
+
+var o1 = { set x(v) { val = v; } };
+var o2 = { get x() { WScript.Echo('get') } };
+
+var val = 'you';
+f(o1);
+if (val !== 'me') WScript.Echo('fail 1');
+val = 'you';
+f(o1);
+if (val !== 'me') WScript.Echo('fail 2');
+try {
+    f(o2);
+}
+catch(e) {
+    val = e;
+}
+if (val.toString() === 'TypeError: Assignment to read-only properties is not allowed in strict mode')
+    WScript.Echo('pass');
+else
+    WScript.Echo('fail 3');
+