Commit f8b74a15 authored by ager@chromium.org's avatar ager@chromium.org

Avoid using Function.prototype.call in a number of places in our

builtins files. We should always use %_CallFunction for a couple of
reasons: it cannot be overwritten and it does not wrap basic types in
wrapper objects.

Review URL: http://codereview.chromium.org/6349018

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6524 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4968d50d
...@@ -605,7 +605,7 @@ function DateToTimeString() { ...@@ -605,7 +605,7 @@ function DateToTimeString() {
// ECMA 262 - 15.9.5.5 // ECMA 262 - 15.9.5.5
function DateToLocaleString() { function DateToLocaleString() {
return DateToString.call(this); return %_CallFunction(this, DateToString);
} }
...@@ -973,7 +973,7 @@ function DateSetYear(year) { ...@@ -973,7 +973,7 @@ function DateSetYear(year) {
// do that either. Instead, we create a new function whose name // do that either. Instead, we create a new function whose name
// property will return toGMTString. // property will return toGMTString.
function DateToGMTString() { function DateToGMTString() {
return DateToUTCString.call(this); return %_CallFunction(this, DateToUTCString);
} }
......
...@@ -38,7 +38,7 @@ function Revive(holder, name, reviver) { ...@@ -38,7 +38,7 @@ function Revive(holder, name, reviver) {
} }
} else { } else {
for (var p in val) { for (var p in val) {
if (ObjectHasOwnProperty.call(val, p)) { if (%_CallFunction(val, p, ObjectHasOwnProperty)) {
var newElement = Revive(val, p, reviver); var newElement = Revive(val, p, reviver);
if (IS_UNDEFINED(newElement)) { if (IS_UNDEFINED(newElement)) {
delete val[p]; delete val[p];
...@@ -101,7 +101,7 @@ function SerializeObject(value, replacer, stack, indent, gap) { ...@@ -101,7 +101,7 @@ function SerializeObject(value, replacer, stack, indent, gap) {
if (IS_ARRAY(replacer)) { if (IS_ARRAY(replacer)) {
var length = replacer.length; var length = replacer.length;
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
if (ObjectHasOwnProperty.call(replacer, i)) { if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) {
var p = replacer[i]; var p = replacer[i];
var strP = JSONSerialize(p, value, replacer, stack, indent, gap); var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
if (!IS_UNDEFINED(strP)) { if (!IS_UNDEFINED(strP)) {
...@@ -114,7 +114,7 @@ function SerializeObject(value, replacer, stack, indent, gap) { ...@@ -114,7 +114,7 @@ function SerializeObject(value, replacer, stack, indent, gap) {
} }
} else { } else {
for (var p in value) { for (var p in value) {
if (ObjectHasOwnProperty.call(value, p)) { if (%_CallFunction(value, p, ObjectHasOwnProperty)) {
var strP = JSONSerialize(p, value, replacer, stack, indent, gap); var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
if (!IS_UNDEFINED(strP)) { if (!IS_UNDEFINED(strP)) {
var member = %QuoteJSONString(p) + ":"; var member = %QuoteJSONString(p) + ":";
......
...@@ -50,33 +50,10 @@ var kNoLineNumberInfo = 0; ...@@ -50,33 +50,10 @@ var kNoLineNumberInfo = 0;
// message on access. // message on access.
var kAddMessageAccessorsMarker = { }; var kAddMessageAccessorsMarker = { };
function GetInstanceName(cons) {
if (cons.length == 0) {
return "";
}
var first = %StringToLowerCase(StringCharAt.call(cons, 0));
if (kVowelSounds === 0) {
kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true};
kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, h: true,
f: true, l: true, m: true, n: true, r: true, s: true, x: true, y: true};
}
var vowel_mapping = kVowelSounds;
if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) {
// First char is upper case
var second = %StringToLowerCase(StringCharAt.call(cons, 1));
// Second char is upper case
if (StringCharAt.call(cons, 1) != second) {
vowel_mapping = kCapitalVowelSounds;
}
}
var s = vowel_mapping[first] ? "an " : "a ";
return s + cons;
}
var kMessages = 0; var kMessages = 0;
var kReplacementMarkers =
[ "%0", "%1", "%2", "%3", "%4", "%5", "%6", "%7", "%8", "%9", "%10" ];
function FormatString(format, args) { function FormatString(format, args) {
var result = format; var result = format;
...@@ -87,7 +64,9 @@ function FormatString(format, args) { ...@@ -87,7 +64,9 @@ function FormatString(format, args) {
} catch (e) { } catch (e) {
str = "#<error>"; str = "#<error>";
} }
result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); var replacement_marker = kReplacementMarkers[i];
var split = %_CallFunction(result, replacement_marker, StringSplit);
result = %_CallFunction(split, str, ArrayJoin);
} }
return result; return result;
} }
...@@ -130,7 +109,7 @@ function ToDetailString(obj) { ...@@ -130,7 +109,7 @@ function ToDetailString(obj) {
if (!constructorName || !IS_STRING(constructorName)) { if (!constructorName || !IS_STRING(constructorName)) {
return ToStringCheckErrorObject(obj); return ToStringCheckErrorObject(obj);
} }
return "#<" + GetInstanceName(constructorName) + ">"; return "#<" + constructorName + ">";
} else { } else {
return ToStringCheckErrorObject(obj); return ToStringCheckErrorObject(obj);
} }
...@@ -352,7 +331,7 @@ Script.prototype.locationFromPosition = function (position, ...@@ -352,7 +331,7 @@ Script.prototype.locationFromPosition = function (position,
var line_ends = this.line_ends; var line_ends = this.line_ends;
var start = line == 0 ? 0 : line_ends[line - 1] + 1; var start = line == 0 ? 0 : line_ends[line - 1] + 1;
var end = line_ends[line]; var end = line_ends[line];
if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') end--;
var column = position - start; var column = position - start;
// Adjust according to the offset within the resource. // Adjust according to the offset within the resource.
...@@ -467,7 +446,7 @@ Script.prototype.sourceLine = function (opt_line) { ...@@ -467,7 +446,7 @@ Script.prototype.sourceLine = function (opt_line) {
var line_ends = this.line_ends; var line_ends = this.line_ends;
var start = line == 0 ? 0 : line_ends[line - 1] + 1; var start = line == 0 ? 0 : line_ends[line - 1] + 1;
var end = line_ends[line]; var end = line_ends[line];
return StringSubstring.call(this.source, start, end); return %_CallFunction(this.source, start, end, StringSubstring);
} }
...@@ -595,7 +574,7 @@ SourceLocation.prototype.restrict = function (opt_limit, opt_before) { ...@@ -595,7 +574,7 @@ SourceLocation.prototype.restrict = function (opt_limit, opt_before) {
* Source text for this location. * Source text for this location.
*/ */
SourceLocation.prototype.sourceText = function () { SourceLocation.prototype.sourceText = function () {
return StringSubstring.call(this.script.source, this.start, this.end); return %_CallFunction(this.script.source, this.start, this.end, StringSubstring);
}; };
...@@ -632,7 +611,10 @@ function SourceSlice(script, from_line, to_line, from_position, to_position) { ...@@ -632,7 +611,10 @@ function SourceSlice(script, from_line, to_line, from_position, to_position) {
* the line terminating characters (if any) * the line terminating characters (if any)
*/ */
SourceSlice.prototype.sourceText = function () { SourceSlice.prototype.sourceText = function () {
return StringSubstring.call(this.script.source, this.from_position, this.to_position); return %_CallFunction(this.script.source,
this.from_position,
this.to_position,
StringSubstring);
}; };
...@@ -707,10 +689,10 @@ CallSite.prototype.getThis = function () { ...@@ -707,10 +689,10 @@ CallSite.prototype.getThis = function () {
CallSite.prototype.getTypeName = function () { CallSite.prototype.getTypeName = function () {
var constructor = this.receiver.constructor; var constructor = this.receiver.constructor;
if (!constructor) if (!constructor)
return $Object.prototype.toString.call(this.receiver); return %_CallFunction(this.receiver, ObjectToString);
var constructorName = constructor.name; var constructorName = constructor.name;
if (!constructorName) if (!constructorName)
return $Object.prototype.toString.call(this.receiver); return %_CallFunction(this.receiver, ObjectToString);
return constructorName; return constructorName;
}; };
...@@ -759,8 +741,8 @@ CallSite.prototype.getMethodName = function () { ...@@ -759,8 +741,8 @@ CallSite.prototype.getMethodName = function () {
// this function. // this function.
var ownName = this.fun.name; var ownName = this.fun.name;
if (ownName && this.receiver && if (ownName && this.receiver &&
(ObjectLookupGetter.call(this.receiver, ownName) === this.fun || (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun ||
ObjectLookupSetter.call(this.receiver, ownName) === this.fun || %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun ||
this.receiver[ownName] === this.fun)) { this.receiver[ownName] === this.fun)) {
// To handle DontEnum properties we guess that the method has // To handle DontEnum properties we guess that the method has
// the same name as the function. // the same name as the function.
......
...@@ -411,7 +411,7 @@ Mirror.prototype.allocateTransientHandle_ = function() { ...@@ -411,7 +411,7 @@ Mirror.prototype.allocateTransientHandle_ = function() {
Mirror.prototype.toText = function() { Mirror.prototype.toText = function() {
// Simpel to text which is used when on specialization in subclass. // Simpel to text which is used when on specialization in subclass.
return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; return "#<" + this.constructor.name + ">";
} }
...@@ -425,7 +425,7 @@ Mirror.prototype.toText = function() { ...@@ -425,7 +425,7 @@ Mirror.prototype.toText = function() {
* @extends Mirror * @extends Mirror
*/ */
function ValueMirror(type, value, transient) { function ValueMirror(type, value, transient) {
Mirror.call(this, type); %_CallFunction(this, type, Mirror);
this.value_ = value; this.value_ = value;
if (!transient) { if (!transient) {
this.allocateHandle_(); this.allocateHandle_();
...@@ -470,7 +470,7 @@ ValueMirror.prototype.value = function() { ...@@ -470,7 +470,7 @@ ValueMirror.prototype.value = function() {
* @extends ValueMirror * @extends ValueMirror
*/ */
function UndefinedMirror() { function UndefinedMirror() {
ValueMirror.call(this, UNDEFINED_TYPE, void 0); %_CallFunction(this, UNDEFINED_TYPE, void 0, ValueMirror);
} }
inherits(UndefinedMirror, ValueMirror); inherits(UndefinedMirror, ValueMirror);
...@@ -486,7 +486,7 @@ UndefinedMirror.prototype.toText = function() { ...@@ -486,7 +486,7 @@ UndefinedMirror.prototype.toText = function() {
* @extends ValueMirror * @extends ValueMirror
*/ */
function NullMirror() { function NullMirror() {
ValueMirror.call(this, NULL_TYPE, null); %_CallFunction(this, NULL_TYPE, null, ValueMirror);
} }
inherits(NullMirror, ValueMirror); inherits(NullMirror, ValueMirror);
...@@ -503,7 +503,7 @@ NullMirror.prototype.toText = function() { ...@@ -503,7 +503,7 @@ NullMirror.prototype.toText = function() {
* @extends ValueMirror * @extends ValueMirror
*/ */
function BooleanMirror(value) { function BooleanMirror(value) {
ValueMirror.call(this, BOOLEAN_TYPE, value); %_CallFunction(this, BOOLEAN_TYPE, value, ValueMirror);
} }
inherits(BooleanMirror, ValueMirror); inherits(BooleanMirror, ValueMirror);
...@@ -520,7 +520,7 @@ BooleanMirror.prototype.toText = function() { ...@@ -520,7 +520,7 @@ BooleanMirror.prototype.toText = function() {
* @extends ValueMirror * @extends ValueMirror
*/ */
function NumberMirror(value) { function NumberMirror(value) {
ValueMirror.call(this, NUMBER_TYPE, value); %_CallFunction(this, NUMBER_TYPE, value, ValueMirror);
} }
inherits(NumberMirror, ValueMirror); inherits(NumberMirror, ValueMirror);
...@@ -537,7 +537,7 @@ NumberMirror.prototype.toText = function() { ...@@ -537,7 +537,7 @@ NumberMirror.prototype.toText = function() {
* @extends ValueMirror * @extends ValueMirror
*/ */
function StringMirror(value) { function StringMirror(value) {
ValueMirror.call(this, STRING_TYPE, value); %_CallFunction(this, STRING_TYPE, value, ValueMirror);
} }
inherits(StringMirror, ValueMirror); inherits(StringMirror, ValueMirror);
...@@ -568,7 +568,7 @@ StringMirror.prototype.toText = function() { ...@@ -568,7 +568,7 @@ StringMirror.prototype.toText = function() {
* @extends ValueMirror * @extends ValueMirror
*/ */
function ObjectMirror(value, type, transient) { function ObjectMirror(value, type, transient) {
ValueMirror.call(this, type || OBJECT_TYPE, value, transient); %_CallFunction(this, type || OBJECT_TYPE, value, transient, ValueMirror);
} }
inherits(ObjectMirror, ValueMirror); inherits(ObjectMirror, ValueMirror);
...@@ -767,7 +767,7 @@ ObjectMirror.prototype.toText = function() { ...@@ -767,7 +767,7 @@ ObjectMirror.prototype.toText = function() {
name = this.className(); name = this.className();
} }
} }
return '#<' + builtins.GetInstanceName(name) + '>'; return '#<' + name + '>';
}; };
...@@ -778,7 +778,7 @@ ObjectMirror.prototype.toText = function() { ...@@ -778,7 +778,7 @@ ObjectMirror.prototype.toText = function() {
* @extends ObjectMirror * @extends ObjectMirror
*/ */
function FunctionMirror(value) { function FunctionMirror(value) {
ObjectMirror.call(this, value, FUNCTION_TYPE); %_CallFunction(this, value, FUNCTION_TYPE, ObjectMirror);
this.resolved_ = true; this.resolved_ = true;
} }
inherits(FunctionMirror, ObjectMirror); inherits(FunctionMirror, ObjectMirror);
...@@ -908,7 +908,7 @@ FunctionMirror.prototype.toText = function() { ...@@ -908,7 +908,7 @@ FunctionMirror.prototype.toText = function() {
function UnresolvedFunctionMirror(value) { function UnresolvedFunctionMirror(value) {
// Construct this using the ValueMirror as an unresolved function is not a // Construct this using the ValueMirror as an unresolved function is not a
// real object but just a string. // real object but just a string.
ValueMirror.call(this, FUNCTION_TYPE, value); %_CallFunction(this, FUNCTION_TYPE, value, ValueMirror);
this.propertyCount_ = 0; this.propertyCount_ = 0;
this.elementCount_ = 0; this.elementCount_ = 0;
this.resolved_ = false; this.resolved_ = false;
...@@ -958,7 +958,7 @@ UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) { ...@@ -958,7 +958,7 @@ UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) {
* @extends ObjectMirror * @extends ObjectMirror
*/ */
function ArrayMirror(value) { function ArrayMirror(value) {
ObjectMirror.call(this, value); %_CallFunction(this, value, ObjectMirror);
} }
inherits(ArrayMirror, ObjectMirror); inherits(ArrayMirror, ObjectMirror);
...@@ -994,7 +994,7 @@ ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index, opt_ ...@@ -994,7 +994,7 @@ ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index, opt_
* @extends ObjectMirror * @extends ObjectMirror
*/ */
function DateMirror(value) { function DateMirror(value) {
ObjectMirror.call(this, value); %_CallFunction(this, value, ObjectMirror);
} }
inherits(DateMirror, ObjectMirror); inherits(DateMirror, ObjectMirror);
...@@ -1012,7 +1012,7 @@ DateMirror.prototype.toText = function() { ...@@ -1012,7 +1012,7 @@ DateMirror.prototype.toText = function() {
* @extends ObjectMirror * @extends ObjectMirror
*/ */
function RegExpMirror(value) { function RegExpMirror(value) {
ObjectMirror.call(this, value, REGEXP_TYPE); %_CallFunction(this, value, REGEXP_TYPE, ObjectMirror);
} }
inherits(RegExpMirror, ObjectMirror); inherits(RegExpMirror, ObjectMirror);
...@@ -1066,7 +1066,7 @@ RegExpMirror.prototype.toText = function() { ...@@ -1066,7 +1066,7 @@ RegExpMirror.prototype.toText = function() {
* @extends ObjectMirror * @extends ObjectMirror
*/ */
function ErrorMirror(value) { function ErrorMirror(value) {
ObjectMirror.call(this, value, ERROR_TYPE); %_CallFunction(this, value, ERROR_TYPE, ObjectMirror);
} }
inherits(ErrorMirror, ObjectMirror); inherits(ErrorMirror, ObjectMirror);
...@@ -1101,7 +1101,7 @@ ErrorMirror.prototype.toText = function() { ...@@ -1101,7 +1101,7 @@ ErrorMirror.prototype.toText = function() {
* @extends Mirror * @extends Mirror
*/ */
function PropertyMirror(mirror, name, details) { function PropertyMirror(mirror, name, details) {
Mirror.call(this, PROPERTY_TYPE); %_CallFunction(this, PROPERTY_TYPE, Mirror);
this.mirror_ = mirror; this.mirror_ = mirror;
this.name_ = name; this.name_ = name;
this.value_ = details[0]; this.value_ = details[0];
...@@ -1397,7 +1397,7 @@ FrameDetails.prototype.scopeCount = function() { ...@@ -1397,7 +1397,7 @@ FrameDetails.prototype.scopeCount = function() {
* @extends Mirror * @extends Mirror
*/ */
function FrameMirror(break_id, index) { function FrameMirror(break_id, index) {
Mirror.call(this, FRAME_TYPE); %_CallFunction(this, FRAME_TYPE, Mirror);
this.break_id_ = break_id; this.break_id_ = break_id;
this.index_ = index; this.index_ = index;
this.details_ = new FrameDetails(break_id, index); this.details_ = new FrameDetails(break_id, index);
...@@ -1712,7 +1712,7 @@ ScopeDetails.prototype.object = function() { ...@@ -1712,7 +1712,7 @@ ScopeDetails.prototype.object = function() {
* @extends Mirror * @extends Mirror
*/ */
function ScopeMirror(frame, index) { function ScopeMirror(frame, index) {
Mirror.call(this, SCOPE_TYPE); %_CallFunction(this, SCOPE_TYPE, Mirror);
this.frame_index_ = frame.index_; this.frame_index_ = frame.index_;
this.scope_index_ = index; this.scope_index_ = index;
this.details_ = new ScopeDetails(frame, index); this.details_ = new ScopeDetails(frame, index);
...@@ -1752,7 +1752,7 @@ ScopeMirror.prototype.scopeObject = function() { ...@@ -1752,7 +1752,7 @@ ScopeMirror.prototype.scopeObject = function() {
* @extends Mirror * @extends Mirror
*/ */
function ScriptMirror(script) { function ScriptMirror(script) {
Mirror.call(this, SCRIPT_TYPE); %_CallFunction(this, SCRIPT_TYPE, Mirror);
this.script_ = script; this.script_ = script;
this.context_ = new ContextMirror(script.context_data); this.context_ = new ContextMirror(script.context_data);
this.allocateHandle_(); this.allocateHandle_();
...@@ -1868,7 +1868,7 @@ ScriptMirror.prototype.toText = function() { ...@@ -1868,7 +1868,7 @@ ScriptMirror.prototype.toText = function() {
* @extends Mirror * @extends Mirror
*/ */
function ContextMirror(data) { function ContextMirror(data) {
Mirror.call(this, CONTEXT_TYPE); %_CallFunction(this, CONTEXT_TYPE, Mirror);
this.data_ = data; this.data_ = data;
this.allocateHandle_(); this.allocateHandle_();
} }
......
...@@ -52,7 +52,7 @@ function DoConstructRegExp(object, pattern, flags) { ...@@ -52,7 +52,7 @@ function DoConstructRegExp(object, pattern, flags) {
var multiline = false; var multiline = false;
for (var i = 0; i < flags.length; i++) { for (var i = 0; i < flags.length; i++) {
var c = StringCharAt.call(flags, i); var c = %_CallFunction(flags, i, StringCharAt);
switch (c) { switch (c) {
case 'g': case 'g':
// Allow duplicate flags to be consistent with JSC and others. // Allow duplicate flags to be consistent with JSC and others.
......
...@@ -2376,6 +2376,8 @@ TEST(APIThrowMessageOverwrittenToString) { ...@@ -2376,6 +2376,8 @@ TEST(APIThrowMessageOverwrittenToString) {
v8::HandleScope scope; v8::HandleScope scope;
v8::V8::AddMessageListener(check_reference_error_message); v8::V8::AddMessageListener(check_reference_error_message);
LocalContext context; LocalContext context;
CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }");
CompileRun("String.prototype.toString = function f() { return 'Yikes'; }");
CompileRun("ReferenceError.prototype.toString =" CompileRun("ReferenceError.prototype.toString ="
" function() { return 'Whoops' }"); " function() { return 'Whoops' }");
CompileRun("asdf;"); CompileRun("asdf;");
...@@ -6246,7 +6248,7 @@ THREADED_TEST(FunctionDescriptorException) { ...@@ -6246,7 +6248,7 @@ THREADED_TEST(FunctionDescriptorException) {
" var str = String(e);" " var str = String(e);"
" if (str.indexOf('TypeError') == -1) return 1;" " if (str.indexOf('TypeError') == -1) return 1;"
" if (str.indexOf('[object Fun]') != -1) return 2;" " if (str.indexOf('[object Fun]') != -1) return 2;"
" if (str.indexOf('#<a Fun>') == -1) return 3;" " if (str.indexOf('#<Fun>') == -1) return 3;"
" return 0;" " return 0;"
" }" " }"
" return 4;" " return 4;"
......
...@@ -80,9 +80,9 @@ function listener(event, exec_state, event_data, data) { ...@@ -80,9 +80,9 @@ function listener(event, exec_state, event_data, data) {
// 1: Call distance on Point where distance is a direct property // 1: Call distance on Point where distance is a direct property
// 2: Call on function an array element 2 // 2: Call on function an array element 2
// 3: [anonymous] // 3: [anonymous]
assertEquals("#<a Point>.distanceTo(p=#<a Point>)", exec_state.frame(0).invocationText()); assertEquals("#<Point>.distanceTo(p=#<Point>)", exec_state.frame(0).invocationText());
assertEquals("#<a Point>.distanceTo(p=#<a Point>)", exec_state.frame(1).invocationText()); assertEquals("#<Point>.distanceTo(p=#<Point>)", exec_state.frame(1).invocationText());
assertEquals("#<an Array>[2](aka distance)(p=#<a Point>, q=#<a Point>)", exec_state.frame(2).invocationText()); assertEquals("#<Array>[2](aka distance)(p=#<Point>, q=#<Point>)", exec_state.frame(2).invocationText());
assertEquals("[anonymous]()", exec_state.frame(3).invocationText()); assertEquals("[anonymous]()", exec_state.frame(3).invocationText());
listenerCalled = true; listenerCalled = true;
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment