Changeset 109824 in webkit
- Timestamp:
- Mar 5, 2012 5:18:42 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r109820 r109824 1 2012-03-05 Gavin Barraclough <barraclough@apple.com> 2 3 putByIndex should throw in strict mode 4 https://bugs.webkit.org/show_bug.cgi?id=80335 5 6 Reviewed by Filip Pizlo. 7 8 * fast/js/primitive-property-access-edge-cases-expected.txt: 9 * fast/js/script-tests/primitive-property-access-edge-cases.js: 10 (checkNumericGet.Object.defineProperty): 11 (checkNumericSet.Object.defineProperty): 12 (checkNumericGetStrict.Object.defineProperty): 13 (checkNumericSetStrict.Object.defineProperty): 14 (checkNumericRead): 15 (checkNumericWrite): 16 (checkNumericReadStrict): 17 (checkNumericWriteStrict): 18 - Added test cases. 19 1 20 2012-03-05 Stephen Chenney <schenney@chromium.org> 2 21 -
trunk/LayoutTests/fast/js/primitive-property-access-edge-cases-expected.txt
r109177 r109824 28 28 PASS checkWriteStrict('hello', String) threw exception TypeError: Attempted to assign to readonly property.. 29 29 PASS checkWriteStrict(true, Boolean) threw exception TypeError: Attempted to assign to readonly property.. 30 PASS checkNumericGet(1, Number) is true 31 PASS checkNumericGet('hello', String) is true 32 PASS checkNumericGet(true, Boolean) is true 33 PASS checkNumericSet(1, Number) is true 34 PASS checkNumericSet('hello', String) is true 35 PASS checkNumericSet(true, Boolean) is true 36 PASS checkNumericGetStrict(1, Number) is true 37 PASS checkNumericGetStrict('hello', String) is true 38 PASS checkNumericGetStrict(true, Boolean) is true 39 PASS checkNumericSetStrict(1, Number) is true 40 PASS checkNumericSetStrict(true, Boolean) is true 41 PASS checkNumericRead(1, Number) is true 42 PASS checkNumericRead('hello', String) is true 43 PASS checkNumericRead(true, Boolean) is true 44 PASS checkNumericWrite(1, Number) is true 45 PASS checkNumericWrite('hello', String) is true 46 PASS checkNumericWrite(true, Boolean) is true 47 PASS checkNumericReadStrict(1, Number) is true 48 PASS checkNumericReadStrict('hello', String) is true 49 PASS checkNumericReadStrict(true, Boolean) is true 50 PASS checkNumericWriteStrict(1, Number) threw exception TypeError: Attempted to assign to readonly property.. 51 PASS checkNumericWriteStrict(true, Boolean) threw exception TypeError: Attempted to assign to readonly property.. 30 52 PASS didNotCrash is true 31 53 PASS successfullyParsed is true -
trunk/LayoutTests/fast/js/script-tests/primitive-property-access-edge-cases.js
r109177 r109824 127 127 shouldThrow("checkWriteStrict(true, Boolean)"); 128 128 129 function checkNumericGet(x, constructor) 130 { 131 checkOkay = false; 132 Object.defineProperty(constructor.prototype, 42, { get: function() { checkOkay = typeof this === 'object'; }, configurable: true }); 133 x[42]; 134 delete constructor.prototype[42]; 135 return checkOkay; 136 } 137 138 function checkNumericSet(x, constructor) 139 { 140 checkOkay = false; 141 Object.defineProperty(constructor.prototype, 42, { set: function() { checkOkay = typeof this === 'object'; }, configurable: true }); 142 x[42] = null; 143 delete constructor.prototype[42]; 144 return checkOkay; 145 } 146 147 function checkNumericGetStrict(x, constructor) 148 { 149 checkOkay = false; 150 Object.defineProperty(constructor.prototype, 42, { get: function() { "use strict"; checkOkay = typeof this !== 'object'; }, configurable: true }); 151 x[42]; 152 delete constructor.prototype[42]; 153 return checkOkay; 154 } 155 156 function checkNumericSetStrict(x, constructor) 157 { 158 checkOkay = false; 159 Object.defineProperty(constructor.prototype, 42, { set: function() { "use strict"; checkOkay = typeof this !== 'object'; }, configurable: true }); 160 x[42] = null; 161 delete constructor.prototype[42]; 162 return checkOkay; 163 } 164 165 shouldBeTrue("checkNumericGet(1, Number)"); 166 shouldBeTrue("checkNumericGet('hello', String)"); 167 shouldBeTrue("checkNumericGet(true, Boolean)"); 168 shouldBeTrue("checkNumericSet(1, Number)"); 169 shouldBeTrue("checkNumericSet('hello', String)"); 170 shouldBeTrue("checkNumericSet(true, Boolean)"); 171 shouldBeTrue("checkNumericGetStrict(1, Number)"); 172 shouldBeTrue("checkNumericGetStrict('hello', String)"); 173 shouldBeTrue("checkNumericGetStrict(true, Boolean)"); 174 shouldBeTrue("checkNumericSetStrict(1, Number)"); 175 //shouldBeTrue("checkNumericSetStrict('hello', String)"); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=80335 176 shouldBeTrue("checkNumericSetStrict(true, Boolean)"); 177 178 function checkNumericRead(x, constructor) 179 { 180 return x[42] === undefined; 181 } 182 183 function checkNumericWrite(x, constructor) 184 { 185 x[42] = null; 186 return x[42] === undefined; 187 } 188 189 function checkNumericReadStrict(x, constructor) 190 { 191 "use strict"; 192 return x[42] === undefined; 193 } 194 195 function checkNumericWriteStrict(x, constructor) 196 { 197 "use strict"; 198 x[42] = null; 199 return x[42] === undefined; 200 } 201 202 shouldBeTrue("checkNumericRead(1, Number)"); 203 shouldBeTrue("checkNumericRead('hello', String)"); 204 shouldBeTrue("checkNumericRead(true, Boolean)"); 205 shouldBeTrue("checkNumericWrite(1, Number)"); 206 shouldBeTrue("checkNumericWrite('hello', String)"); 207 shouldBeTrue("checkNumericWrite(true, Boolean)"); 208 shouldBeTrue("checkNumericReadStrict(1, Number)"); 209 shouldBeTrue("checkNumericReadStrict('hello', String)"); 210 shouldBeTrue("checkNumericReadStrict(true, Boolean)"); 211 shouldThrow("checkNumericWriteStrict(1, Number)"); 212 //shouldThrow("checkNumericWriteStrict('hello', String)"); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=80335 213 shouldThrow("checkNumericWriteStrict(true, Boolean)"); 214 129 215 shouldBeTrue("didNotCrash"); -
trunk/Source/JavaScriptCore/ChangeLog
r109804 r109824 1 2012-03-05 Gavin Barraclough <barraclough@apple.com> 2 3 putByIndex should throw in strict mode 4 https://bugs.webkit.org/show_bug.cgi?id=80335 5 6 Reviewed by Filip Pizlo. 7 8 We'll need to pass an additional parameter. 9 10 Part 1 - rename JSValue::put() for integer indices to JSValue::putByIndex() 11 to match the method in the MethodTable, make this take a parameter indicating 12 whether the put should throw. This fixes the cases where the base of the put 13 is a primitive. 14 15 * dfg/DFGOperations.cpp: 16 (DFG): 17 (JSC::DFG::putByVal): 18 (JSC::DFG::operationPutByValInternal): 19 * interpreter/Interpreter.cpp: 20 (JSC::Interpreter::execute): 21 (JSC::Interpreter::privateExecute): 22 * jit/JITStubs.cpp: 23 (JSC::DEFINE_STUB_FUNCTION): 24 * llint/LLIntSlowPaths.cpp: 25 (JSC::LLInt::LLINT_SLOW_PATH_DECL): 26 * runtime/JSObject.h: 27 (JSC::JSValue::putByIndex): 28 * runtime/JSValue.cpp: 29 (JSC): 30 * runtime/JSValue.h: 31 (JSValue): 32 1 33 2012-03-05 Sam Weinig <sam@webkit.org> 2 34 -
trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp
r109172 r109824 147 147 namespace JSC { namespace DFG { 148 148 149 template<bool strict> 149 150 static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value) 150 151 { … … 176 177 } 177 178 178 baseValue.put (exec, index, value);179 baseValue.putByIndex(exec, index, value, strict); 179 180 } 180 181 … … 190 191 191 192 if (LIKELY(property.isUInt32())) { 192 putByVal (exec, baseValue, property.asUInt32(), value);193 putByVal<strict>(exec, baseValue, property.asUInt32(), value); 193 194 return; 194 195 } … … 198 199 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble); 199 200 if (propertyAsDouble == propertyAsUInt32) { 200 putByVal (exec, baseValue, propertyAsUInt32, value);201 putByVal<strict>(exec, baseValue, propertyAsUInt32, value); 201 202 return; 202 203 } -
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r109627 r109824 1159 1159 } 1160 1160 case JSONPPathEntryTypeLookup: { 1161 baseObject.put (callFrame, JSONPPath.last().m_pathIndex, JSONPValue);1161 baseObject.putByIndex(callFrame, JSONPPath.last().m_pathIndex, JSONPValue, slot.isStrictMode()); 1162 1162 if (callFrame->hadException()) 1163 1163 return jsUndefined(); … … 3791 3791 jsByteArray->setIndex(i, jsValue.asDouble()); 3792 3792 else 3793 baseValue.put (callFrame, i, jsValue);3793 baseValue.putByIndex(callFrame, i, jsValue, codeBlock->isStrictMode()); 3794 3794 } else 3795 baseValue.put (callFrame, i, callFrame->r(value).jsValue());3795 baseValue.putByIndex(callFrame, i, callFrame->r(value).jsValue(), codeBlock->isStrictMode()); 3796 3796 } else { 3797 3797 Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame)); … … 3856 3856 int value = vPC[3].u.operand; 3857 3857 3858 callFrame->r(base).jsValue().put(callFrame, property, callFrame->r(value).jsValue()); 3858 JSValue arrayValue = callFrame->r(base).jsValue(); 3859 ASSERT(isJSArray(arrayValue)); 3860 asArray(arrayValue)->putDirectIndex(callFrame, property, callFrame->r(value).jsValue(), false); 3859 3861 3860 3862 vPC += OPCODE_LENGTH(op_put_by_index); -
trunk/Source/JavaScriptCore/jit/JITStubs.cpp
r109705 r109824 2569 2569 } 2570 2570 2571 baseValue.put (callFrame, i, value);2571 baseValue.putByIndex(callFrame, i, value, callFrame->codeBlock()->isStrictMode()); 2572 2572 } else 2573 baseValue.put (callFrame, i, value);2573 baseValue.putByIndex(callFrame, i, value, callFrame->codeBlock()->isStrictMode()); 2574 2574 } else { 2575 2575 Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame)); … … 2612 2612 if (!isJSByteArray(baseValue)) 2613 2613 ctiPatchCallByReturnAddress(callFrame->codeBlock(), STUB_RETURN_ADDRESS, FunctionPtr(cti_op_put_by_val)); 2614 baseValue.put (callFrame, i, value);2614 baseValue.putByIndex(callFrame, i, value, callFrame->codeBlock()->isStrictMode()); 2615 2615 } else { 2616 2616 Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame)); … … 3403 3403 unsigned property = stackFrame.args[1].int32(); 3404 3404 3405 stackFrame.args[0].jsValue().put(callFrame, property, stackFrame.args[2].jsValue()); 3405 JSValue arrayValue = stackFrame.args[0].jsValue(); 3406 ASSERT(isJSArray(arrayValue)); 3407 asArray(arrayValue)->putDirectIndex(callFrame, property, stackFrame.args[2].jsValue(), false); 3406 3408 } 3407 3409 -
trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
r109705 r109824 1060 1060 } 1061 1061 } 1062 baseValue.put (exec, i, value);1062 baseValue.putByIndex(exec, i, value, exec->codeBlock()->isStrictMode()); 1063 1063 LLINT_END(); 1064 1064 } … … 1100 1100 { 1101 1101 LLINT_BEGIN(); 1102 LLINT_OP_C(1).jsValue().put(exec, pc[2].u.operand, LLINT_OP_C(3).jsValue()); 1102 JSValue arrayValue = LLINT_OP_C(1).jsValue(); 1103 ASSERT(isJSArray(arrayValue)); 1104 asArray(arrayValue)->putDirectIndex(exec, pc[2].u.operand, LLINT_OP_C(3).jsValue(), false); 1103 1105 LLINT_END(); 1104 1106 } -
trunk/Source/JavaScriptCore/runtime/JSObject.h
r109177 r109824 841 841 } 842 842 843 inline void JSValue::put (ExecState* exec, unsigned propertyName, JSValue value)843 inline void JSValue::putByIndex(ExecState* exec, unsigned propertyName, JSValue value, bool shouldThrow) 844 844 { 845 845 if (UNLIKELY(!isCell())) { 846 JSObject* thisObject = synthesizeObject(exec);847 thisObject->methodTable()->putByIndex(thisObject, exec, propertyName, value);846 PutPropertySlot slot(shouldThrow); 847 putToPrimitive(exec, Identifier::from(exec, propertyName), value, slot); 848 848 return; 849 849 } -
trunk/Source/JavaScriptCore/runtime/JSValue.cpp
r109177 r109824 90 90 ASSERT(isUndefinedOrNull()); 91 91 return exec->globalThisValue(); 92 }93 94 JSObject* JSValue::synthesizeObject(ExecState* exec) const95 {96 ASSERT(!isCell());97 if (isNumber())98 return constructNumber(exec, exec->lexicalGlobalObject(), asValue());99 if (isBoolean())100 return constructBooleanFromImmediateBoolean(exec, exec->lexicalGlobalObject(), asValue());101 102 ASSERT(isUndefinedOrNull());103 throwError(exec, createNotAnObjectError(exec, *this));104 return JSNotAnObject::create(exec);105 92 } 106 93 -
trunk/Source/JavaScriptCore/runtime/JSValue.h
r109177 r109824 223 223 void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&); 224 224 void putToPrimitive(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&); 225 void put (ExecState*, unsigned propertyName, JSValue);225 void putByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow); 226 226 227 227 JSObject* toThisObject(ExecState*) const; … … 253 253 JS_EXPORT_PRIVATE JSObject* toObjectSlowCase(ExecState*, JSGlobalObject*) const; 254 254 JS_EXPORT_PRIVATE JSObject* toThisObjectSlowCase(ExecState*) const; 255 256 JSObject* synthesizeObject(ExecState*) const;257 255 258 256 #if USE(JSVALUE32_64)
Note: See TracChangeset
for help on using the changeset viewer.