Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/js/v8natives.js

Issue 1540953004: [runtime] Rewrite Function.prototype.toString in C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix typos. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 "parseInt", GlobalParseInt, 1245 "parseInt", GlobalParseInt,
1246 "parseFloat", GlobalParseFloat 1246 "parseFloat", GlobalParseFloat
1247 ]); 1247 ]);
1248 1248
1249 %SetForceInlineFlag(NumberIsNaN); 1249 %SetForceInlineFlag(NumberIsNaN);
1250 1250
1251 1251
1252 // ---------------------------------------------------------------------------- 1252 // ----------------------------------------------------------------------------
1253 // Function 1253 // Function
1254 1254
1255 function NativeCodeFunctionSourceString(func) {
1256 var name = %FunctionGetName(func);
1257 if (name) {
1258 // Mimic what KJS does.
1259 return 'function ' + name + '() { [native code] }';
1260 }
1261
1262 return 'function () { [native code] }';
1263 }
1264
1265 function FunctionSourceString(func) {
1266 if (!IS_FUNCTION(func)) {
1267 throw MakeTypeError(kNotGeneric, 'Function.prototype.toString');
1268 }
1269
1270 if (%FunctionHidesSource(func)) {
1271 return NativeCodeFunctionSourceString(func);
1272 }
1273
1274 var classSource = %ClassGetSourceCode(func);
1275 if (IS_STRING(classSource)) {
1276 return classSource;
1277 }
1278
1279 var source = %FunctionGetSourceCode(func);
1280 if (!IS_STRING(source)) {
1281 return NativeCodeFunctionSourceString(func);
1282 }
1283
1284 if (%FunctionIsArrow(func)) {
1285 return source;
1286 }
1287
1288 var name = %FunctionNameShouldPrintAsAnonymous(func)
1289 ? 'anonymous'
1290 : %FunctionGetName(func);
1291
1292 var isGenerator = %FunctionIsGenerator(func);
1293 var head = %FunctionIsConciseMethod(func)
1294 ? (isGenerator ? '*' : '')
1295 : (isGenerator ? 'function* ' : 'function ');
1296 return head + name + source;
1297 }
1298
1299
1300 function FunctionToString() {
1301 return FunctionSourceString(this);
1302 }
1303
1304
1305 // ES6 9.2.3.2 Function.prototype.bind(thisArg , ...args) 1255 // ES6 9.2.3.2 Function.prototype.bind(thisArg , ...args)
1306 function FunctionBind(this_arg) { // Length is 1. 1256 function FunctionBind(this_arg) { // Length is 1.
1307 if (!IS_CALLABLE(this)) throw MakeTypeError(kFunctionBind); 1257 if (!IS_CALLABLE(this)) throw MakeTypeError(kFunctionBind);
1308 1258
1309 var boundFunction = function () { 1259 var boundFunction = function () {
1310 // Poison .arguments and .caller, but is otherwise not detectable. 1260 // Poison .arguments and .caller, but is otherwise not detectable.
1311 "use strict"; 1261 "use strict";
1312 // This function must not use any object literals (Object, Array, RegExp), 1262 // This function must not use any object literals (Object, Array, RegExp),
1313 // since the literals-array is being used to store the bound data. 1263 // since the literals-array is being used to store the bound data.
1314 if (!IS_UNDEFINED(new.target)) { 1264 if (!IS_UNDEFINED(new.target)) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 1356
1407 1357
1408 // ---------------------------------------------------------------------------- 1358 // ----------------------------------------------------------------------------
1409 1359
1410 %SetCode(GlobalFunction, FunctionConstructor); 1360 %SetCode(GlobalFunction, FunctionConstructor);
1411 %AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction, 1361 %AddNamedProperty(GlobalFunction.prototype, "constructor", GlobalFunction,
1412 DONT_ENUM); 1362 DONT_ENUM);
1413 1363
1414 utils.InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [ 1364 utils.InstallFunctions(GlobalFunction.prototype, DONT_ENUM, [
1415 "bind", FunctionBind, 1365 "bind", FunctionBind,
1416 "toString", FunctionToString
1417 ]); 1366 ]);
1418 1367
1419 // ---------------------------------------------------------------------------- 1368 // ----------------------------------------------------------------------------
1420 // Iterator related spec functions. 1369 // Iterator related spec functions.
1421 1370
1422 // ES6 7.4.1 GetIterator(obj, method) 1371 // ES6 7.4.1 GetIterator(obj, method)
1423 function GetIterator(obj, method) { 1372 function GetIterator(obj, method) {
1424 if (IS_UNDEFINED(method)) { 1373 if (IS_UNDEFINED(method)) {
1425 method = obj[iteratorSymbol]; 1374 method = obj[iteratorSymbol];
1426 } 1375 }
1427 if (!IS_CALLABLE(method)) { 1376 if (!IS_CALLABLE(method)) {
1428 throw MakeTypeError(kNotIterable, obj); 1377 throw MakeTypeError(kNotIterable, obj);
1429 } 1378 }
1430 var iterator = %_Call(method, obj); 1379 var iterator = %_Call(method, obj);
1431 if (!IS_RECEIVER(iterator)) { 1380 if (!IS_RECEIVER(iterator)) {
1432 throw MakeTypeError(kNotAnIterator, iterator); 1381 throw MakeTypeError(kNotAnIterator, iterator);
1433 } 1382 }
1434 return iterator; 1383 return iterator;
1435 } 1384 }
1436 1385
1437 // ---------------------------------------------------------------------------- 1386 // ----------------------------------------------------------------------------
1438 // Exports 1387 // Exports
1439 1388
1440 utils.Export(function(to) { 1389 utils.Export(function(to) {
1441 to.FunctionSourceString = FunctionSourceString;
1442 to.GetIterator = GetIterator; 1390 to.GetIterator = GetIterator;
1443 to.GetMethod = GetMethod; 1391 to.GetMethod = GetMethod;
1444 to.IsFinite = GlobalIsFinite; 1392 to.IsFinite = GlobalIsFinite;
1445 to.IsNaN = GlobalIsNaN; 1393 to.IsNaN = GlobalIsNaN;
1446 to.NewFunctionString = NewFunctionString; 1394 to.NewFunctionString = NewFunctionString;
1447 to.NumberIsNaN = NumberIsNaN; 1395 to.NumberIsNaN = NumberIsNaN;
1448 to.ObjectDefineProperties = ObjectDefineProperties; 1396 to.ObjectDefineProperties = ObjectDefineProperties;
1449 to.ObjectDefineProperty = ObjectDefineProperty; 1397 to.ObjectDefineProperty = ObjectDefineProperty;
1450 to.ObjectFreeze = ObjectFreezeJS; 1398 to.ObjectFreeze = ObjectFreezeJS;
1451 to.ObjectHasOwnProperty = ObjectHasOwnProperty; 1399 to.ObjectHasOwnProperty = ObjectHasOwnProperty;
1452 to.ObjectIsFrozen = ObjectIsFrozen; 1400 to.ObjectIsFrozen = ObjectIsFrozen;
1453 to.ObjectIsSealed = ObjectIsSealed; 1401 to.ObjectIsSealed = ObjectIsSealed;
1454 to.ObjectKeys = ObjectKeys; 1402 to.ObjectKeys = ObjectKeys;
1455 }); 1403 });
1456 1404
1457 %InstallToContext([ 1405 %InstallToContext([
1458 "global_eval_fun", GlobalEval, 1406 "global_eval_fun", GlobalEval,
1459 "object_value_of", ObjectValueOf, 1407 "object_value_of", ObjectValueOf,
1460 ]); 1408 ]);
1461 1409
1462 }) 1410 })
OLDNEW
« src/debug/mirrors.js ('K') | « src/js/prologue.js ('k') | src/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698