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

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

Issue 1530893002: [proxies] Correctly handle proxies in Function.prototype.bind (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « no previous file | test/mjsunit/function-bind.js » ('j') | test/mjsunit/function-bind.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 : (isGenerator ? 'function* ' : 'function '); 1295 : (isGenerator ? 'function* ' : 'function ');
1296 return head + name + source; 1296 return head + name + source;
1297 } 1297 }
1298 1298
1299 1299
1300 function FunctionToString() { 1300 function FunctionToString() {
1301 return FunctionSourceString(this); 1301 return FunctionSourceString(this);
1302 } 1302 }
1303 1303
1304 1304
1305 // ES5 15.3.4.5
1306 // ES6 9.2.3.2 Function.prototype.bind(thisArg , ...args) 1305 // ES6 9.2.3.2 Function.prototype.bind(thisArg , ...args)
1307 // TODO(cbruni): check again and remove FunctionProxies section further down
1308 function FunctionBind(this_arg) { // Length is 1. 1306 function FunctionBind(this_arg) { // Length is 1.
1309 if (!IS_CALLABLE(this)) throw MakeTypeError(kFunctionBind); 1307 if (!IS_CALLABLE(this)) throw MakeTypeError(kFunctionBind);
1310 1308
1311 var boundFunction = function () { 1309 var boundFunction = function () {
1312 // Poison .arguments and .caller, but is otherwise not detectable. 1310 // Poison .arguments and .caller, but is otherwise not detectable.
1313 "use strict"; 1311 "use strict";
1314 // This function must not use any object literals (Object, Array, RegExp), 1312 // This function must not use any object literals (Object, Array, RegExp),
1315 // since the literals-array is being used to store the bound data. 1313 // since the literals-array is being used to store the bound data.
1316 if (!IS_UNDEFINED(new.target)) { 1314 if (!IS_UNDEFINED(new.target)) {
1317 return %NewObjectFromBound(boundFunction); 1315 return %NewObjectFromBound(boundFunction);
(...skipping 12 matching lines...) Expand all
1330 for (var i = 0; i < bound_argc; i++) { 1328 for (var i = 0; i < bound_argc; i++) {
1331 argv[i] = bindings[i + 2]; 1329 argv[i] = bindings[i + 2];
1332 } 1330 }
1333 for (var j = 0; j < argc; j++) { 1331 for (var j = 0; j < argc; j++) {
1334 argv[i++] = %_Arguments(j); 1332 argv[i++] = %_Arguments(j);
1335 } 1333 }
1336 return %Apply(bindings[0], bindings[1], argv, 0, bound_argc + argc); 1334 return %Apply(bindings[0], bindings[1], argv, 0, bound_argc + argc);
1337 }; 1335 };
1338 1336
1339 var new_length = 0; 1337 var new_length = 0;
1340 var old_length = this.length; 1338 if (ObjectGetOwnPropertyDescriptor(this, "length") !== UNDEFINED) {
1341 // FunctionProxies might provide a non-UInt32 value. If so, ignore it. 1339 var old_length = this.length;
1342 if ((typeof old_length === "number") && 1340 if (IS_NUMBER(old_length)) {
1343 ((old_length >>> 0) === old_length)) { 1341 var argc = %_ArgumentsLength();
1344 var argc = %_ArgumentsLength(); 1342 if (argc > 0) argc--; // Don't count the thisArg as parameter.
1345 if (argc > 0) argc--; // Don't count the thisArg as parameter. 1343 new_length = TO_INTEGER(old_length) - argc;
1346 new_length = old_length - argc; 1344 if (new_length < 0) new_length = 0;
1347 if (new_length < 0) new_length = 0; 1345 }
1348 } 1346 }
1347
1349 // This runtime function finds any remaining arguments on the stack, 1348 // This runtime function finds any remaining arguments on the stack,
1350 // so we don't pass the arguments object. 1349 // so we don't pass the arguments object.
1351 var result = %FunctionBindArguments(boundFunction, this, 1350 var result = %FunctionBindArguments(boundFunction, this,
1352 this_arg, new_length); 1351 this_arg, new_length);
1353 1352
1354 var name = this.name; 1353 var name = this.name;
1355 var bound_name = IS_STRING(name) ? name : ""; 1354 var bound_name = IS_STRING(name) ? name : "";
1356 %DefineDataPropertyUnchecked(result, "name", "bound " + bound_name, 1355 %DefineDataPropertyUnchecked(result, "name", "bound " + bound_name,
1357 DONT_ENUM | READ_ONLY); 1356 DONT_ENUM | READ_ONLY);
1358 1357
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 to.ObjectIsSealed = ObjectIsSealed; 1451 to.ObjectIsSealed = ObjectIsSealed;
1453 to.ObjectKeys = ObjectKeys; 1452 to.ObjectKeys = ObjectKeys;
1454 }); 1453 });
1455 1454
1456 %InstallToContext([ 1455 %InstallToContext([
1457 "global_eval_fun", GlobalEval, 1456 "global_eval_fun", GlobalEval,
1458 "object_value_of", ObjectValueOf, 1457 "object_value_of", ObjectValueOf,
1459 ]); 1458 ]);
1460 1459
1461 }) 1460 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/function-bind.js » ('j') | test/mjsunit/function-bind.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698