From 724962846c3466d3060300c38bfa33d5cd6ef38d Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Wed, 14 Sep 2011 12:33:57 +0000 Subject: [PATCH] Make built-in functions not call .apply on functions. Uses the new %Apply runtime function instead. Removes last(?) dependency on user-mungable infrastructure. Review URL: http://codereview.chromium.org/7887031 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9277 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/execution.cc | 4 ++-- src/runtime.js | 4 ++-- src/string.js | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/execution.cc b/src/execution.cc index de7632a..f36d4e4 100644 --- a/src/execution.cc +++ b/src/execution.cc @@ -227,7 +227,7 @@ Handle Execution::GetFunctionDelegate(Handle object) { // If you return a function from here, it will be called when an // attempt is made to call the given object as a function. - // If object is a function proxies, get its handler. Iterate if necessary. + // If object is a function proxy, get its handler. Iterate if necessary. Object* fun = *object; while (fun->IsJSFunctionProxy()) { fun = JSFunctionProxy::cast(fun)->call_trap(); @@ -251,7 +251,7 @@ Handle Execution::TryGetFunctionDelegate(Handle object, ASSERT(!object->IsJSFunction()); Isolate* isolate = Isolate::Current(); - // If object is a function proxies, get its handler. Iterate if necessary. + // If object is a function proxy, get its handler. Iterate if necessary. Object* fun = *object; while (fun->IsJSFunctionProxy()) { fun = JSFunctionProxy::cast(fun)->call_trap(); diff --git a/src/runtime.js b/src/runtime.js index c52e7fb..14ff1b6 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -408,7 +408,7 @@ function CALL_NON_FUNCTION() { if (!IS_FUNCTION(delegate)) { throw %MakeTypeError('called_non_callable', [typeof this]); } - return delegate.apply(this, arguments); + return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); } @@ -417,7 +417,7 @@ function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { if (!IS_FUNCTION(delegate)) { throw %MakeTypeError('called_non_callable', [typeof this]); } - return delegate.apply(this, arguments); + return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); } diff --git a/src/string.js b/src/string.js index a3e3e09..297105d 100644 --- a/src/string.js +++ b/src/string.js @@ -440,13 +440,14 @@ function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) { i++; } } else { + var receiver = %GetDefaultReceiver(replace); while (i < len) { var elem = res[i]; if (!%_IsSmi(elem)) { // elem must be an Array. // Use the apply argument as backing for global RegExp properties. lastMatchInfoOverride = elem; - var func_result = replace.apply(null, elem); + var func_result = %Apply(replace, receiver, elem, 0, elem.length); res[i] = TO_STRING_INLINE(func_result); } i++; @@ -472,11 +473,11 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) { // The number of captures plus one for the match. var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; var replacement; + var receiver = %GetDefaultReceiver(replace); if (m == 1) { // No captures, only the match, which is always valid. var s = SubString(subject, index, endOfMatch); // Don't call directly to avoid exposing the built-in global object. - var receiver = %GetDefaultReceiver(replace); replacement = %_CallFunction(receiver, s, index, subject, replace); } else { @@ -487,7 +488,7 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) { parameters[j] = index; parameters[j + 1] = subject; - replacement = replace.apply(null, parameters); + replacement = %Apply(replace, receiver, parameters, 0, j + 2); } result.add(replacement); // The add method converts to string if necessary. -- 2.7.4