Commit 9da356ee authored by ager@chromium.org's avatar ager@chromium.org

Make sure that the name accessor on functions return the expected

names.

- Set the correct name of library functions.
- Set the name of C++ callback functions.
- Clean up a couple of out-dated comments related to literal creation.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@414 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 06fa6d1c
......@@ -34,19 +34,19 @@ function CreateDate(time) {
var date = new ORIGINAL_DATE();
date.setTime(time);
return date;
};
}
const kApiFunctionCache = {};
const functionCache = kApiFunctionCache;
function Instantiate(data) {
function Instantiate(data, name) {
if (!%IsTemplate(data)) return data;
var tag = %GetTemplateField(data, kApiTagOffset);
switch (tag) {
case kFunctionTag:
return InstantiateFunction(data);
return InstantiateFunction(data, name);
case kNewObjectTag:
var Constructor = %GetTemplateField(data, kApiConstructorOffset);
var result = Constructor ? new (Instantiate(Constructor))() : {};
......@@ -55,14 +55,15 @@ function Instantiate(data) {
default:
throw 'Unknown API tag <' + tag + '>';
}
};
}
function InstantiateFunction(data) {
function InstantiateFunction(data, name) {
var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset);
if (!(serialNumber in kApiFunctionCache)) {
kApiFunctionCache[serialNumber] = null;
var fun = %CreateApiFunction(data);
if (name) %FunctionSetName(fun, name);
kApiFunctionCache[serialNumber] = fun;
var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
fun.prototype = prototype ? Instantiate(prototype) : {};
......@@ -75,7 +76,7 @@ function InstantiateFunction(data) {
ConfigureTemplateInstance(fun, data);
}
return kApiFunctionCache[serialNumber];
};
}
function ConfigureTemplateInstance(obj, data) {
......@@ -85,8 +86,8 @@ function ConfigureTemplateInstance(obj, data) {
var name = properties[i + 1];
var prop_data = properties[i + 2];
var attributes = properties[i + 3];
var value = Instantiate(prop_data);
var value = Instantiate(prop_data, name);
%SetProperty(obj, name, value, attributes);
}
}
};
}
......@@ -132,13 +132,13 @@ function Join(array, length, separator, convert) {
// Make sure to pop the visited array no matter what happens.
if (is_array) visited_arrays.pop();
}
};
}
function ConvertToString(e) {
if (e == null) return '';
else return ToString(e);
};
}
function ConvertToLocaleString(e) {
......@@ -153,7 +153,7 @@ function ConvertToLocaleString(e) {
else
return ToString(e);
}
};
}
// This function implements the optimized splice implementation that can use
......@@ -196,7 +196,7 @@ function SmartSlice(array, start_i, del_count, len, deleted_elements) {
}
}
}
};
}
// This function implements the optimized splice implementation that can use
......@@ -258,7 +258,7 @@ function SmartMove(array, start_i, del_count, len, num_additional_args) {
}
// Move contents of new_array into this array
%MoveArrayContents(new_array, array);
};
}
// This is part of the old simple-minded splice. We are using it either
......@@ -274,7 +274,7 @@ function SimpleSlice(array, start_i, del_count, len, deleted_elements) {
if (!IS_UNDEFINED(current) || index in array)
deleted_elements[i] = current;
}
};
}
function SimpleMove(array, start_i, del_count, len, num_additional_args) {
......@@ -314,7 +314,7 @@ function SimpleMove(array, start_i, del_count, len, num_additional_args) {
}
}
}
};
}
// -------------------------------------------------------------------
......@@ -325,7 +325,7 @@ function ArrayToString() {
throw new $TypeError('Array.prototype.toString is not generic');
}
return Join(this, this.length, ',', ConvertToString);
};
}
function ArrayToLocaleString() {
......@@ -333,14 +333,14 @@ function ArrayToLocaleString() {
throw new $TypeError('Array.prototype.toString is not generic');
}
return Join(this, this.length, ',', ConvertToLocaleString);
};
}
function ArrayJoin(separator) {
if (IS_UNDEFINED(separator)) separator = ',';
else separator = ToString(separator);
return Join(this, ToUint32(this.length), separator, ConvertToString);
};
}
// Removes the last element from the array and returns it. See
......@@ -356,7 +356,7 @@ function ArrayPop() {
this.length = n;
delete this[n];
return value;
};
}
// Appends the arguments to the end of the array and returns the new
......@@ -369,7 +369,7 @@ function ArrayPush() {
}
this.length = n + m;
return this.length;
};
}
function ArrayConcat(arg1) { // length == 1
......@@ -415,7 +415,7 @@ function ArrayConcat(arg1) { // length == 1
A.length = n; // may contain empty arrays
return A;
};
}
// For implementing reverse() on large, sparse arrays.
......@@ -490,7 +490,7 @@ function ArrayReverse() {
}
}
return this;
};
}
function ArrayShift() {
......@@ -511,7 +511,7 @@ function ArrayShift() {
this.length = len - 1;
return first;
};
}
function ArrayUnshift(arg1) { // length == 1
......@@ -530,7 +530,7 @@ function ArrayUnshift(arg1) { // length == 1
this.length = len + num_arguments;
return len + num_arguments;
};
}
function ArraySlice(start, end) {
......@@ -556,18 +556,18 @@ function ArraySlice(start, end) {
var result = [];
if (end_i < start_i)
return result;
if (end_i < start_i) return result;
if (IS_ARRAY(this))
if (IS_ARRAY(this)) {
SmartSlice(this, start_i, end_i - start_i, len, result);
else
} else {
SimpleSlice(this, start_i, end_i - start_i, len, result);
}
result.length = end_i - start_i;
return result;
};
}
function ArraySplice(start, delete_count) {
......@@ -643,7 +643,7 @@ function ArraySplice(start, delete_count) {
// Return the deleted elements.
return deleted_elements;
};
}
function ArraySort(comparefn) {
......@@ -760,13 +760,12 @@ function ArraySort(comparefn) {
}
return this;
};
}
// The following functions cannot be made efficient on sparse arrays while
// preserving the semantics, since the calls to the receiver function can add
// or delete elements from the array.
function ArrayFilter(f, receiver) {
if (!IS_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
......@@ -782,7 +781,7 @@ function ArrayFilter(f, receiver) {
}
}
return result;
};
}
function ArrayForEach(f, receiver) {
......@@ -798,7 +797,7 @@ function ArrayForEach(f, receiver) {
f.call(receiver, current, i, this);
}
}
};
}
// Executes the function once for each element present in the
......@@ -817,7 +816,7 @@ function ArraySome(f, receiver) {
}
}
return false;
};
}
function ArrayEvery(f, receiver) {
......@@ -835,7 +834,7 @@ function ArrayEvery(f, receiver) {
}
return true;
};
}
function ArrayMap(f, receiver) {
......@@ -853,7 +852,7 @@ function ArrayMap(f, receiver) {
}
}
return result;
};
}
function ArrayIndexOf(element, index) {
......@@ -875,7 +874,7 @@ function ArrayIndexOf(element, index) {
}
}
return -1;
};
}
function ArrayLastIndexOf(element, index) {
......@@ -898,51 +897,58 @@ function ArrayLastIndexOf(element, index) {
}
}
return -1;
};
}
// -------------------------------------------------------------------
function InstallProperties(prototype, attributes, properties) {
for (var key in properties) {
%AddProperty(prototype, key, properties[key], attributes);
function InstallFunctions(prototype, attributes, functions) {
for (var i = 0; i < functions.length; i += 2) {
var key = functions[i];
var f = functions[i + 1];
%FunctionSetName(f, key);
%AddProperty(prototype, key, f, attributes);
}
};
}
function UpdateFunctionLengths(lengths) {
for (var key in lengths) {
%FunctionSetLength(this[key], lengths[key]);
}
};
}
// -------------------------------------------------------------------
function SetupArray() {
// Setup non-enumerable properties of the Array.prototype object.
InstallProperties($Array.prototype, DONT_ENUM, {
constructor: $Array,
toString: ArrayToString,
toLocaleString: ArrayToLocaleString,
join: ArrayJoin,
pop: ArrayPop,
push: ArrayPush,
concat: ArrayConcat,
reverse: ArrayReverse,
shift: ArrayShift,
unshift: ArrayUnshift,
slice: ArraySlice,
splice: ArraySplice,
sort: ArraySort,
filter: ArrayFilter,
forEach: ArrayForEach,
some: ArraySome,
every: ArrayEvery,
map: ArrayMap,
indexOf: ArrayIndexOf,
lastIndexOf: ArrayLastIndexOf
});
// Setup non-enumerable constructor property on the Array.prototype
// object.
%AddProperty($Array.prototype, "constructor", $Array, DONT_ENUM);
// Setup non-enumerable functions of the Array.prototype object and
// set their names.
InstallFunctions($Array.prototype, DONT_ENUM, $Array(
"toString", ArrayToString,
"toLocaleString", ArrayToLocaleString,
"join", ArrayJoin,
"pop", ArrayPop,
"push", ArrayPush,
"concat", ArrayConcat,
"reverse", ArrayReverse,
"shift", ArrayShift,
"unshift", ArrayUnshift,
"slice", ArraySlice,
"splice", ArraySplice,
"sort", ArraySort,
"filter", ArrayFilter,
"forEach", ArrayForEach,
"some", ArraySome,
"every", ArrayEvery,
"map", ArrayMap,
"indexOf", ArrayIndexOf,
"lastIndexOf", ArrayLastIndexOf
));
// Manipulate the length of some of the functions to meet
// expectations set by ECMA-262 or Mozilla.
......@@ -956,7 +962,7 @@ function SetupArray() {
ArrayLastIndexOf: 1,
ArrayPush: 1
});
};
}
SetupArray();
This diff is collapsed.
......@@ -75,7 +75,7 @@ function MakeBreakPoint(source_position, opt_line, opt_column, opt_script_break_
var break_point = new BreakPoint(source_position, opt_line, opt_column, opt_script_break_point);
break_points.push(break_point);
return break_point;
};
}
// Object representing a break point.
......@@ -95,7 +95,7 @@ function BreakPoint(source_position, opt_line, opt_column, opt_script_break_poin
this.active_ = true;
this.condition_ = null;
this.ignoreCount_ = 0;
};
}
BreakPoint.prototype.number = function() {
......@@ -204,7 +204,7 @@ BreakPoint.prototype.isTriggered = function(exec_state) {
// the break point is triggered and supposed to break execution.
function IsBreakPointTriggered(break_id, break_point) {
return break_point.isTriggered(MakeExecutionState(break_id));
};
}
// Object representing a script break point. The script is referenced by its
......@@ -217,7 +217,7 @@ function ScriptBreakPoint(script_name, opt_line, opt_column) {
this.active_ = true;
this.condition_ = null;
this.ignoreCount_ = 0;
};
}
ScriptBreakPoint.prototype.number = function() {
......@@ -354,7 +354,7 @@ function UpdateScriptBreakPoints(script) {
script_break_points[i].set(script);
}
}
};
}
// Function called from the runtime to handle a debug request receiced from the
......@@ -676,12 +676,12 @@ Debug.scripts = function() {
function MakeExecutionState(break_id) {
return new ExecutionState(break_id);
};
}
function ExecutionState(break_id) {
this.break_id = break_id;
this.selected_frame = 0;
};
}
ExecutionState.prototype.prepareStep = function(opt_action, opt_count) {
var action = Debug.StepAction.StepIn;
......@@ -727,13 +727,13 @@ ExecutionState.prototype.debugCommandProcessor = function(protocol) {
function MakeBreakEvent(exec_state, break_points_hit) {
return new BreakEvent(exec_state, break_points_hit);
};
}
function BreakEvent(exec_state, break_points_hit) {
this.exec_state_ = exec_state;
this.break_points_hit_ = break_points_hit;
};
}
BreakEvent.prototype.func = function() {
......@@ -846,13 +846,13 @@ BreakEvent.prototype.toJSONProtocol = function() {
function MakeExceptionEvent(exec_state, exception, uncaught) {
return new ExceptionEvent(exec_state, exception, uncaught);
};
}
function ExceptionEvent(exec_state, exception, uncaught) {
this.exec_state_ = exec_state;
this.exception_ = exception;
this.uncaught_ = uncaught;
};
}
ExceptionEvent.prototype.uncaught = function() {
return this.uncaught_;
......@@ -931,13 +931,13 @@ ExceptionEvent.prototype.toJSONProtocol = function() {
function MakeCompileEvent(script_source, script_name, script_function) {
return new CompileEvent(script_source, script_name, script_function);
};
}
function CompileEvent(script_source, script_name, script_function) {
this.scriptSource = script_source;
this.scriptName = script_name;
this.scriptFunction = script_function;
};
}
CompileEvent.prototype.details = function() {
var result = "";
......@@ -967,11 +967,11 @@ CompileEvent.prototype.debugPrompt = function() {
function MakeNewFunctionEvent(func) {
return new NewFunctionEvent(func);
};
}
function NewFunctionEvent(func) {
this.func = func;
};
}
NewFunctionEvent.prototype.details = function() {
var result = "";
......@@ -1314,7 +1314,7 @@ function SourceUnderline(source_text, position) {
// Return the source line text with the underline beneath.
return source_text + '\n' + underline;
};
}
function FrameSourceUnderline(frame) {
......@@ -1322,14 +1322,14 @@ function FrameSourceUnderline(frame) {
if (location) {
return SourceUnderline(location.sourceText(), location.position - location.start);
}
};
}
function RequestPacket(command) {
this.seq = 0;
this.type = 'request';
this.command = command;
};
}
RequestPacket.prototype.toJSONProtocol = function() {
......@@ -1367,7 +1367,7 @@ function ResponsePacket(request) {
if (request) this.command = request.command;
this.success = true;
this.running = false;
};
}
ResponsePacket.prototype.failed = function(message) {
......@@ -1995,7 +1995,7 @@ function SimpleObjectToJSON_(object) {
// Make JSON object representation.
return '{' + content.join(',') + '}';
};
}
/**
* Convert an array to its JSON representation. This is a VERY simple
......@@ -2027,4 +2027,4 @@ function SimpleArrayToJSON_(array) {
}
json += ']';
return json;
};
}
......@@ -30,74 +30,56 @@
// has the added benefit that the code in this file is isolated from
// changes to these properties.
const $Infinity = global.Infinity;
const $floor = $Math_floor;
const $random = $Math_random;
const $abs = $Math_abs;
const $floor = MathFloor;
const $random = MathRandom;
const $abs = MathAbs;
// Instance class name can only be set on functions. That is the only
// purpose for MathConstructor.
function MathConstructor() {};
function MathConstructor() {}
%FunctionSetInstanceClassName(MathConstructor, 'Math');
const $Math = new MathConstructor();
$Math.__proto__ = global.Object.prototype;
%AddProperty(global, "Math", $Math, DONT_ENUM);
function $Math_random() { return %Math_random(); }
%AddProperty($Math, "random", $Math_random, DONT_ENUM);
function $Math_abs(x) {
// ECMA 262 - 15.8.2.1
function MathAbs(x) {
if (%_IsSmi(x)) {
return x >= 0 ? x : -x;
} else {
return %Math_abs(ToNumber(x));
}
}
%AddProperty($Math, "abs", $Math_abs, DONT_ENUM);
function $Math_acos(x) { return %Math_acos(ToNumber(x)); }
%AddProperty($Math, "acos", $Math_acos, DONT_ENUM);
function $Math_asin(x) { return %Math_asin(ToNumber(x)); }
%AddProperty($Math, "asin", $Math_asin, DONT_ENUM);
function $Math_atan(x) { return %Math_atan(ToNumber(x)); }
%AddProperty($Math, "atan", $Math_atan, DONT_ENUM);
function $Math_ceil(x) { return %Math_ceil(ToNumber(x)); }
%AddProperty($Math, "ceil", $Math_ceil, DONT_ENUM);
function $Math_cos(x) { return %Math_cos(ToNumber(x)); }
%AddProperty($Math, "cos", $Math_cos, DONT_ENUM);
// ECMA 262 - 15.8.2.2
function MathAcos(x) { return %Math_acos(ToNumber(x)); }
function $Math_exp(x) { return %Math_exp(ToNumber(x)); }
%AddProperty($Math, "exp", $Math_exp, DONT_ENUM);
// ECMA 262 - 15.8.2.3
function MathAsin(x) { return %Math_asin(ToNumber(x)); }
function $Math_floor(x) { return %Math_floor(ToNumber(x)); }
%AddProperty($Math, "floor", $Math_floor, DONT_ENUM);
// ECMA 262 - 15.8.2.4
function MathAtan(x) { return %Math_atan(ToNumber(x)); }
function $Math_log(x) { return %Math_log(ToNumber(x)); }
%AddProperty($Math, "log", $Math_log, DONT_ENUM);
// ECMA 262 - 15.8.2.5
function MathAtan2(x, y) { return %Math_atan2(ToNumber(x), ToNumber(y)); }
function $Math_round(x) { return %Math_round(ToNumber(x)); }
%AddProperty($Math, "round", $Math_round, DONT_ENUM);
// ECMA 262 - 15.8.2.6
function MathCeil(x) { return %Math_ceil(ToNumber(x)); }
function $Math_sin(x) { return %Math_sin(ToNumber(x)); }
%AddProperty($Math, "sin", $Math_sin, DONT_ENUM);
// ECMA 262 - 15.8.2.7
function MathCos(x) { return %Math_cos(ToNumber(x)); }
function $Math_sqrt(x) { return %Math_sqrt(ToNumber(x)); }
%AddProperty($Math, "sqrt", $Math_sqrt, DONT_ENUM);
// ECMA 262 - 15.8.2.8
function MathExp(x) { return %Math_exp(ToNumber(x)); }
function $Math_tan(x) { return %Math_tan(ToNumber(x)); }
%AddProperty($Math, "tan", $Math_tan, DONT_ENUM);
// ECMA 262 - 15.8.2.9
function MathFloor(x) { return %Math_floor(ToNumber(x)); }
function $Math_atan2(x, y) { return %Math_atan2(ToNumber(x), ToNumber(y)); }
%AddProperty($Math, "atan2", $Math_atan2, DONT_ENUM);
// ECMA 262 - 15.8.2.10
function MathLog(x) { return %Math_log(ToNumber(x)); }
function $Math_pow(x, y) { return %Math_pow(ToNumber(x), ToNumber(y)); }
%AddProperty($Math, "pow", $Math_pow, DONT_ENUM);
function $Math_max(arg1, arg2) { // length == 2
// ECMA 262 - 15.8.2.11
function MathMax(arg1, arg2) { // length == 2
var r = -$Infinity;
for (var i = %_ArgumentsLength() - 1; i >= 0; --i) {
var n = ToNumber(%_Arguments(i));
......@@ -107,9 +89,9 @@ function $Math_max(arg1, arg2) { // length == 2
}
return r;
}
%AddProperty($Math, "max", $Math_max, DONT_ENUM);
function $Math_min(arg1, arg2) { // length == 2
// ECMA 262 - 15.8.2.12
function MathMin(arg1, arg2) { // length == 2
var r = $Infinity;
for (var i = %_ArgumentsLength() - 1; i >= 0; --i) {
var n = ToNumber(%_Arguments(i));
......@@ -119,21 +101,66 @@ function $Math_min(arg1, arg2) { // length == 2
}
return r;
}
%AddProperty($Math, "min", $Math_min, DONT_ENUM);
// ECMA-262, section 15.8.1.1.
%AddProperty($Math, "E", 2.7182818284590452354, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262, section 15.8.1.2.
%AddProperty($Math, "LN10", 2.302585092994046, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262, section 15.8.1.3.
%AddProperty($Math, "LN2", 0.6931471805599453, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262, section 15.8.1.4.
%AddProperty($Math, "LOG2E", 1.4426950408889634, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "LOG10E", 0.43429448190325176, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "PI", 3.1415926535897932, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "SQRT1_2", 0.7071067811865476, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "SQRT2", 1.4142135623730951, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA 262 - 15.8.2.13
function MathPow(x, y) { return %Math_pow(ToNumber(x), ToNumber(y)); }
// ECMA 262 - 15.8.2.14
function MathRandom() { return %Math_random(); }
// ECMA 262 - 15.8.2.15
function MathRound(x) { return %Math_round(ToNumber(x)); }
// ECMA 262 - 15.8.2.16
function MathSin(x) { return %Math_sin(ToNumber(x)); }
// ECMA 262 - 15.8.2.17
function MathSqrt(x) { return %Math_sqrt(ToNumber(x)); }
// ECMA 262 - 15.8.2.18
function MathTan(x) { return %Math_tan(ToNumber(x)); }
// -------------------------------------------------------------------
function SetupMath() {
// Setup math constants.
// ECMA-262, section 15.8.1.1.
%AddProperty($Math, "E", 2.7182818284590452354, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262, section 15.8.1.2.
%AddProperty($Math, "LN10", 2.302585092994046, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262, section 15.8.1.3.
%AddProperty($Math, "LN2", 0.6931471805599453, DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262, section 15.8.1.4.
%AddProperty($Math, "LOG2E", 1.4426950408889634, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "LOG10E", 0.43429448190325176, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "PI", 3.1415926535897932, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "SQRT1_2", 0.7071067811865476, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddProperty($Math, "SQRT2", 1.4142135623730951, DONT_ENUM | DONT_DELETE | READ_ONLY);
// Setup non-enumerable functions of the Math object and
// set their names.
InstallFunctions($Math, DONT_ENUM, $Array(
"random", MathRandom,
"abs", MathAbs,
"acos", MathAcos,
"asin", MathAsin,
"atan", MathAtan,
"ceil", MathCeil,
"cos", MathCos,
"exp", MathExp,
"floor", MathFloor,
"log", MathLog,
"round", MathRound,
"sin", MathSin,
"sqrt", MathSqrt,
"tan", MathTan,
"atan2", MathAtan2,
"pow", MathPow,
"max", MathMax,
"min", MathMin
));
};
SetupMath();
......@@ -48,7 +48,7 @@ function GetInstanceName(cons) {
}
var s = mapping[first] ? "an " : "a ";
return s + cons;
};
}
const kMessages = {
......@@ -124,7 +124,7 @@ function FormatString(format, args) {
result = result.split("%" + i).join(str);
}
return result;
};
}
function ToDetailString(obj) {
......@@ -137,7 +137,7 @@ function ToDetailString(obj) {
} else {
return ToString(obj);
}
};
}
function MakeGenericError(constructor, type, args) {
......@@ -156,7 +156,7 @@ function MakeGenericError(constructor, type, args) {
e.type = type;
e.arguments = args;
return e;
};
}
/**
......@@ -175,7 +175,7 @@ function FormatMessage(message) {
var format = kMessages[message.type];
if (!format) return "<unknown message " + message.type + ">";
return FormatString(format, message.args);
};
}
function GetLineNumber(message) {
......@@ -183,7 +183,7 @@ function GetLineNumber(message) {
var location = message.script.locationFromPosition(message.startPos);
if (location == null) return -1;
return location.line + 1;
};
}
// Returns the source code line containing the given source
......@@ -193,37 +193,37 @@ function GetSourceLine(message) {
if (location == null) return "";
location.restrict();
return location.sourceText();
};
}
function MakeTypeError(type, args) {
return MakeGenericError($TypeError, type, args);
};
}
function MakeRangeError(type, args) {
return MakeGenericError($RangeError, type, args);
};
}
function MakeSyntaxError(type, args) {
return MakeGenericError($SyntaxError, type, args);
};
}
function MakeReferenceError(type, args) {
return MakeGenericError($ReferenceError, type, args);
};
}
function MakeEvalError(type, args) {
return MakeGenericError($EvalError, type, args);
};
}
function MakeError(type, args) {
return MakeGenericError($Error, type, args);
};
}
/**
......@@ -445,7 +445,7 @@ function SourceLocation(script, position, line, column, start, end) {
this.column = column;
this.start = start;
this.end = end;
};
}
const kLineLengthLimit = 78;
......@@ -473,7 +473,7 @@ SourceLocation.prototype.restrict = function (opt_limit, opt_before) {
// If no before is specified center for small limits and perfer more source
// before the the position that after for longer limits.
if (limit <= 20) {
before = $Math_floor(limit / 2);
before = $floor(limit / 2);
} else {
before = limit - 10;
}
......@@ -554,7 +554,7 @@ function GetPositionInLine(message) {
if (location == null) return -1;
location.restrict();
return message.startPos - location.start;
};
}
function ErrorMessage(type, args, startPos, endPos, script, stackTrace) {
......@@ -564,12 +564,12 @@ function ErrorMessage(type, args, startPos, endPos, script, stackTrace) {
this.args = args;
this.script = script;
this.stackTrace = stackTrace;
};
}
function MakeMessage(type, args, startPos, endPos, script, stackTrace) {
return new ErrorMessage(type, args, startPos, endPos, script, stackTrace);
};
}
function GetStackTraceLine(recv, fun, pos, isGlobal) {
......@@ -578,7 +578,7 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
} catch (e) {
return "<error: " + e + ">";
}
};
}
function GetFunctionName(fun, recv) {
......@@ -589,7 +589,7 @@ function GetFunctionName(fun, recv) {
return prop;
}
return "[anonymous]";
};
}
function UnsafeGetStackTraceLine(recv, fun, pos, isTopLevel) {
......@@ -619,20 +619,20 @@ function UnsafeGetStackTraceLine(recv, fun, pos, isTopLevel) {
}
}
return (result) ? " at " + result : result;
};
}
// ----------------------------------------------------------------------------
// Error implementation
function DefineError(name) {
var f = function(msg) {};
function DefineError(f) {
// Store the error function in both the global object
// and the runtime object. The function is fetched
// from the runtime object when throwing errors from
// within the runtime system to avoid strange side
// effects when overwriting the error functions from
// user code.
var name = f.name;
%AddProperty(global, name, f, DONT_ENUM);
this['$' + name] = f;
// Configure the error function.
......@@ -648,22 +648,22 @@ function DefineError(name) {
return new f(m);
}
});
};
}
$Math.__proto__ = global.Object.prototype;
DefineError('Error');
DefineError('TypeError');
DefineError('RangeError');
DefineError('SyntaxError');
DefineError('ReferenceError');
DefineError('EvalError');
DefineError('URIError');
DefineError(function Error() { });
DefineError(function TypeError() { });
DefineError(function RangeError() { });
DefineError(function SyntaxError() { });
DefineError(function ReferenceError() { });
DefineError(function EvalError() { });
DefineError(function URIError() { });
// Setup extra properties of the Error.prototype object.
$Error.prototype.message = '';
%AddProperty($Error.prototype, 'toString', function() {
%AddProperty($Error.prototype, 'toString', function toString() {
var type = this.type;
if (type && !this.hasOwnProperty("message")) {
return this.name + ": " + FormatMessage({ type: type, args: this.arguments });
......
......@@ -338,7 +338,7 @@ Mirror.prototype.toText = function() {
function ValueMirror(type, value) {
Mirror.call(this, type);
this.value_ = value;
};
}
inherits(ValueMirror, Mirror);
......@@ -372,7 +372,7 @@ ValueMirror.prototype.value = function() {
*/
function UndefinedMirror() {
ValueMirror.call(this, UNDEFINED_TYPE, void 0);
};
}
inherits(UndefinedMirror, ValueMirror);
......@@ -388,7 +388,7 @@ UndefinedMirror.prototype.toText = function() {
*/
function NullMirror() {
ValueMirror.call(this, NULL_TYPE, null);
};
}
inherits(NullMirror, ValueMirror);
......@@ -405,7 +405,7 @@ NullMirror.prototype.toText = function() {
*/
function BooleanMirror(value) {
ValueMirror.call(this, BOOLEAN_TYPE, value);
};
}
inherits(BooleanMirror, ValueMirror);
......@@ -428,7 +428,7 @@ BooleanMirror.prototype.toText = function() {
*/
function NumberMirror(value) {
ValueMirror.call(this, NUMBER_TYPE, value);
};
}
inherits(NumberMirror, ValueMirror);
......@@ -451,7 +451,7 @@ NumberMirror.prototype.toText = function() {
*/
function StringMirror(value) {
ValueMirror.call(this, STRING_TYPE, value);
};
}
inherits(StringMirror, ValueMirror);
......@@ -493,7 +493,7 @@ StringMirror.prototype.toText = function() {
*/
function ObjectMirror(value, type) {
ValueMirror.call(this, type || OBJECT_TYPE, value);
};
}
inherits(ObjectMirror, ValueMirror);
......@@ -805,7 +805,7 @@ ObjectMirror.prototype.toText = function() {
function FunctionMirror(value) {
ObjectMirror.call(this, value, FUNCTION_TYPE);
this.resolved_ = true;
};
}
inherits(FunctionMirror, ObjectMirror);
......@@ -918,7 +918,7 @@ function UnresolvedFunctionMirror(value) {
this.propertyCount_ = 0;
this.elementCount_ = 0;
this.resolved_ = false;
};
}
inherits(UnresolvedFunctionMirror, FunctionMirror);
......@@ -960,7 +960,7 @@ UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) {
*/
function ArrayMirror(value) {
ObjectMirror.call(this, value);
};
}
inherits(ArrayMirror, ObjectMirror);
......@@ -1008,7 +1008,7 @@ ArrayMirror.prototype.fillJSON_ = function(content, details) {
*/
function DateMirror(value) {
ObjectMirror.call(this, value);
};
}
inherits(DateMirror, ObjectMirror);
......@@ -1033,7 +1033,7 @@ DateMirror.prototype.toText = function() {
*/
function RegExpMirror(value) {
ObjectMirror.call(this, value, REGEXP_TYPE);
};
}
inherits(RegExpMirror, ObjectMirror);
......@@ -1098,7 +1098,7 @@ RegExpMirror.prototype.toText = function() {
*/
function ErrorMirror(value) {
ObjectMirror.call(this, value, ERROR_TYPE);
};
}
inherits(ErrorMirror, ObjectMirror);
......@@ -1145,7 +1145,7 @@ function PropertyMirror(mirror, name, value, details) {
this.name_ = name;
this.value_ = value;
this.details_ = details;
};
}
inherits(PropertyMirror, Mirror);
......@@ -1228,7 +1228,7 @@ PropertyMirror.prototype.fillJSON_ = function(content, details) {
*/
function InterceptorPropertyMirror(mirror, name, value) {
PropertyMirror.call(this, mirror, name, value, PropertyType.Interceptor);
};
}
inherits(InterceptorPropertyMirror, PropertyMirror);
......@@ -1243,7 +1243,7 @@ function AccessorMirror(getter, setter) {
Mirror.call(this, ACCESSOR_TYPE);
this.getter_ = getter;
this.setter_ = setter;
};
}
inherits(AccessorMirror, Mirror);
......@@ -1334,7 +1334,7 @@ const kFrameDetailsNameValueSize = 2;
function FrameDetails(break_id, index) {
this.break_id_ = break_id;
this.details_ = %GetFrameDetails(break_id, index);
};
}
FrameDetails.prototype.frameId = function() {
......@@ -1440,7 +1440,7 @@ function FrameMirror(break_id, index) {
this.break_id_ = break_id;
this.index_ = index;
this.details_ = new FrameDetails(break_id, index);
};
}
inherits(FrameMirror, Mirror);
......@@ -1744,7 +1744,7 @@ FrameMirror.prototype.toText = function(opt_locals) {
function ScriptMirror(script) {
Mirror.call(this, SCRIPT_TYPE);
this.script_ = script;
};
}
inherits(ScriptMirror, Mirror);
......@@ -1813,27 +1813,27 @@ ScriptMirror.prototype.toText = function() {
function MakeJSONPair_(name, value) {
return '"' + name + '":' + value;
};
}
function ArrayToJSONObject_(content) {
return '{' + content.join(',') + '}';
};
}
function ArrayToJSONArray_(content) {
return '[' + content.join(',') + ']';
};
}
function BooleanToJSON_(value) {
return String(value);
};
}
function NumberToJSON_(value) {
return String(value);
};
}
// Mapping of some control characters to avoid the \uXXXX syntax for most
......@@ -1886,7 +1886,7 @@ function StringToJSON_(value) {
// Simple string with no special characters.
return '"' + value + '"';
};
}
/**
......@@ -1910,7 +1910,7 @@ function DateToISO8601_(value) {
f(builtins.GetUTCMinutesFrom(value)) + ':' +
f(builtins.GetUTCSecondsFrom(value)) + '.' +
g(builtins.GetUTCMillisecondsFrom(value)) + 'Z';
};
}
/**
* Convert a Date to ISO 8601 format. To avoid depending on the Date object
......@@ -1921,4 +1921,4 @@ function DateToISO8601_(value) {
*/
function DateToJSON_(value) {
return '"' + DateToISO8601_(value) + '"';
};
}
This diff is collapsed.
......@@ -135,6 +135,13 @@ static Object* Runtime_CreateObjectLiteralBoilerplate(Arguments args) {
Handle<FixedArray> literals = args.at<FixedArray>(0);
int literals_index = Smi::cast(args[1])->value();
Handle<FixedArray> constant_properties = args.at<FixedArray>(2);
// Get the global context from the literals array. This is the
// context in which the function was created and we use the object
// function from this context to create the object literal. We do
// not use the object function from the current global context
// because this might be the object function from another context
// which we should not have access to.
Handle<Context> context =
Handle<Context>(JSFunction::GlobalContextFromLiterals(*literals));
......@@ -143,11 +150,6 @@ static Object* Runtime_CreateObjectLiteralBoilerplate(Arguments args) {
constant_properties,
is_result_from_cache);
// Get the object function from the literals array. This is the
// object function from the context in which the function was
// created. We do not use the object function from the current
// global context because this might be the object function from
// another context which we should not have access to.
Handle<JSObject> boilerplate = Factory::NewJSObjectFromMap(map);
{ // Add the constant propeties to the boilerplate.
int length = constant_properties->length();
......@@ -189,8 +191,8 @@ static Object* Runtime_CreateArrayLiteral(Arguments args) {
// Takes a FixedArray of elements containing the literal elements of
// the array literal and produces JSArray with those elements.
// Additionally takes the literals array of the surrounding function
// which contains the Array function to use for creating the array
// literal.
// which contains the context from which to get the Array function
// to use for creating the array literal.
ASSERT(args.length() == 2);
CONVERT_CHECKED(FixedArray, elements, args[0]);
CONVERT_CHECKED(FixedArray, literals, args[1]);
......@@ -727,11 +729,11 @@ static Object* Runtime_MaterializeRegExpLiteral(Arguments args) {
Handle<String> pattern = args.at<String>(2);
Handle<String> flags = args.at<String>(3);
// Get the RegExp function from the literals array. This is the
// RegExp function from the context in which the function was
// created. We do not use the RegExp function from the current
// global context because this might be the RegExp function from
// another context which we should not have access to.
// Get the RegExp function from the context in the literals array.
// This is the RegExp function from the context in which the
// function was created. We do not use the RegExp function from the
// current global context because this might be the RegExp function
// from another context which we should not have access to.
Handle<JSFunction> constructor =
Handle<JSFunction>(
JSFunction::GlobalContextFromLiterals(*literals)->regexp_function());
......
......@@ -93,7 +93,7 @@ function EQUALS(y) {
}
}
};
}
// ECMA-262, section 11.9.4, page 56.
......@@ -119,7 +119,7 @@ function STRICT_EQUALS(x) {
}
return %_ObjectEquals(this, x) ? 0 : 1;
};
}
// ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
......@@ -137,7 +137,7 @@ function COMPARE(x, ncr) {
} else {
return %NumberCompare(%ToNumber(a), %ToNumber(b), ncr);
}
};
}
......@@ -163,43 +163,43 @@ function ADD(x) {
} else {
return %NumberAdd(%ToNumber(a), %ToNumber(b));
}
};
}
// ECMA-262, section 11.6.2, page 50.
function SUB(x) {
return %NumberSub(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.5.1, page 48.
function MUL(x) {
return %NumberMul(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.5.2, page 49.
function DIV(x) {
return %NumberDiv(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.5.3, page 49.
function MOD(x) {
return %NumberMod(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.4.4, page 47.
function INC() {
return %NumberAdd(%ToNumber(this), 1);
};
}
// ECMA-262, section 11.4.5, page 48.
function DEC() {
return %NumberSub(%ToNumber(this), 1);
};
}
......@@ -211,49 +211,49 @@ function DEC() {
// ECMA-262, section 11.10, page 57.
function BIT_OR(x) {
return %NumberOr(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.10, page 57.
function BIT_AND(x) {
return %NumberAnd(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.10, page 57.
function BIT_XOR(x) {
return %NumberXor(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.4.7, page 47.
function UNARY_MINUS() {
return %NumberUnaryMinus(%ToNumber(this));
};
}
// ECMA-262, section 11.4.8, page 48.
function BIT_NOT() {
return %NumberNot(%ToNumber(this));
};
}
// ECMA-262, section 11.7.1, page 51.
function SHL(x) {
return %NumberShl(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.7.2, page 51.
function SAR(x) {
return %NumberSar(%ToNumber(this), %ToNumber(x));
};
}
// ECMA-262, section 11.7.3, page 52.
function SHR(x) {
return %NumberShr(%ToNumber(this), %ToNumber(x));
};
}
......@@ -265,7 +265,7 @@ function SHR(x) {
// ECMA-262, section 11.4.1, page 46.
function DELETE(key) {
return %DeleteProperty(%ToObject(this), %ToString(key));
};
}
// ECMA-262, section 11.8.7, page 54.
......@@ -274,7 +274,7 @@ function IN(x) {
throw %MakeTypeError('invalid_in_operator_use', [this, x]);
}
return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToString(this));
};
}
// ECMA-262, section 11.8.6, page 54.
......@@ -297,14 +297,14 @@ function INSTANCE_OF(F) {
// Return whether or not O is in the prototype chain of V.
return %IsInPrototypeChain(O, V);
};
}
// Get an array of property keys for the given object. Used in
// for-in statements.
function GET_KEYS() {
return %GetPropertyNames(this);
};
}
// Filter a given key against an object by checking if the object
......@@ -314,7 +314,7 @@ function FILTER_KEY(key) {
var string = %ToString(key);
if (%HasProperty(this, string)) return string;
return null;
};
}
function CALL_NON_FUNCTION() {
......@@ -326,7 +326,7 @@ function CALL_NON_FUNCTION() {
var parameters = %NewArguments(delegate);
return delegate.apply(callee, parameters);
};
}
function APPLY_PREPARE(args) {
......@@ -363,30 +363,30 @@ function APPLY_PREPARE(args) {
// Return the length which is the number of arguments to copy to the
// stack. It is guaranteed to be a small integer at this point.
return length;
};
}
function APPLY_OVERFLOW(length) {
throw %MakeRangeError('apply_overflow', [length]);
};
}
// Convert the receiver to an object - forward to ToObject.
function TO_OBJECT() {
return %ToObject(this);
};
}
// Convert the receiver to a number - forward to ToNumber.
function TO_NUMBER() {
return %ToNumber(this);
};
}
// Convert the receiver to a string - forward to ToString.
function TO_STRING() {
return %ToString(this);
};
}
/* -------------------------------------
......@@ -401,7 +401,7 @@ function ToPrimitive(x, hint) {
if (x == null) return x; // check for null, undefined
if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x);
};
}
// ECMA-262, section 9.3, page 31.
......@@ -411,7 +411,7 @@ function ToNumber(x) {
if (IS_BOOLEAN(x)) return x ? 1 : 0;
if (IS_UNDEFINED(x)) return $NaN;
return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x));
};
}
// ECMA-262, section 9.8, page 35.
......@@ -421,7 +421,7 @@ function ToString(x) {
if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
if (IS_UNDEFINED(x)) return 'undefined';
return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x));
};
}
// ... where did this come from?
......@@ -431,7 +431,7 @@ function ToBoolean(x) {
if (x == null) return false;
if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
return true;
};
}
// ECMA-262, section 9.9, page 36.
......@@ -441,28 +441,28 @@ function ToObject(x) {
if (IS_BOOLEAN(x)) return new $Boolean(x);
if (x == null) throw %MakeTypeError('null_to_object', []);
return x;
};
}
// ECMA-262, section 9.4, page 34.
function ToInteger(x) {
if (%_IsSmi(x)) return x;
return %NumberToInteger(ToNumber(x));
};
}
// ECMA-262, section 9.6, page 34.
function ToUint32(x) {
if (%_IsSmi(x) && x >= 0) return x;
return %NumberToJSUint32(ToNumber(x));
};
}
// ECMA-262, section 9.5, page 34
function ToInt32(x) {
if (%_IsSmi(x)) return x;
return %NumberToJSInt32(ToNumber(x));
};
}
......@@ -481,7 +481,7 @@ function IsPrimitive(x) {
// considered a primitive value.
return IS_NULL(x);
}
};
}
// ECMA-262, section 8.6.2.6, page 28.
......@@ -497,7 +497,7 @@ function DefaultNumber(x) {
}
throw %MakeTypeError('cannot_convert_to_primitive', []);
};
}
// ECMA-262, section 8.6.2.6, page 28.
......@@ -513,7 +513,7 @@ function DefaultString(x) {
}
throw %MakeTypeError('cannot_convert_to_primitive', []);
};
}
// NOTE: Setting the prototype for Array must take place as early as
......
......@@ -46,17 +46,20 @@
%AddProperty($String.prototype, "constructor", $String, DONT_ENUM);
%AddProperty($String.prototype, "valueOf", function() {
%AddProperty($String.prototype, "valueOf", function valueOf() {
if (!IS_STRING(this) && %ClassOf(this) !== 'String')
throw new $TypeError('String.prototype.valueOf is not generic');
return %_ValueOf(this);
}, DONT_ENUM);
%AddProperty($String.prototype, "toString", $String.prototype.valueOf, DONT_ENUM);
%AddProperty($String.prototype, "toString", function toString() {
if (!IS_STRING(this) && %ClassOf(this) !== 'String')
throw new $TypeError('String.prototype.toString is not generic');
return %_ValueOf(this);
}, DONT_ENUM);
// ECMA-262 section 15.5.4.5
%AddProperty($String.prototype, "charCodeAt", function(pos) {
%AddProperty($String.prototype, "charCodeAt", function charCodeAt(pos) {
var fast_answer = %_FastCharCodeAt(this, pos);
if (%_IsSmi(fast_answer)) {
return fast_answer;
......@@ -68,7 +71,7 @@
// ECMA-262, section 15.5.4.6
%AddProperty($String.prototype, "concat", function() {
%AddProperty($String.prototype, "concat", function concat() {
var len = %_ArgumentsLength();
var parts = new $Array(len + 1);
parts[0] = ToString(this);
......@@ -92,7 +95,7 @@ function SubString(string, start, end) {
// ECMA-262, section 15.5.4.11
%AddProperty($String.prototype, "replace", function (search, replace) {
%AddProperty($String.prototype, "replace", function replace(search, replace) {
var subject = ToString(this);
// Delegate to one of the regular expression variants if necessary.
......@@ -330,7 +333,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
// ECMA-262 section 15.5.4.7
%AddProperty($String.prototype, "indexOf", function(searchString /* position */) { // length == 1
%AddProperty($String.prototype, "indexOf", function indexOf(searchString /* position */) { // length == 1
var subject_str = ToString(this);
var pattern_str = ToString(searchString);
var subject_str_len = subject_str.length;
......@@ -348,7 +351,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
// ECMA-262 section 15.5.4.8
%AddProperty($String.prototype, "lastIndexOf", function(searchString /* position */) { // length == 1
%AddProperty($String.prototype, "lastIndexOf", function lastIndexOf(searchString /* position */) { // length == 1
var sub = ToString(this);
var pat = ToString(searchString);
var index = (%_ArgumentsLength() > 1)
......@@ -371,7 +374,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
//
// This function is implementation specific. For now, we do not
// do anything locale specific.
%AddProperty($String.prototype, "localeCompare", function(other) {
%AddProperty($String.prototype, "localeCompare", function localeCompare(other) {
if (%_ArgumentsLength() === 0) return 0;
var this_str = ToString(this);
......@@ -381,7 +384,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
// ECMA-262 section 15.5.4.10
%AddProperty($String.prototype, "match", function(regexp) {
%AddProperty($String.prototype, "match", function match(regexp) {
if (!IS_REGEXP(regexp)) regexp = new ORIGINAL_REGEXP(regexp);
var subject = ToString(this);
......@@ -404,7 +407,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
// ECMA-262 section 15.5.4.12
%AddProperty($String.prototype, "search", function(re) {
%AddProperty($String.prototype, "search", function search(re) {
var regexp = new ORIGINAL_REGEXP(re);
var s = ToString(this);
var last_idx = regexp.lastIndex; // keep old lastIndex
......@@ -419,7 +422,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
// ECMA-262 section 15.5.4.13
%AddProperty($String.prototype, "slice", function(start, end) {
%AddProperty($String.prototype, "slice", function slice(start, end) {
var s = ToString(this);
var s_len = s.length;
var start_i = TO_INTEGER(start);
......@@ -454,7 +457,7 @@ function ApplyReplacementFunction(replace, captures, subject) {
// ECMA-262 section 15.5.4.14
%AddProperty($String.prototype, "split", function(separator, limit) {
%AddProperty($String.prototype, "split", function split(separator, limit) {
var subject = ToString(this);
var result = [];
var lim = (limit === void 0) ? 0xffffffff : ToUint32(limit);
......@@ -546,7 +549,7 @@ function splitMatch(separator, subject, current_index, start_index) {
// ECMA-262 section 15.5.4.15
%AddProperty($String.prototype, "substring", function(start, end) {
%AddProperty($String.prototype, "substring", function substring(start, end) {
var s = ToString(this);
var s_len = s.length;
var start_i = TO_INTEGER(start);
......@@ -570,7 +573,7 @@ function splitMatch(separator, subject, current_index, start_index) {
// This is not a part of ECMA-262.
%AddProperty($String.prototype, "substr", function(start, n) {
%AddProperty($String.prototype, "substr", function substr(start, n) {
var s = ToString(this);
var len;
......@@ -608,27 +611,31 @@ function splitMatch(separator, subject, current_index, start_index) {
// ECMA-262, 15.5.4.16
%AddProperty($String.prototype, "toLowerCase", function() {
%AddProperty($String.prototype, "toLowerCase", function toLowerCase() {
return %StringToLowerCase(ToString(this));
}, DONT_ENUM);
// ECMA-262, 15.5.4.17
%AddProperty($String.prototype, "toLocaleLowerCase", $String.prototype.toLowerCase, DONT_ENUM);
%AddProperty($String.prototype, "toLocaleLowerCase", function toLocaleLowerCase() {
return %StringToLowerCase(ToString(this));
}, DONT_ENUM);
// ECMA-262, 15.5.4.18
%AddProperty($String.prototype, "toUpperCase", function() {
%AddProperty($String.prototype, "toUpperCase", function toUpperCase() {
return %StringToUpperCase(ToString(this));
}, DONT_ENUM);
// ECMA-262, 15.5.4.19
%AddProperty($String.prototype, "toLocaleUpperCase", $String.prototype.toUpperCase, DONT_ENUM);
%AddProperty($String.prototype, "toLocaleUpperCase", function toLocaleUpperCase() {
return %StringToUpperCase(ToString(this));
}, DONT_ENUM);
// ECMA-262, section 15.5.3.2
%AddProperty($String, "fromCharCode", function(code) {
%AddProperty($String, "fromCharCode", function fromCharCode(code) {
var n = %_ArgumentsLength();
if (n == 1) return %CharFromCode(ToNumber(code) & 0xffff)
......@@ -642,14 +649,14 @@ function splitMatch(separator, subject, current_index, start_index) {
// ECMA-262, section 15.5.4.4
function CharAt(pos) {
function charAt(pos) {
var subject = ToString(this);
var index = TO_INTEGER(pos);
if (index >= subject.length || index < 0) return "";
return %CharFromCode(%StringCharCodeAt(subject, index));
};
%AddProperty($String.prototype, "charAt", CharAt, DONT_ENUM);
%AddProperty($String.prototype, "charAt", charAt, DONT_ENUM);
// Helper function for very basic XSS protection.
......@@ -663,67 +670,67 @@ function HtmlEscape(str) {
// Compatibility support for KJS.
// Tested by mozilla/js/tests/js1_5/Regress/regress-276103.js.
%AddProperty($String.prototype, "link", function(link) {
return "<a href=\"" + HtmlEscape(link) + "\">" + this + "</a>";
%AddProperty($String.prototype, "link", function link(s) {
return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>";
}, DONT_ENUM);
%AddProperty($String.prototype, "anchor", function(name) {
%AddProperty($String.prototype, "anchor", function anchor(name) {
return "<a name=\"" + HtmlEscape(name) + "\">" + this + "</a>";
}, DONT_ENUM);
%AddProperty($String.prototype, "fontcolor", function(color) {
%AddProperty($String.prototype, "fontcolor", function fontcolor(color) {
return "<font color=\"" + HtmlEscape(color) + "\">" + this + "</font>";
}, DONT_ENUM);
%AddProperty($String.prototype, "fontsize", function(size) {
%AddProperty($String.prototype, "fontsize", function fontsize(size) {
return "<font size=\"" + HtmlEscape(size) + "\">" + this + "</font>";
}, DONT_ENUM);
%AddProperty($String.prototype, "big", function() {
%AddProperty($String.prototype, "big", function big() {
return "<big>" + this + "</big>";
}, DONT_ENUM);
%AddProperty($String.prototype, "blink", function() {
%AddProperty($String.prototype, "blink", function blink() {
return "<blink>" + this + "</blink>";
}, DONT_ENUM);
%AddProperty($String.prototype, "bold", function() {
%AddProperty($String.prototype, "bold", function bold() {
return "<b>" + this + "</b>";
}, DONT_ENUM);
%AddProperty($String.prototype, "fixed", function() {
%AddProperty($String.prototype, "fixed", function fixed() {
return "<tt>" + this + "</tt>";
}, DONT_ENUM);
%AddProperty($String.prototype, "italics", function() {
%AddProperty($String.prototype, "italics", function italics() {
return "<i>" + this + "</i>";
}, DONT_ENUM);
%AddProperty($String.prototype, "small", function() {
%AddProperty($String.prototype, "small", function small() {
return "<small>" + this + "</small>";
}, DONT_ENUM);
%AddProperty($String.prototype, "strike", function() {
%AddProperty($String.prototype, "strike", function strike() {
return "<strike>" + this + "</strike>";
}, DONT_ENUM);
%AddProperty($String.prototype, "sub", function() {
%AddProperty($String.prototype, "sub", function sub() {
return "<sub>" + this + "</sub>";
}, DONT_ENUM);
%AddProperty($String.prototype, "sup", function() {
%AddProperty($String.prototype, "sup", function sup() {
return "<sup>" + this + "</sup>";
}, DONT_ENUM);
......
......@@ -35,7 +35,7 @@ function URIAddEncodedOctetToBuffer(octet, result, index) {
result[index++] = hexCharCodeArray[octet >> 4];
result[index++] = hexCharCodeArray[octet & 0x0F];
return index;
};
}
function URIEncodeOctets(octets, result, index) {
......@@ -44,7 +44,7 @@ function URIEncodeOctets(octets, result, index) {
if (octets[2]) index = URIAddEncodedOctetToBuffer(octets[2], result, index);
if (octets[3]) index = URIAddEncodedOctetToBuffer(octets[3], result, index);
return index;
};
}
function URIEncodeSingle(cc, result, index) {
......@@ -63,7 +63,7 @@ function URIEncodeSingle(cc, result, index) {
octets[2] = z + 128;
}
return URIEncodeOctets(octets, result, index);
};
}
function URIEncodePair(cc1 , cc2, result, index) {
......@@ -78,7 +78,7 @@ function URIEncodePair(cc1 , cc2, result, index) {
octets[2] = ((x << 4) | y) + 128;
octets[3] = z + 128;
return URIEncodeOctets(octets, result, index);
};
}
function URIHexCharsToCharCode(ch1, ch2) {
......@@ -86,7 +86,7 @@ function URIHexCharsToCharCode(ch1, ch2) {
throw new $URIError("URI malformed");
}
return HexStrToCharCode(ch1 + ch2);
};
}
function URIDecodeOctets(octets, result, index) {
......@@ -111,7 +111,7 @@ function URIDecodeOctets(octets, result, index) {
var y = octets[0] & 31;
result[index++] = (y << 6) | z;
return index;
};
}
// ECMA-262, section 15.1.3
......@@ -137,7 +137,7 @@ function Encode(uri, unescape) {
}
}
return %StringFromCharCodeArray(result);
};
}
// ECMA-262, section 15.1.3
......@@ -177,7 +177,7 @@ function Decode(uri, reserved) {
}
result.length = index;
return %StringFromCharCodeArray(result);
};
}
// ECMA-262 - 15.1.3.1.
......@@ -202,7 +202,7 @@ function URIDecode(uri) {
};
var string = ToString(uri);
return Decode(string, reservedPredicate);
};
}
// ECMA-262 - 15.1.3.2.
......@@ -210,7 +210,7 @@ function URIDecodeComponent(component) {
function reservedPredicate(cc) { return false; };
var string = ToString(component);
return Decode(string, reservedPredicate);
};
}
// Does the char code correspond to an alpha-numeric char.
......@@ -223,7 +223,7 @@ function isAlphaNumeric(cc) {
if (48 <= cc && cc <= 57) return true;
return false;
};
}
// ECMA-262 - 15.1.3.3.
......@@ -252,7 +252,7 @@ function URIEncode(uri) {
var string = ToString(uri);
return Encode(string, unescapePredicate);
};
}
// ECMA-262 - 15.1.3.4
......@@ -275,7 +275,7 @@ function URIEncodeComponent(component) {
var string = ToString(component);
return Encode(string, unescapePredicate);
};
}
const hexCharArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
......@@ -296,7 +296,7 @@ function HexValueOf(c) {
if (code >= 97 && code <= 102) return code - 87;
return -1;
};
}
// Convert a character code to 4-digit hex string representation
......@@ -309,7 +309,7 @@ function CharCodeToHex4Str(cc) {
cc = cc >>> 4;
}
return r;
};
}
// Converts hex string to char code. Not efficient.
......@@ -321,7 +321,7 @@ function HexStrToCharCode(s) {
m = m + 4;
}
return r;
};
}
// Returns true if all digits in string s are valid hex numbers
......@@ -335,14 +335,14 @@ function IsValidHex(s) {
}
}
return true;
};
}
// ECMA-262 - B.2.1.
function URIEscape(str) {
var s = ToString(str);
return %URIEscape(s);
};
}
// ECMA-262 - B.2.2.
......@@ -355,16 +355,17 @@ function URIUnescape(str) {
// -------------------------------------------------------------------
function SetupURI() {
// Setup non-enumerable URI properties of the global object.
InstallProperties(global, DONT_ENUM, {
escape: URIEscape,
unescape: URIUnescape,
decodeURI: URIDecode,
decodeURIComponent: URIDecodeComponent,
encodeURI: URIEncode,
encodeURIComponent: URIEncodeComponent
});
};
// Setup non-enumerable URI functions on the global object and set
// their names.
InstallFunctions(global, DONT_ENUM, $Array(
"escape", URIEscape,
"unescape", URIUnescape,
"decodeURI", URIDecode,
"decodeURIComponent", URIDecodeComponent,
"encodeURI", URIEncode,
"encodeURIComponent", URIEncodeComponent
));
}
SetupURI();
......@@ -27,6 +27,7 @@
// This file relies on the fact that the following declarations have been made
//
// in runtime.js:
// const $Object = global.Object;
// const $Boolean = global.Boolean;
......@@ -34,6 +35,9 @@
// const $Function = global.Function;
// const $Array = global.Array;
// const $NaN = 0/0;
//
// in math.js:
// const $floor = MathFloor
// ECMA 262 - 15.1.1.1.
......@@ -52,14 +56,14 @@
function $isNaN(number) {
var n = ToNumber(number);
return NUMBER_IS_NAN(n);
};
}
%AddProperty(global, "isNaN", $isNaN, DONT_ENUM);
// ECMA 262 - 15.1.5
function $isFinite(number) {
return %NumberIsFinite(ToNumber(number));
};
}
%AddProperty(global, "isFinite", $isFinite, DONT_ENUM);
......@@ -75,9 +79,9 @@ function $isFinite(number) {
if (%_IsSmi(string)) return string;
if (IS_NUMBER(string)) {
if (string >= 0.01 && string < 1e9)
return $Math_floor(string);
return $floor(string);
if (string <= -0.01 && string > -1e9)
return - $Math_floor(-string);
return - $floor(-string);
}
} else {
radix = TO_INT32(radix);
......@@ -382,7 +386,7 @@ function FunctionSourceString(func) {
if (source.match(regexp)) source = source.replace(regexp, "$1");
var name = %FunctionGetName(func);
return 'function ' + name + source;
};
}
%AddProperty($Function.prototype, "toString", function() {
......@@ -413,6 +417,6 @@ function NewFunction(arg1) { // length == 1
var f = %CompileString(source, -1, false)();
%FunctionSetName(f, "anonymous");
return %SetNewFunctionAttributes(f);
};
}
%SetCode($Function, NewFunction);
......@@ -4937,3 +4937,22 @@ THREADED_TEST(CompilationCache) {
CHECK_EQ(1234, script1->Run()->Int32Value());
CHECK_EQ(1234, script2->Run()->Int32Value());
}
static v8::Handle<Value> FunctionNameCallback(const v8::Arguments& args) {
ApiTestFuzzer::Fuzz();
return v8_num(42);
}
THREADED_TEST(CallbackFunctionName) {
v8::HandleScope scope;
LocalContext context;
Local<ObjectTemplate> t = ObjectTemplate::New();
t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback));
context->Global()->Set(v8_str("obj"), t->NewInstance());
v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
CHECK(value->IsString());
v8::String::AsciiValue name(value);
CHECK_EQ("asdf", *name);
}
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function TestFunctionNames(object, names) {
for (var i = 0; i < names.length; i++) {
assertEquals(names[i], object[names[i]].name);
}
}
// Array.prototype functions.
var arrayPrototypeFunctions = [
"toString", "toLocaleString", "join", "pop", "push", "concat", "reverse",
"shift", "unshift", "slice", "splice", "sort", "filter", "forEach",
"some", "every", "map", "indexOf", "lastIndexOf"];
TestFunctionNames(Array.prototype, arrayPrototypeFunctions);
// Date functions.
var dateFunctions = ["UTC", "parse", "now"];
TestFunctionNames(Date, dateFunctions);
// Date.prototype functions.
var datePrototypeFunctions = [
"toString", "toDateString", "toTimeString", "toLocaleString",
"toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
"getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth",
"getDate", "getUTCDate", "getDay", "getUTCDay", "getHours",
"getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds",
"getUTCSeconds", "getMilliseconds", "getUTCMilliseconds",
"getTimezoneOffset", "setTime", "setMilliseconds",
"setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes",
"setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate",
"setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString",
"toUTCString", "getYear", "setYear"];
TestFunctionNames(Date.prototype, datePrototypeFunctions);
// Math functions.
var mathFunctions = [
"random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor",
"log", "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"];
TestFunctionNames(Math, mathFunctions);
// RegExp.prototype functions.
var regExpPrototypeFunctions = ["exec", "test", "toString", "compile"];
TestFunctionNames(RegExp.prototype, regExpPrototypeFunctions);
// String functions.
var stringFunctions = ["fromCharCode"];
TestFunctionNames(String, stringFunctions);
// String.prototype functions.
var stringPrototypeFunctions = [
"toString", "valueOf", "charAt", "charCodeAt", "concat", "indexOf",
"lastIndexOf", "localeCompare", "match", "replace", "search", "slice",
"split", "substring", "substr", "toLowerCase", "toLocaleLowerCase",
"toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor",
"fontsize", "big", "blink", "bold", "fixed", "italics", "small",
"strike", "sub", "sup"];
TestFunctionNames(String.prototype, stringPrototypeFunctions);
// Global functions.
var globalFunctions = [
"escape", "unescape", "decodeURI", "decodeURIComponent",
"encodeURI", "encodeURIComponent", "Error", "TypeError",
"RangeError", "SyntaxError", "ReferenceError", "EvalError",
"URIError"];
TestFunctionNames(this, globalFunctions);
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