Changeset 114185 in webkit
- Timestamp:
- Apr 13, 2012 5:26:25 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r114183 r114185 1 2012-04-13 Hojong Han <hojong.han@samsung.com> 2 3 Array.prototype.toString and Array.prototype.toLocaleString should be generic 4 https://bugs.webkit.org/show_bug.cgi?id=81588 5 6 Reviewed by Gavin Barraclough. 7 8 * runtime/ArrayPrototype.cpp: 9 (JSC::arrayProtoFuncToString): 10 (JSC::arrayProtoFuncToLocaleString): 11 * runtime/CommonIdentifiers.h: 12 * tests/mozilla/ecma/Array/15.4.4.2.js: 13 (getTestCases.array.item.new.TestCase): 14 (getTestCases): 15 1 16 2012-04-13 Gavin Barraclough <barraclough@apple.com> 2 17 -
trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r113396 r114185 255 255 JSValue thisValue = exec->hostThisValue(); 256 256 257 bool isRealArray = isJSArray(thisValue); 258 if (!isRealArray && !thisValue.inherits(&JSArray::s_info)) 259 return throwVMTypeError(exec); 257 JSObject* thisObject = thisValue.toObject(exec); 258 if (exec->hadException()) 259 return JSValue::encode(jsUndefined()); 260 261 JSValue function = JSValue(thisObject).get(exec, exec->propertyNames().join); 262 if (!function.isCell()) 263 return objectProtoFuncToString(exec); 264 265 CallData callData; 266 CallType callType = getCallData(function, callData); 267 if (callType == CallTypeNone) 268 return objectProtoFuncToString(exec); 269 270 if (!isJSArray(thisObject) || callType != CallTypeHost || callData.native.function != arrayProtoFuncJoin) 271 return JSValue::encode(call(exec, function, callType, callData, thisObject, exec->emptyList())); 272 273 ASSERT(isJSArray(thisValue)); 260 274 JSArray* thisObj = asArray(thisValue); 261 275 262 276 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); 263 277 if (exec->hadException()) … … 274 288 for (unsigned k = 0; k < length; k++) { 275 289 JSValue element; 276 if ( isRealArray &&thisObj->canGetIndex(k))290 if (thisObj->canGetIndex(k)) 277 291 element = thisObj->getIndex(k); 278 292 else … … 332 346 JSValue thisValue = exec->hostThisValue(); 333 347 334 if (!thisValue.inherits(&JSArray::s_info))335 return throwVMTypeError(exec);336 JSObject* thisObj = asArray(thisValue);348 JSObject* thisObj = thisValue.toObject(exec); 349 if (exec->hadException()) 350 return JSValue::encode(jsUndefined()); 337 351 338 352 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); … … 361 375 str = call(exec, conversionFunction, callType, callData, element, exec->emptyList()).toUString(exec); 362 376 else 363 str = element.toUString(exec);377 return throwVMTypeError(exec); 364 378 if (exec->hadException()) 365 379 return JSValue::encode(jsUndefined()); 366 380 stringJoiner.append(str); 367 } 381 } else 382 return JSValue::encode(jsEmptyString(exec)); 368 383 } 369 384 -
trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h
r113396 r114185 73 73 macro(valueOf) \ 74 74 macro(writable) \ 75 macro(displayName) 75 macro(displayName)\ 76 macro(join) 76 77 77 78 #define JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(macro) \ -
trunk/Source/JavaScriptCore/tests/mozilla/ecma/Array/15.4.4.2.js
r43410 r114185 56 56 array[item++] = new TestCase( SECTION, "(new Array(void 0,null)).toString()", ",", (new Array(void 0,null)).toString() ); 57 57 58 array[item++] = new TestCase( SECTION, 59 "{__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', length: 3}.toString()", 60 "a,b,c", 61 {__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', length: 3}.toString() ); 62 array[item++] = new TestCase( SECTION, 63 "{__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', join: function() { return 'join' }}.toString()", 64 "join", 65 {__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', join: function() { return 'join' }}.toString() ); 66 array[item++] = new TestCase( SECTION, 67 "Array.prototype.toString.call({join: function() { return 'join' }})", 68 "join", 69 Array.prototype.toString.call({join: function() { return 'join' }}) ); 70 array[item++] = new TestCase( SECTION, 71 "Array.prototype.toString.call({sort: function() { return 'sort' }})", 72 "[object Object]", 73 Array.prototype.toString.call({sort: function() { return 'sort' }}) ); 74 array[item++] = new TestCase( SECTION, 75 "Array.prototype.toString.call(new Date)", 76 "[object Date]", 77 Array.prototype.toString.call(new Date) ); 78 array[item++] = new TestCase( SECTION, 79 "Number.prototype.join = function() { return 'number join' }; Array.prototype.toString.call(42)", 80 "number join", 81 eval("Number.prototype.join = function() { return 'number join' }; Array.prototype.toString.call(42)") ); 82 58 83 var EXPECT_STRING = ""; 59 84 var MYARR = new Array(); … … 68 93 array[item++] = new TestCase( SECTION, "MYARR.toString()", EXPECT_STRING, MYARR.toString() ); 69 94 95 array[item++] = new TestCase( SECTION, 96 "Array.prototype.join = function() { return 'join' }; [0, 1, 2].toString()", 97 "join", 98 eval("Array.prototype.join = function() { return 'join' }; [0, 1, 2].toString()") ); 70 99 71 100 return ( array );
Note: See TracChangeset
for help on using the changeset viewer.