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

Side by Side Diff: src/v8natives.js

Issue 6413018: Provide special case for f.bind(obj). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 } 1134 }
1135 // this_arg is not an argument that should be bound. 1135 // this_arg is not an argument that should be bound.
1136 var argc_bound = (%_ArgumentsLength() || 1) - 1; 1136 var argc_bound = (%_ArgumentsLength() || 1) - 1;
1137 if (argc_bound > 0) { 1137 if (argc_bound > 0) {
1138 var bound_args = new $Array(argc_bound); 1138 var bound_args = new $Array(argc_bound);
1139 for(var i = 0; i < argc_bound; i++) { 1139 for(var i = 0; i < argc_bound; i++) {
1140 bound_args[i] = %_Arguments(i+1); 1140 bound_args[i] = %_Arguments(i+1);
1141 } 1141 }
1142 } 1142 }
1143 var fn = this; 1143 var fn = this;
1144 var result = function() { 1144 if (argc_bound == 0) {
1145 // Combine the args we got from the bind call with the args 1145 var result = function() { return fn.apply(this_arg, arguments); };
1146 // given as argument to the invocation. 1146 } else {
1147 var argc = %_ArgumentsLength(); 1147 var result = function() {
1148 var args = new $Array(argc + argc_bound); 1148 // Combine the args we got from the bind call with the args
1149 // Add bound arguments. 1149 // given as argument to the invocation.
1150 for (var i = 0; i < argc_bound; i++) { 1150 var argc = %_ArgumentsLength();
1151 args[i] = bound_args[i]; 1151 var args = new $Array(argc + argc_bound);
1152 } 1152 // Add bound arguments.
1153 // Add arguments from call. 1153 for (var i = 0; i < argc_bound; i++) {
1154 for (var i = 0; i < argc; i++) { 1154 args[i] = bound_args[i];
1155 args[argc_bound + i] = %_Arguments(i); 1155 }
1156 } 1156 // Add arguments from call.
1157 // If this is a construct call we use a special runtime method 1157 for (var i = 0; i < argc; i++) {
1158 // to generate the actual object using the bound function. 1158 args[argc_bound + i] = %_Arguments(i);
1159 if (%_IsConstructCall()) { 1159 }
1160 return %NewObjectFromBound(fn, args); 1160 // If this is a construct call we use a special runtime method
1161 } 1161 // to generate the actual object using the bound function.
1162 return fn.apply(this_arg, args); 1162 if (%_IsConstructCall()) {
1163 }; 1163 return %NewObjectFromBound(fn, args);
1164 }
1165 return fn.apply(this_arg, args);
1166 };
1167 }
1164 1168
1165 // We already have caller and arguments properties on functions, 1169 // We already have caller and arguments properties on functions,
1166 // which are non-configurable. It therefore makes no sence to 1170 // which are non-configurable. It therefore makes no sence to
1167 // try to redefine these as defined by the spec. The spec says 1171 // try to redefine these as defined by the spec. The spec says
1168 // that bind should make these throw a TypeError if get or set 1172 // that bind should make these throw a TypeError if get or set
1169 // is called and make them non-enumerable and non-configurable. 1173 // is called and make them non-enumerable and non-configurable.
1170 // To be consistent with our normal functions we leave this as it is. 1174 // To be consistent with our normal functions we leave this as it is.
1171 1175
1172 // Set the correct length. 1176 // Set the correct length.
1173 var length = (this.length - argc_bound) > 0 ? this.length - argc_bound : 0; 1177 var length = (this.length - argc_bound) > 0 ? this.length - argc_bound : 0;
(...skipping 30 matching lines...) Expand all
1204 // ---------------------------------------------------------------------------- 1208 // ----------------------------------------------------------------------------
1205 1209
1206 function SetupFunction() { 1210 function SetupFunction() {
1207 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1211 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1208 "bind", FunctionBind, 1212 "bind", FunctionBind,
1209 "toString", FunctionToString 1213 "toString", FunctionToString
1210 )); 1214 ));
1211 } 1215 }
1212 1216
1213 SetupFunction(); 1217 SetupFunction();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698