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 var $functionSourceString; | |
6 | |
7 (function(global, utils) { | 5 (function(global, utils) { |
8 | 6 |
9 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
10 | 8 |
11 // ---------------------------------------------------------------------------- | 9 // ---------------------------------------------------------------------------- |
12 // Imports | 10 // Imports |
13 | 11 |
14 var GlobalArray = global.Array; | 12 var GlobalArray = global.Array; |
15 var GlobalBoolean = global.Boolean; | 13 var GlobalBoolean = global.Boolean; |
16 var GlobalFunction = global.Function; | 14 var GlobalFunction = global.Function; |
17 var GlobalNumber = global.Number; | 15 var GlobalNumber = global.Number; |
18 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
19 var InternalArray = utils.InternalArray; | 17 var InternalArray = utils.InternalArray; |
20 | |
21 var MathAbs; | 18 var MathAbs; |
22 var ProxyDelegateCallAndConstruct; | 19 var ProxyDelegateCallAndConstruct; |
23 var ProxyDerivedHasOwnTrap; | 20 var ProxyDerivedHasOwnTrap; |
24 var ProxyDerivedKeysTrap; | 21 var ProxyDerivedKeysTrap; |
25 var StringIndexOf; | 22 var StringIndexOf; |
| 23 var ToBoolean; |
| 24 var ToNumber; |
| 25 var ToString; |
26 | 26 |
27 utils.Import(function(from) { | 27 utils.Import(function(from) { |
28 MathAbs = from.MathAbs; | 28 MathAbs = from.MathAbs; |
29 StringIndexOf = from.StringIndexOf; | 29 StringIndexOf = from.StringIndexOf; |
| 30 ToString = from.ToString; |
| 31 }); |
| 32 |
| 33 utils.ImportNow(function(from) { |
| 34 ToBoolean = from.ToBoolean; |
| 35 ToNumber = from.ToNumber; |
30 }); | 36 }); |
31 | 37 |
32 utils.ImportFromExperimental(function(from) { | 38 utils.ImportFromExperimental(function(from) { |
33 ProxyDelegateCallAndConstruct = from.ProxyDelegateCallAndConstruct; | 39 ProxyDelegateCallAndConstruct = from.ProxyDelegateCallAndConstruct; |
34 ProxyDerivedHasOwnTrap = from.ProxyDerivedHasOwnTrap; | 40 ProxyDerivedHasOwnTrap = from.ProxyDerivedHasOwnTrap; |
35 ProxyDerivedKeysTrap = from.ProxyDerivedKeysTrap; | 41 ProxyDerivedKeysTrap = from.ProxyDerivedKeysTrap; |
36 }); | 42 }); |
37 | 43 |
38 // ---------------------------------------------------------------------------- | 44 // ---------------------------------------------------------------------------- |
39 | 45 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 345 } |
340 | 346 |
341 | 347 |
342 // ES5 8.10.5. | 348 // ES5 8.10.5. |
343 function ToPropertyDescriptor(obj) { | 349 function ToPropertyDescriptor(obj) { |
344 if (!IS_SPEC_OBJECT(obj)) throw MakeTypeError(kPropertyDescObject, obj); | 350 if (!IS_SPEC_OBJECT(obj)) throw MakeTypeError(kPropertyDescObject, obj); |
345 | 351 |
346 var desc = new PropertyDescriptor(); | 352 var desc = new PropertyDescriptor(); |
347 | 353 |
348 if ("enumerable" in obj) { | 354 if ("enumerable" in obj) { |
349 desc.setEnumerable($toBoolean(obj.enumerable)); | 355 desc.setEnumerable(ToBoolean(obj.enumerable)); |
350 } | 356 } |
351 | 357 |
352 if ("configurable" in obj) { | 358 if ("configurable" in obj) { |
353 desc.setConfigurable($toBoolean(obj.configurable)); | 359 desc.setConfigurable(ToBoolean(obj.configurable)); |
354 } | 360 } |
355 | 361 |
356 if ("value" in obj) { | 362 if ("value" in obj) { |
357 desc.setValue(obj.value); | 363 desc.setValue(obj.value); |
358 } | 364 } |
359 | 365 |
360 if ("writable" in obj) { | 366 if ("writable" in obj) { |
361 desc.setWritable($toBoolean(obj.writable)); | 367 desc.setWritable(ToBoolean(obj.writable)); |
362 } | 368 } |
363 | 369 |
364 if ("get" in obj) { | 370 if ("get" in obj) { |
365 var get = obj.get; | 371 var get = obj.get; |
366 if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) { | 372 if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) { |
367 throw MakeTypeError(kObjectGetterCallable, get); | 373 throw MakeTypeError(kObjectGetterCallable, get); |
368 } | 374 } |
369 desc.setGet(get); | 375 desc.setGet(get); |
370 } | 376 } |
371 | 377 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 611 } |
606 | 612 |
607 | 613 |
608 // Harmony proxies. | 614 // Harmony proxies. |
609 function DefineProxyProperty(obj, p, attributes, should_throw) { | 615 function DefineProxyProperty(obj, p, attributes, should_throw) { |
610 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 616 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
611 if (IS_SYMBOL(p)) return false; | 617 if (IS_SYMBOL(p)) return false; |
612 | 618 |
613 var handler = %GetHandler(obj); | 619 var handler = %GetHandler(obj); |
614 var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); | 620 var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); |
615 if (!$toBoolean(result)) { | 621 if (!ToBoolean(result)) { |
616 if (should_throw) { | 622 if (should_throw) { |
617 throw MakeTypeError(kProxyHandlerReturned, | 623 throw MakeTypeError(kProxyHandlerReturned, |
618 handler, "false", "defineProperty"); | 624 handler, "false", "defineProperty"); |
619 } else { | 625 } else { |
620 return false; | 626 return false; |
621 } | 627 } |
622 } | 628 } |
623 return true; | 629 return true; |
624 } | 630 } |
625 | 631 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 return true; | 800 return true; |
795 } | 801 } |
796 | 802 |
797 | 803 |
798 // ES5 section 15.4.5.1. | 804 // ES5 section 15.4.5.1. |
799 function DefineArrayProperty(obj, p, desc, should_throw) { | 805 function DefineArrayProperty(obj, p, desc, should_throw) { |
800 // Step 3 - Special handling for array index. | 806 // Step 3 - Special handling for array index. |
801 if (!IS_SYMBOL(p)) { | 807 if (!IS_SYMBOL(p)) { |
802 var index = TO_UINT32(p); | 808 var index = TO_UINT32(p); |
803 var emit_splice = false; | 809 var emit_splice = false; |
804 if ($toString(index) == p && index != 4294967295) { | 810 if (ToString(index) == p && index != 4294967295) { |
805 var length = obj.length; | 811 var length = obj.length; |
806 if (index >= length && %IsObserved(obj)) { | 812 if (index >= length && %IsObserved(obj)) { |
807 emit_splice = true; | 813 emit_splice = true; |
808 $observeBeginPerformSplice(obj); | 814 $observeBeginPerformSplice(obj); |
809 } | 815 } |
810 | 816 |
811 var length_desc = GetOwnPropertyJS(obj, "length"); | 817 var length_desc = GetOwnPropertyJS(obj, "length"); |
812 if ((index >= length && !length_desc.isWritable()) || | 818 if ((index >= length && !length_desc.isWritable()) || |
813 !DefineObjectProperty(obj, p, desc, true)) { | 819 !DefineObjectProperty(obj, p, desc, true)) { |
814 if (emit_splice) | 820 if (emit_splice) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 var seenKeys = { __proto__: null }; | 968 var seenKeys = { __proto__: null }; |
963 var j = 0; | 969 var j = 0; |
964 for (var i = 0; i < propertyNames.length; ++i) { | 970 for (var i = 0; i < propertyNames.length; ++i) { |
965 var name = propertyNames[i]; | 971 var name = propertyNames[i]; |
966 if (IS_SYMBOL(name)) { | 972 if (IS_SYMBOL(name)) { |
967 if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) { | 973 if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) { |
968 continue; | 974 continue; |
969 } | 975 } |
970 } else { | 976 } else { |
971 if (filter & PROPERTY_ATTRIBUTES_STRING) continue; | 977 if (filter & PROPERTY_ATTRIBUTES_STRING) continue; |
972 name = $toString(name); | 978 name = ToString(name); |
973 } | 979 } |
974 if (seenKeys[name]) continue; | 980 if (seenKeys[name]) continue; |
975 seenKeys[name] = true; | 981 seenKeys[name] = true; |
976 propertyNames[j++] = name; | 982 propertyNames[j++] = name; |
977 } | 983 } |
978 propertyNames.length = j; | 984 propertyNames.length = j; |
979 } | 985 } |
980 | 986 |
981 return propertyNames; | 987 return propertyNames; |
982 } | 988 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 // deliverChangeRecords, getNotifier, observe and unobserve are added | 1336 // deliverChangeRecords, getNotifier, observe and unobserve are added |
1331 // in object-observe.js. | 1337 // in object-observe.js. |
1332 ]); | 1338 ]); |
1333 | 1339 |
1334 | 1340 |
1335 // ---------------------------------------------------------------------------- | 1341 // ---------------------------------------------------------------------------- |
1336 // Boolean | 1342 // Boolean |
1337 | 1343 |
1338 function BooleanConstructor(x) { | 1344 function BooleanConstructor(x) { |
1339 if (%_IsConstructCall()) { | 1345 if (%_IsConstructCall()) { |
1340 %_SetValueOf(this, $toBoolean(x)); | 1346 %_SetValueOf(this, ToBoolean(x)); |
1341 } else { | 1347 } else { |
1342 return $toBoolean(x); | 1348 return ToBoolean(x); |
1343 } | 1349 } |
1344 } | 1350 } |
1345 | 1351 |
1346 | 1352 |
1347 function BooleanToString() { | 1353 function BooleanToString() { |
1348 // NOTE: Both Boolean objects and values can enter here as | 1354 // NOTE: Both Boolean objects and values can enter here as |
1349 // 'this'. This is not as dictated by ECMA-262. | 1355 // 'this'. This is not as dictated by ECMA-262. |
1350 var b = this; | 1356 var b = this; |
1351 if (!IS_BOOLEAN(b)) { | 1357 if (!IS_BOOLEAN(b)) { |
1352 if (!IS_BOOLEAN_WRAPPER(b)) { | 1358 if (!IS_BOOLEAN_WRAPPER(b)) { |
(...skipping 25 matching lines...) Expand all Loading... |
1378 utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ | 1384 utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ |
1379 "toString", BooleanToString, | 1385 "toString", BooleanToString, |
1380 "valueOf", BooleanValueOf | 1386 "valueOf", BooleanValueOf |
1381 ]); | 1387 ]); |
1382 | 1388 |
1383 | 1389 |
1384 // ---------------------------------------------------------------------------- | 1390 // ---------------------------------------------------------------------------- |
1385 // Number | 1391 // Number |
1386 | 1392 |
1387 function NumberConstructor(x) { | 1393 function NumberConstructor(x) { |
1388 var value = %_ArgumentsLength() == 0 ? 0 : $toNumber(x); | 1394 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); |
1389 if (%_IsConstructCall()) { | 1395 if (%_IsConstructCall()) { |
1390 %_SetValueOf(this, value); | 1396 %_SetValueOf(this, value); |
1391 } else { | 1397 } else { |
1392 return value; | 1398 return value; |
1393 } | 1399 } |
1394 } | 1400 } |
1395 | 1401 |
1396 | 1402 |
1397 // ECMA-262 section 15.7.4.2. | 1403 // ECMA-262 section 15.7.4.2. |
1398 function NumberToStringJS(radix) { | 1404 function NumberToStringJS(radix) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 function NumberToPrecisionJS(precision) { | 1497 function NumberToPrecisionJS(precision) { |
1492 var x = this; | 1498 var x = this; |
1493 if (!IS_NUMBER(this)) { | 1499 if (!IS_NUMBER(this)) { |
1494 if (!IS_NUMBER_WRAPPER(this)) { | 1500 if (!IS_NUMBER_WRAPPER(this)) { |
1495 throw MakeTypeError(kIncompatibleMethodReceiver, | 1501 throw MakeTypeError(kIncompatibleMethodReceiver, |
1496 "Number.prototype.toPrecision", this); | 1502 "Number.prototype.toPrecision", this); |
1497 } | 1503 } |
1498 // Get the value of this number in case it's an object. | 1504 // Get the value of this number in case it's an object. |
1499 x = %_ValueOf(this); | 1505 x = %_ValueOf(this); |
1500 } | 1506 } |
1501 if (IS_UNDEFINED(precision)) return $toString(%_ValueOf(this)); | 1507 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); |
1502 var p = TO_INTEGER(precision); | 1508 var p = TO_INTEGER(precision); |
1503 | 1509 |
1504 if (NUMBER_IS_NAN(x)) return "NaN"; | 1510 if (NUMBER_IS_NAN(x)) return "NaN"; |
1505 if (x == INFINITY) return "Infinity"; | 1511 if (x == INFINITY) return "Infinity"; |
1506 if (x == -INFINITY) return "-Infinity"; | 1512 if (x == -INFINITY) return "-Infinity"; |
1507 | 1513 |
1508 if (p < 1 || p > 21) { | 1514 if (p < 1 || p > 21) { |
1509 throw MakeRangeError(kToPrecisionFormatRange); | 1515 throw MakeRangeError(kToPrecisionFormatRange); |
1510 } | 1516 } |
1511 return %NumberToPrecision(x, p); | 1517 return %NumberToPrecision(x, p); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 // To be consistent with our normal functions we leave this as it is. | 1717 // To be consistent with our normal functions we leave this as it is. |
1712 // TODO(lrn): Do set these to be thrower. | 1718 // TODO(lrn): Do set these to be thrower. |
1713 return result; | 1719 return result; |
1714 } | 1720 } |
1715 | 1721 |
1716 | 1722 |
1717 function NewFunctionString(args, function_token) { | 1723 function NewFunctionString(args, function_token) { |
1718 var n = args.length; | 1724 var n = args.length; |
1719 var p = ''; | 1725 var p = ''; |
1720 if (n > 1) { | 1726 if (n > 1) { |
1721 p = $toString(args[0]); | 1727 p = ToString(args[0]); |
1722 for (var i = 1; i < n - 1; i++) { | 1728 for (var i = 1; i < n - 1; i++) { |
1723 p += ',' + $toString(args[i]); | 1729 p += ',' + ToString(args[i]); |
1724 } | 1730 } |
1725 // If the formal parameters string include ) - an illegal | 1731 // If the formal parameters string include ) - an illegal |
1726 // character - it may make the combined function expression | 1732 // character - it may make the combined function expression |
1727 // compile. We avoid this problem by checking for this early on. | 1733 // compile. We avoid this problem by checking for this early on. |
1728 if (%_CallFunction(p, ')', StringIndexOf) != -1) { | 1734 if (%_CallFunction(p, ')', StringIndexOf) != -1) { |
1729 throw MakeSyntaxError(kParenthesisInArgString); | 1735 throw MakeSyntaxError(kParenthesisInArgString); |
1730 } | 1736 } |
1731 // If the formal parameters include an unbalanced block comment, the | 1737 // If the formal parameters include an unbalanced block comment, the |
1732 // function must be rejected. Since JavaScript does not allow nested | 1738 // function must be rejected. Since JavaScript does not allow nested |
1733 // comments we can include a trailing block comment to catch this. | 1739 // comments we can include a trailing block comment to catch this. |
1734 p += '\n/' + '**/'; | 1740 p += '\n/' + '**/'; |
1735 } | 1741 } |
1736 var body = (n > 0) ? $toString(args[n - 1]) : ''; | 1742 var body = (n > 0) ? ToString(args[n - 1]) : ''; |
1737 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; | 1743 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; |
1738 } | 1744 } |
1739 | 1745 |
1740 | 1746 |
1741 function FunctionConstructor(arg1) { // length == 1 | 1747 function FunctionConstructor(arg1) { // length == 1 |
1742 var source = NewFunctionString(arguments, 'function'); | 1748 var source = NewFunctionString(arguments, 'function'); |
1743 var global_proxy = %GlobalProxy(FunctionConstructor); | 1749 var global_proxy = %GlobalProxy(FunctionConstructor); |
1744 // Compile the string in the constructor and not a helper so that errors | 1750 // Compile the string in the constructor and not a helper so that errors |
1745 // appear to come from here. | 1751 // appear to come from here. |
1746 var f = %_CallFunction(global_proxy, %CompileString(source, true)); | 1752 var f = %_CallFunction(global_proxy, %CompileString(source, true)); |
(...skipping 28 matching lines...) Expand all Loading... |
1775 var iterator = %_CallFunction(obj, method); | 1781 var iterator = %_CallFunction(obj, method); |
1776 if (!IS_SPEC_OBJECT(iterator)) { | 1782 if (!IS_SPEC_OBJECT(iterator)) { |
1777 throw MakeTypeError(kNotAnIterator, iterator); | 1783 throw MakeTypeError(kNotAnIterator, iterator); |
1778 } | 1784 } |
1779 return iterator; | 1785 return iterator; |
1780 } | 1786 } |
1781 | 1787 |
1782 // ---------------------------------------------------------------------------- | 1788 // ---------------------------------------------------------------------------- |
1783 // Exports | 1789 // Exports |
1784 | 1790 |
1785 $functionSourceString = FunctionSourceString; | |
1786 | |
1787 utils.ObjectDefineProperties = ObjectDefineProperties; | |
1788 utils.ObjectDefineProperty = ObjectDefineProperty; | |
1789 | |
1790 utils.Export(function(to) { | 1791 utils.Export(function(to) { |
1791 to.Delete = Delete; | 1792 to.Delete = Delete; |
| 1793 to.FunctionSourceString = FunctionSourceString; |
1792 to.GetIterator = GetIterator; | 1794 to.GetIterator = GetIterator; |
1793 to.GetMethod = GetMethod; | 1795 to.GetMethod = GetMethod; |
1794 to.IsFinite = GlobalIsFinite; | 1796 to.IsFinite = GlobalIsFinite; |
1795 to.IsNaN = GlobalIsNaN; | 1797 to.IsNaN = GlobalIsNaN; |
1796 to.NewFunctionString = NewFunctionString; | 1798 to.NewFunctionString = NewFunctionString; |
1797 to.NumberIsNaN = NumberIsNaN; | 1799 to.NumberIsNaN = NumberIsNaN; |
| 1800 to.ObjectDefineProperties = ObjectDefineProperties; |
1798 to.ObjectDefineProperty = ObjectDefineProperty; | 1801 to.ObjectDefineProperty = ObjectDefineProperty; |
1799 to.ObjectFreeze = ObjectFreezeJS; | 1802 to.ObjectFreeze = ObjectFreezeJS; |
1800 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; | 1803 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; |
1801 to.ObjectHasOwnProperty = ObjectHasOwnProperty; | 1804 to.ObjectHasOwnProperty = ObjectHasOwnProperty; |
1802 to.ObjectIsFrozen = ObjectIsFrozen; | 1805 to.ObjectIsFrozen = ObjectIsFrozen; |
1803 to.ObjectIsSealed = ObjectIsSealed; | 1806 to.ObjectIsSealed = ObjectIsSealed; |
1804 to.ObjectToString = ObjectToString; | 1807 to.ObjectToString = ObjectToString; |
1805 to.OwnPropertyKeys = OwnPropertyKeys; | 1808 to.OwnPropertyKeys = OwnPropertyKeys; |
1806 to.ToNameArray = ToNameArray; | 1809 to.ToNameArray = ToNameArray; |
1807 }); | 1810 }); |
1808 | 1811 |
1809 utils.ExportToRuntime(function(to) { | 1812 utils.ExportToRuntime(function(to) { |
1810 to.GlobalEval = GlobalEval; | 1813 to.GlobalEval = GlobalEval; |
1811 to.ObjectDefineOwnProperty = DefineOwnPropertyFromAPI; | 1814 to.ObjectDefineOwnProperty = DefineOwnPropertyFromAPI; |
1812 to.ObjectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor; | 1815 to.ObjectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor; |
1813 to.ToCompletePropertyDescriptor = ToCompletePropertyDescriptor; | 1816 to.ToCompletePropertyDescriptor = ToCompletePropertyDescriptor; |
1814 }); | 1817 }); |
1815 | 1818 |
1816 }) | 1819 }) |
OLD | NEW |