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