Changeset 246346 in webkit
- Timestamp:
- Jun 11, 2019 8:18:53 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r246333 r246346 1 2019-06-11 Alexey Shvayka <shvaikalesh@gmail.com> 2 3 JSC should throw if proxy set returns falsish in strict mode context 4 https://bugs.webkit.org/show_bug.cgi?id=177398 5 6 Reviewed by Yusuke Suzuki. 7 8 1. Add coverage for Proxy `set` trap returning falsy value in strict mode. 9 2. RegExp methods throw unless [[Set]] succeeds. Return `true` from Proxy `set` traps to fix the tests. 10 11 * stress/proxy-set.js: Add 2 test cases. 12 * stress/regexp-match-proxy.js: Fix test. 13 * stress/regexp-replace-proxy.js: Fix test. 14 1 15 2019-06-11 Alexey Shvayka <shvaikalesh@gmail.com> 2 16 -
trunk/JSTests/stress/proxy-set.js
r217093 r246346 80 80 } 81 81 } 82 83 (function() { 84 "use strict"; 85 let target = { 86 x: 30 87 }; 88 89 let handler = { 90 set: function() { 91 return false; 92 } 93 }; 94 95 let proxy = new Proxy(target, handler); 96 for (let i = 0; i < 1000; i++) { 97 let threw = false; 98 try { 99 proxy.x = 40; 100 } catch(e) { 101 assert(e.toString() === "TypeError: Proxy object's 'set' trap returned falsy value for property 'x'"); 102 threw = true; 103 } 104 assert(threw); 105 } 106 })(); 107 108 (function() { 109 "use strict"; 110 let target = { 111 x: 30 112 }; 113 114 let handler = { 115 set: function() { 116 return false; 117 } 118 }; 119 120 let proxy = new Proxy(target, handler); 121 for (let i = 0; i < 1000; i++) { 122 let threw = false; 123 try { 124 proxy[42] = 40; 125 } catch(e) { 126 assert(e.toString() === "TypeError: Proxy object's 'set' trap returned falsy value for property '42'"); 127 threw = true; 128 } 129 assert(threw); 130 } 131 })(); 82 132 83 133 { -
trunk/JSTests/stress/regexp-match-proxy.js
r198625 r246346 54 54 getSet.push(k); 55 55 o[k] = v; 56 return true; 56 57 } 57 58 }); … … 84 85 getSet.push(k); 85 86 o[k] = v; 87 return true; 86 88 } 87 89 }); … … 118 120 regExpGlobal_tx_Greedy.lastIndex = v; 119 121 o[k] = v; 122 return true; 120 123 } 121 124 }); … … 153 156 regExpGlobalUnicode_digit_nonGreedy.lastIndex = v; 154 157 o[k] = v; 158 return true; 155 159 } 156 160 }); -
trunk/JSTests/stress/regexp-replace-proxy.js
r200117 r246346 51 51 getSet.push(k); 52 52 o[k] = v; 53 return true; 53 54 } 54 55 }); … … 79 80 getSet.push(k); 80 81 o[k] = v; 82 return true; 81 83 } 82 84 }); … … 111 113 regExp_phoneNumber.lastIndex = v; 112 114 o[k] = v; 115 return true; 113 116 } 114 117 }); … … 142 145 regExpGlobalUnicode_digit_nonGreedy.lastIndex = v; 143 146 o[k] = v; 147 return true; 144 148 } 145 149 }); -
trunk/Source/JavaScriptCore/ChangeLog
r246333 r246346 1 2019-06-11 Alexey Shvayka <shvaikalesh@gmail.com> 2 3 JSC should throw if proxy set returns falsish in strict mode context 4 https://bugs.webkit.org/show_bug.cgi?id=177398 5 6 Reviewed by Yusuke Suzuki. 7 8 Throw TypeError exception if Proxy's `set` trap returns falsy value. 9 (step 6.c of https://tc39.es/ecma262/#sec-putvalue) 10 11 * runtime/ProxyObject.cpp: 12 (JSC::ProxyObject::performPut): 13 (JSC::ProxyObject::put): 14 (JSC::ProxyObject::putByIndexCommon): 15 * runtime/ProxyObject.h: 16 1 17 2019-06-11 Alexey Shvayka <shvaikalesh@gmail.com> 2 18 -
trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp
r246333 r246346 410 410 411 411 template <typename PerformDefaultPutFunction> 412 bool ProxyObject::performPut(ExecState* exec, JSValue putValue, JSValue thisValue, PropertyName propertyName, PerformDefaultPutFunction performDefaultPut )412 bool ProxyObject::performPut(ExecState* exec, JSValue putValue, JSValue thisValue, PropertyName propertyName, PerformDefaultPutFunction performDefaultPut, bool shouldThrow) 413 413 { 414 414 NO_TAIL_CALLS(); … … 449 449 bool trapResultAsBool = trapResult.toBoolean(exec); 450 450 RETURN_IF_EXCEPTION(scope, false); 451 if (!trapResultAsBool) 452 return false; 451 if (!trapResultAsBool) { 452 if (shouldThrow) 453 throwVMTypeError(exec, scope, makeString("Proxy object's 'set' trap returned falsy value for property '", String(propertyName.uid()), "'")); 454 return false; 455 } 453 456 454 457 PropertyDescriptor descriptor; … … 479 482 return target->methodTable(vm)->put(target, exec, propertyName, value, slot); 480 483 }; 481 return thisObject->performPut(exec, value, slot.thisValue(), propertyName, performDefaultPut );484 return thisObject->performPut(exec, value, slot.thisValue(), propertyName, performDefaultPut, slot.isStrictMode()); 482 485 } 483 486 … … 494 497 return target->methodTable(vm)->put(target, exec, ident.impl(), putValue, slot); 495 498 }; 496 RELEASE_AND_RETURN(scope, performPut(exec, putValue, thisValue, ident.impl(), performDefaultPut ));499 RELEASE_AND_RETURN(scope, performPut(exec, putValue, thisValue, ident.impl(), performDefaultPut, shouldThrow)); 497 500 } 498 501 -
trunk/Source/JavaScriptCore/runtime/ProxyObject.h
r242636 r246346 101 101 bool performDelete(ExecState*, PropertyName, DefaultDeleteFunction); 102 102 template <typename PerformDefaultPutFunction> 103 bool performPut(ExecState*, JSValue putValue, JSValue thisValue, PropertyName, PerformDefaultPutFunction );103 bool performPut(ExecState*, JSValue putValue, JSValue thisValue, PropertyName, PerformDefaultPutFunction, bool shouldThrow); 104 104 bool performPreventExtensions(ExecState*); 105 105 bool performIsExtensible(ExecState*);
Note: See TracChangeset
for help on using the changeset viewer.