Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
| 6 // in runtime.js: | 6 // in runtime.js: |
| 7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
| 8 // var $Boolean = global.Boolean; | 8 // var $Boolean = global.Boolean; |
| 9 // var $Number = global.Number; | 9 // var $Number = global.Number; |
| 10 // var $Function = global.Function; | 10 // var $Function = global.Function; |
| (...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1384 | 1384 |
| 1385 // ECMA-262, Edition 6, section B.2.2.1.2 | 1385 // ECMA-262, Edition 6, section B.2.2.1.2 |
| 1386 function ObjectSetProto(proto) { | 1386 function ObjectSetProto(proto) { |
| 1387 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); | 1387 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); |
| 1388 | 1388 |
| 1389 if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) { | 1389 if ((IS_SPEC_OBJECT(proto) || IS_NULL(proto)) && IS_SPEC_OBJECT(this)) { |
| 1390 %SetPrototype(this, proto); | 1390 %SetPrototype(this, proto); |
| 1391 } | 1391 } |
| 1392 } | 1392 } |
| 1393 | 1393 |
| 1394 var kError = { error: UNDEFINED }; | |
| 1395 function TryCatch3(fn, arg1, arg2, arg3) { | |
| 1396 try { | |
| 1397 return fn(arg1, arg2, arg3); | |
| 1398 } catch (e) { | |
| 1399 kError.error = e; | |
|
jsbell
2014/09/08 17:22:41
Wouldn't this "leak" the exception?
(I'm not inti
caitp (gmail)
2014/09/08 17:48:27
Yes, within the sandbox it would be kept alive ---
| |
| 1400 return kError; | |
| 1401 } | |
| 1402 } | |
| 1403 | |
| 1404 function CopyEnumerableValue(to, from, p) { | |
| 1405 var desc = ObjectGetOwnPropertyDescriptor(from, p); | |
| 1406 if (!IS_UNDEFINED(desc) && desc.enumerable) { | |
| 1407 // Approximately Put() (7.3.2) | |
| 1408 %SetProperty(to, p, from[p], kStrictMode); | |
| 1409 } | |
| 1410 } | |
| 1411 | |
| 1412 | |
| 1413 function ObjectAssign(target, sources) { | |
| 1414 var to = ToObject(target); | |
| 1415 var argsLen = %_ArgumentsLength(); | |
| 1416 if (argsLen < 2) return to; | |
| 1417 | |
| 1418 for (var i = 1; i < argsLen; ++i) { | |
| 1419 var nextSource = %_Arguments(i); | |
| 1420 if (IS_NULL(nextSource) || IS_UNDEFINED(nextSource)) { | |
| 1421 continue; | |
| 1422 } | |
| 1423 | |
| 1424 var from = ToObject(nextSource); | |
| 1425 var keysArray = ObjectGetOwnPropertyKeys(from); | |
| 1426 var len = keysArray.length; | |
| 1427 var pendingException = UNDEFINED; | |
| 1428 | |
| 1429 for (var j = 0; j < len; ++j) { | |
| 1430 // Get "sort of" abrupt completion record for steps 5d i...iii | |
| 1431 // TryCatch3 moved out to ensure that ObjectAssign can be optimized | |
| 1432 // --- will measure if it makes a meaningful difference, but we've | |
| 1433 // seen that Object.assign() is pretty slow already. | |
| 1434 var record = TryCatch3(CopyEnumerableValue, to, from, keysArray[j]); | |
| 1435 if (record === kError) { | |
| 1436 if (IS_UNDEFINED(pendingException)) | |
| 1437 pendingException = kError.error; | |
| 1438 } | |
| 1439 } | |
| 1440 | |
| 1441 if (!IS_UNDEFINED(pendingException)) | |
| 1442 throw pendingException; | |
| 1443 } | |
| 1444 return to; | |
| 1445 } | |
| 1446 | |
| 1394 | 1447 |
| 1395 function ObjectConstructor(x) { | 1448 function ObjectConstructor(x) { |
| 1396 if (%_IsConstructCall()) { | 1449 if (%_IsConstructCall()) { |
| 1397 if (x == null) return this; | 1450 if (x == null) return this; |
| 1398 return ToObject(x); | 1451 return ToObject(x); |
| 1399 } else { | 1452 } else { |
| 1400 if (x == null) return { }; | 1453 if (x == null) return { }; |
| 1401 return ToObject(x); | 1454 return ToObject(x); |
| 1402 } | 1455 } |
| 1403 } | 1456 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1440 "getPrototypeOf", ObjectGetPrototypeOf, | 1493 "getPrototypeOf", ObjectGetPrototypeOf, |
| 1441 "setPrototypeOf", ObjectSetPrototypeOf, | 1494 "setPrototypeOf", ObjectSetPrototypeOf, |
| 1442 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1495 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
| 1443 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1496 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1444 // getOwnPropertySymbols is added in symbol.js. | 1497 // getOwnPropertySymbols is added in symbol.js. |
| 1445 "is", ObjectIs, | 1498 "is", ObjectIs, |
| 1446 "isExtensible", ObjectIsExtensible, | 1499 "isExtensible", ObjectIsExtensible, |
| 1447 "isFrozen", ObjectIsFrozen, | 1500 "isFrozen", ObjectIsFrozen, |
| 1448 "isSealed", ObjectIsSealed, | 1501 "isSealed", ObjectIsSealed, |
| 1449 "preventExtensions", ObjectPreventExtension, | 1502 "preventExtensions", ObjectPreventExtension, |
| 1450 "seal", ObjectSeal | 1503 "seal", ObjectSeal, |
| 1451 // deliverChangeRecords, getNotifier, observe and unobserve are added | 1504 // deliverChangeRecords, getNotifier, observe and unobserve are added |
| 1452 // in object-observe.js. | 1505 // in object-observe.js. |
| 1506 "assign", ObjectAssign | |
| 1453 )); | 1507 )); |
| 1454 } | 1508 } |
| 1455 | 1509 |
| 1456 SetUpObject(); | 1510 SetUpObject(); |
| 1457 | 1511 |
| 1458 | 1512 |
| 1459 // ---------------------------------------------------------------------------- | 1513 // ---------------------------------------------------------------------------- |
| 1460 // Boolean | 1514 // Boolean |
| 1461 | 1515 |
| 1462 function BooleanConstructor(x) { | 1516 function BooleanConstructor(x) { |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1901 } | 1955 } |
| 1902 if (!IS_SPEC_FUNCTION(method)) { | 1956 if (!IS_SPEC_FUNCTION(method)) { |
| 1903 throw MakeTypeError('not_iterable', [obj]); | 1957 throw MakeTypeError('not_iterable', [obj]); |
| 1904 } | 1958 } |
| 1905 var iterator = %_CallFunction(obj, method); | 1959 var iterator = %_CallFunction(obj, method); |
| 1906 if (!IS_SPEC_OBJECT(iterator)) { | 1960 if (!IS_SPEC_OBJECT(iterator)) { |
| 1907 throw MakeTypeError('not_an_iterator', [iterator]); | 1961 throw MakeTypeError('not_an_iterator', [iterator]); |
| 1908 } | 1962 } |
| 1909 return iterator; | 1963 return iterator; |
| 1910 } | 1964 } |
| OLD | NEW |