| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ---------------------------------------------------------------------------- | 9 // ---------------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| 11 | 11 |
| 12 var GlobalArray = global.Array; | 12 var GlobalArray = global.Array; |
| 13 var GlobalBoolean = global.Boolean; | 13 var GlobalBoolean = global.Boolean; |
| 14 var GlobalFunction = global.Function; | 14 var GlobalFunction = global.Function; |
| 15 var GlobalNumber = global.Number; | 15 var GlobalNumber = global.Number; |
| 16 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
| 17 var InternalArray = utils.InternalArray; | 17 var InternalArray = utils.InternalArray; |
| 18 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 18 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
| 19 var MakeRangeError; | 19 var MakeRangeError; |
| 20 var MakeSyntaxError; | 20 var MakeSyntaxError; |
| 21 var MakeTypeError; | 21 var MakeTypeError; |
| 22 var MathAbs; | 22 var MathAbs; |
| 23 var NaN = %GetRootNaN(); | 23 var NaN = %GetRootNaN(); |
| 24 var ObjectToString = utils.ImportNow("object_to_string"); | 24 var ObjectToString = utils.ImportNow("object_to_string"); |
| 25 var ObserveBeginPerformSplice; | 25 var ObserveBeginPerformSplice; |
| 26 var ObserveEndPerformSplice; | 26 var ObserveEndPerformSplice; |
| 27 var ObserveEnqueueSpliceRecord; | 27 var ObserveEnqueueSpliceRecord; |
| 28 var SameValue = utils.ImportNow("SameValue"); | 28 var SameValue = utils.ImportNow("SameValue"); |
| 29 var StringIndexOf; | |
| 30 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 29 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 31 | 30 |
| 32 utils.Import(function(from) { | 31 utils.Import(function(from) { |
| 33 MakeRangeError = from.MakeRangeError; | 32 MakeRangeError = from.MakeRangeError; |
| 34 MakeSyntaxError = from.MakeSyntaxError; | 33 MakeSyntaxError = from.MakeSyntaxError; |
| 35 MakeTypeError = from.MakeTypeError; | 34 MakeTypeError = from.MakeTypeError; |
| 36 MathAbs = from.MathAbs; | 35 MathAbs = from.MathAbs; |
| 37 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice; | 36 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice; |
| 38 ObserveEndPerformSplice = from.ObserveEndPerformSplice; | 37 ObserveEndPerformSplice = from.ObserveEndPerformSplice; |
| 39 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord; | 38 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord; |
| 40 StringIndexOf = from.StringIndexOf; | |
| 41 }); | 39 }); |
| 42 | 40 |
| 43 // ---------------------------------------------------------------------------- | 41 // ---------------------------------------------------------------------------- |
| 44 | 42 |
| 45 | 43 |
| 46 // ES6 18.2.3 isNaN(number) | 44 // ES6 18.2.3 isNaN(number) |
| 47 function GlobalIsNaN(number) { | 45 function GlobalIsNaN(number) { |
| 48 number = TO_NUMBER(number); | 46 number = TO_NUMBER(number); |
| 49 return NUMBER_IS_NAN(number); | 47 return NUMBER_IS_NAN(number); |
| 50 } | 48 } |
| (...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 // which are non-configurable. It therefore makes no sence to | 1295 // which are non-configurable. It therefore makes no sence to |
| 1298 // try to redefine these as defined by the spec. The spec says | 1296 // try to redefine these as defined by the spec. The spec says |
| 1299 // that bind should make these throw a TypeError if get or set | 1297 // that bind should make these throw a TypeError if get or set |
| 1300 // is called and make them non-enumerable and non-configurable. | 1298 // is called and make them non-enumerable and non-configurable. |
| 1301 // To be consistent with our normal functions we leave this as it is. | 1299 // To be consistent with our normal functions we leave this as it is. |
| 1302 // TODO(lrn): Do set these to be thrower. | 1300 // TODO(lrn): Do set these to be thrower. |
| 1303 return result; | 1301 return result; |
| 1304 } | 1302 } |
| 1305 | 1303 |
| 1306 | 1304 |
| 1307 function NewFunctionString(args, function_token) { | |
| 1308 var n = args.length; | |
| 1309 var p = ''; | |
| 1310 if (n > 1) { | |
| 1311 p = TO_STRING(args[0]); | |
| 1312 for (var i = 1; i < n - 1; i++) { | |
| 1313 p += ',' + TO_STRING(args[i]); | |
| 1314 } | |
| 1315 // If the formal parameters string include ) - an illegal | |
| 1316 // character - it may make the combined function expression | |
| 1317 // compile. We avoid this problem by checking for this early on. | |
| 1318 if (%_Call(StringIndexOf, p, ')') != -1) { | |
| 1319 throw MakeSyntaxError(kParenthesisInArgString); | |
| 1320 } | |
| 1321 // If the formal parameters include an unbalanced block comment, the | |
| 1322 // function must be rejected. Since JavaScript does not allow nested | |
| 1323 // comments we can include a trailing block comment to catch this. | |
| 1324 p += '\n/' + '**/'; | |
| 1325 } | |
| 1326 var body = (n > 0) ? TO_STRING(args[n - 1]) : ''; | |
| 1327 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; | |
| 1328 } | |
| 1329 | |
| 1330 | |
| 1331 function FunctionConstructor(arg1) { // length == 1 | |
| 1332 var source = NewFunctionString(arguments, 'function'); | |
| 1333 var global_proxy = %GlobalProxy(FunctionConstructor); | |
| 1334 // Compile the string in the constructor and not a helper so that errors | |
| 1335 // appear to come from here. | |
| 1336 var func = %_Call(%CompileString(source, true), global_proxy); | |
| 1337 // Set name-should-print-as-anonymous flag on the ShareFunctionInfo and | |
| 1338 // ensure that |func| uses correct initial map from |new.target| if | |
| 1339 // it's available. | |
| 1340 return %CompleteFunctionConstruction(func, GlobalFunction, new.target); | |
| 1341 } | |
| 1342 | |
| 1343 | |
| 1344 // ---------------------------------------------------------------------------- | 1305 // ---------------------------------------------------------------------------- |
| 1345 | 1306 |
| 1346 %SetCode(GlobalFunction, FunctionConstructor); | |
| 1347 %AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction, | 1307 %AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction, |
| 1348 DONT_ENUM); | 1308 DONT_ENUM); |
| 1349 | 1309 |
| 1350 utils.InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [ | 1310 utils.InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [ |
| 1351 "bind", FunctionBind, | 1311 "bind", FunctionBind, |
| 1352 ]); | 1312 ]); |
| 1353 | 1313 |
| 1354 // ---------------------------------------------------------------------------- | 1314 // ---------------------------------------------------------------------------- |
| 1355 // Iterator related spec functions. | 1315 // Iterator related spec functions. |
| 1356 | 1316 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1370 } | 1330 } |
| 1371 | 1331 |
| 1372 // ---------------------------------------------------------------------------- | 1332 // ---------------------------------------------------------------------------- |
| 1373 // Exports | 1333 // Exports |
| 1374 | 1334 |
| 1375 utils.Export(function(to) { | 1335 utils.Export(function(to) { |
| 1376 to.GetIterator = GetIterator; | 1336 to.GetIterator = GetIterator; |
| 1377 to.GetMethod = GetMethod; | 1337 to.GetMethod = GetMethod; |
| 1378 to.IsFinite = GlobalIsFinite; | 1338 to.IsFinite = GlobalIsFinite; |
| 1379 to.IsNaN = GlobalIsNaN; | 1339 to.IsNaN = GlobalIsNaN; |
| 1380 to.NewFunctionString = NewFunctionString; | |
| 1381 to.NumberIsNaN = NumberIsNaN; | 1340 to.NumberIsNaN = NumberIsNaN; |
| 1382 to.ObjectDefineProperties = ObjectDefineProperties; | 1341 to.ObjectDefineProperties = ObjectDefineProperties; |
| 1383 to.ObjectDefineProperty = ObjectDefineProperty; | 1342 to.ObjectDefineProperty = ObjectDefineProperty; |
| 1384 to.ObjectFreeze = ObjectFreezeJS; | 1343 to.ObjectFreeze = ObjectFreezeJS; |
| 1385 to.ObjectHasOwnProperty = ObjectHasOwnProperty; | 1344 to.ObjectHasOwnProperty = ObjectHasOwnProperty; |
| 1386 to.ObjectIsFrozen = ObjectIsFrozen; | 1345 to.ObjectIsFrozen = ObjectIsFrozen; |
| 1387 to.ObjectIsSealed = ObjectIsSealed; | 1346 to.ObjectIsSealed = ObjectIsSealed; |
| 1388 to.ObjectKeys = ObjectKeys; | 1347 to.ObjectKeys = ObjectKeys; |
| 1389 }); | 1348 }); |
| 1390 | 1349 |
| 1391 %InstallToContext([ | 1350 %InstallToContext([ |
| 1392 "object_value_of", ObjectValueOf, | 1351 "object_value_of", ObjectValueOf, |
| 1393 ]); | 1352 ]); |
| 1394 | 1353 |
| 1395 }) | 1354 }) |
| OLD | NEW |