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,105 +490,105 @@ function ArrayReverse() { ...@@ -490,105 +490,105 @@ function ArrayReverse() {
} }
} }
return this; return this;
}; }
function ArrayShift() { function ArrayShift() {
var len = ToUint32(this.length); var len = ToUint32(this.length);
if (len === 0) { if (len === 0) {
this.length = 0; this.length = 0;
return; return;
} }
var first = this[0]; var first = this[0];
if (IS_ARRAY(this)) if (IS_ARRAY(this))
SmartMove(this, 0, 1, len, 0); SmartMove(this, 0, 1, len, 0);
else else
SimpleMove(this, 0, 1, len, 0); SimpleMove(this, 0, 1, len, 0);
this.length = len - 1; this.length = len - 1;
return first; return first;
}; }
function ArrayUnshift(arg1) { // length == 1 function ArrayUnshift(arg1) { // length == 1
var len = ToUint32(this.length); var len = ToUint32(this.length);
var num_arguments = %_ArgumentsLength(); var num_arguments = %_ArgumentsLength();
if (IS_ARRAY(this)) if (IS_ARRAY(this))
SmartMove(this, 0, 0, len, num_arguments); SmartMove(this, 0, 0, len, num_arguments);
else else
SimpleMove(this, 0, 0, len, num_arguments); SimpleMove(this, 0, 0, len, num_arguments);
for (var i = 0; i < num_arguments; i++) { for (var i = 0; i < num_arguments; i++) {
this[i] = %_Arguments(i); this[i] = %_Arguments(i);
} }
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) {
var len = ToUint32(this.length); var len = ToUint32(this.length);
var start_i = TO_INTEGER(start); var start_i = TO_INTEGER(start);
var end_i = len; var end_i = len;
if (end !== void 0) end_i = TO_INTEGER(end); if (end !== void 0) end_i = TO_INTEGER(end);
if (start_i < 0) { if (start_i < 0) {
start_i += len; start_i += len;
if (start_i < 0) start_i = 0; if (start_i < 0) start_i = 0;
} else { } else {
if (start_i > len) start_i = len; if (start_i > len) start_i = len;
} }
if (end_i < 0) { if (end_i < 0) {
end_i += len; end_i += len;
if (end_i < 0) end_i = 0; if (end_i < 0) end_i = 0;
} else { } else {
if (end_i > len) end_i = len; if (end_i > len) end_i = len;
} }
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) {
var num_arguments = %_ArgumentsLength(); var num_arguments = %_ArgumentsLength();
// SpiderMonkey and KJS return undefined in the case where no // SpiderMonkey and KJS return undefined in the case where no
// arguments are given instead of using the implicit undefined // arguments are given instead of using the implicit undefined
// arguments. This does not follow ECMA-262, but we do the same for // arguments. This does not follow ECMA-262, but we do the same for
// compatibility. // compatibility.
if (num_arguments == 0) return; if (num_arguments == 0) return;
var len = ToUint32(this.length); var len = ToUint32(this.length);
var start_i = TO_INTEGER(start); var start_i = TO_INTEGER(start);
if (start_i < 0) { if (start_i < 0) {
start_i += len; start_i += len;
if (start_i < 0) start_i = 0; if (start_i < 0) start_i = 0;
} else { } else {
if (start_i > len) start_i = len; if (start_i > len) start_i = len;
} }
// SpiderMonkey and KJS treat the case where no delete count is // SpiderMonkey and KJS treat the case where no delete count is
// given differently from when an undefined delete count is given. // given differently from when an undefined delete count is given.
// This does not follow ECMA-262, but we do the same for // This does not follow ECMA-262, but we do the same for
...@@ -601,18 +601,18 @@ function ArraySplice(start, delete_count) { ...@@ -601,18 +601,18 @@ function ArraySplice(start, delete_count) {
} else { } else {
del_count = len - start_i; del_count = len - start_i;
} }
var deleted_elements = []; var deleted_elements = [];
deleted_elements.length = del_count; deleted_elements.length = del_count;
// Number of elements to add. // Number of elements to add.
var num_additional_args = 0; var num_additional_args = 0;
if (num_arguments > 2) { if (num_arguments > 2) {
num_additional_args = num_arguments - 2; num_additional_args = num_arguments - 2;
} }
var use_simple_splice = true; var use_simple_splice = true;
if (IS_ARRAY(this) && num_additional_args !== del_count) { if (IS_ARRAY(this) && num_additional_args !== del_count) {
// If we are only deleting/moving a few things near the end of the // If we are only deleting/moving a few things near the end of the
// array then the simple version is going to be faster, because it // array then the simple version is going to be faster, because it
...@@ -622,7 +622,7 @@ function ArraySplice(start, delete_count) { ...@@ -622,7 +622,7 @@ function ArraySplice(start, delete_count) {
use_simple_splice = false; use_simple_splice = false;
} }
} }
if (use_simple_splice) { if (use_simple_splice) {
SimpleSlice(this, start_i, del_count, len, deleted_elements); SimpleSlice(this, start_i, del_count, len, deleted_elements);
SimpleMove(this, start_i, del_count, len, num_additional_args); SimpleMove(this, start_i, del_count, len, num_additional_args);
...@@ -630,7 +630,7 @@ function ArraySplice(start, delete_count) { ...@@ -630,7 +630,7 @@ function ArraySplice(start, delete_count) {
SmartSlice(this, start_i, del_count, len, deleted_elements); SmartSlice(this, start_i, del_count, len, deleted_elements);
SmartMove(this, start_i, del_count, len, num_additional_args); SmartMove(this, start_i, del_count, len, num_additional_args);
} }
// Insert the arguments into the resulting array in // Insert the arguments into the resulting array in
// place of the deleted elements. // place of the deleted elements.
var i = start_i; var i = start_i;
...@@ -640,10 +640,10 @@ function ArraySplice(start, delete_count) { ...@@ -640,10 +640,10 @@ function ArraySplice(start, delete_count) {
this[i++] = %_Arguments(arguments_index++); this[i++] = %_Arguments(arguments_index++);
} }
this.length = len - del_count + num_additional_args; this.length = len - del_count + num_additional_args;
// Return the deleted elements. // Return the deleted elements.
return deleted_elements; return deleted_elements;
}; }
function ArraySort(comparefn) { function ArraySort(comparefn) {
...@@ -651,7 +651,7 @@ function ArraySort(comparefn) { ...@@ -651,7 +651,7 @@ function ArraySort(comparefn) {
// For short (length <= 22) arrays, insertion sort is used for efficiency. // For short (length <= 22) arrays, insertion sort is used for efficiency.
var custom_compare = IS_FUNCTION(comparefn); var custom_compare = IS_FUNCTION(comparefn);
function Compare(x,y) { function Compare(x,y) {
if (custom_compare) { if (custom_compare) {
return comparefn.call(null, x, y); return comparefn.call(null, x, y);
...@@ -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) {
...@@ -833,9 +832,9 @@ function ArrayEvery(f, receiver) { ...@@ -833,9 +832,9 @@ function ArrayEvery(f, receiver) {
if (!f.call(receiver, current, i, this)) return false; if (!f.call(receiver, current, i, this)) return false;
} }
} }
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();
...@@ -40,19 +40,19 @@ const $Date = global.Date; ...@@ -40,19 +40,19 @@ const $Date = global.Date;
// ECMA 262 - 15.9.1.2 // ECMA 262 - 15.9.1.2
function Day(time) { function Day(time) {
return $floor(time/msPerDay); return $floor(time/msPerDay);
}; }
// ECMA 262 - 5.2 // ECMA 262 - 5.2
function Modulo(value, remainder) { function Modulo(value, remainder) {
var mod = value % remainder; var mod = value % remainder;
return mod >= 0 ? mod : mod + remainder; return mod >= 0 ? mod : mod + remainder;
}; }
function TimeWithinDay(time) { function TimeWithinDay(time) {
return Modulo(time, msPerDay); return Modulo(time, msPerDay);
}; }
// ECMA 262 - 15.9.1.3 // ECMA 262 - 15.9.1.3
...@@ -60,7 +60,7 @@ function DaysInYear(year) { ...@@ -60,7 +60,7 @@ function DaysInYear(year) {
if (year % 4 != 0) return 365; if (year % 4 != 0) return 365;
if ((year % 100 == 0) && (year % 400 != 0)) return 365; if ((year % 100 == 0) && (year % 400 != 0)) return 365;
return 366; return 366;
}; }
function DayFromYear(year) { function DayFromYear(year) {
...@@ -68,39 +68,39 @@ function DayFromYear(year) { ...@@ -68,39 +68,39 @@ function DayFromYear(year) {
+ $floor((year-1969)/4) + $floor((year-1969)/4)
- $floor((year-1901)/100) - $floor((year-1901)/100)
+ $floor((year-1601)/400); + $floor((year-1601)/400);
}; }
function TimeFromYear(year) { function TimeFromYear(year) {
return msPerDay * DayFromYear(year); return msPerDay * DayFromYear(year);
}; }
function YearFromTime(time) { function YearFromTime(time) {
return FromJulianDay(Day(time) + kDayZeroInJulianDay).year; return FromJulianDay(Day(time) + kDayZeroInJulianDay).year;
}; }
function InLeapYear(time) { function InLeapYear(time) {
return DaysInYear(YearFromTime(time)) == 366 ? 1 : 0; return DaysInYear(YearFromTime(time)) == 366 ? 1 : 0;
}; }
// ECMA 262 - 15.9.1.4 // ECMA 262 - 15.9.1.4
function MonthFromTime(time) { function MonthFromTime(time) {
return FromJulianDay(Day(time) + kDayZeroInJulianDay).month; return FromJulianDay(Day(time) + kDayZeroInJulianDay).month;
}; }
function DayWithinYear(time) { function DayWithinYear(time) {
return Day(time) - DayFromYear(YearFromTime(time)); return Day(time) - DayFromYear(YearFromTime(time));
}; }
// ECMA 262 - 15.9.1.5 // ECMA 262 - 15.9.1.5
function DateFromTime(time) { function DateFromTime(time) {
return FromJulianDay(Day(time) + kDayZeroInJulianDay).date; return FromJulianDay(Day(time) + kDayZeroInJulianDay).date;
}; }
// ECMA 262 - 15.9.1.9 // ECMA 262 - 15.9.1.9
...@@ -110,7 +110,7 @@ function EquivalentYear(year) { ...@@ -110,7 +110,7 @@ function EquivalentYear(year) {
// - week day of first day. // - week day of first day.
var time = TimeFromYear(year); var time = TimeFromYear(year);
return (InLeapYear(time) == 0 ? 1967 : 1956) + (WeekDay(time) * 12) % 28; return (InLeapYear(time) == 0 ? 1967 : 1956) + (WeekDay(time) * 12) % 28;
}; }
function EquivalentTime(t) { function EquivalentTime(t) {
...@@ -125,7 +125,7 @@ function EquivalentTime(t) { ...@@ -125,7 +125,7 @@ function EquivalentTime(t) {
if (t >= -2.1e12 && t <= 2.1e12) return t; if (t >= -2.1e12 && t <= 2.1e12) return t;
var day = MakeDay(EquivalentYear(YearFromTime(t)), MonthFromTime(t), DateFromTime(t)); var day = MakeDay(EquivalentYear(YearFromTime(t)), MonthFromTime(t), DateFromTime(t));
return TimeClip(MakeDate(day, TimeWithinDay(t))); return TimeClip(MakeDate(day, TimeWithinDay(t)));
}; }
var local_time_offset; var local_time_offset;
...@@ -135,7 +135,7 @@ function LocalTimeOffset() { ...@@ -135,7 +135,7 @@ function LocalTimeOffset() {
local_time_offset = %DateLocalTimeOffset(); local_time_offset = %DateLocalTimeOffset();
} }
return local_time_offset; return local_time_offset;
}; }
var daylight_cache_time = $NaN; var daylight_cache_time = $NaN;
...@@ -149,7 +149,7 @@ function DaylightSavingsOffset(t) { ...@@ -149,7 +149,7 @@ function DaylightSavingsOffset(t) {
daylight_cache_time = t; daylight_cache_time = t;
daylight_cache_offset = offset; daylight_cache_offset = offset;
return offset; return offset;
}; }
var timezone_cache_time = $NaN; var timezone_cache_time = $NaN;
...@@ -163,46 +163,46 @@ function LocalTimezone(t) { ...@@ -163,46 +163,46 @@ function LocalTimezone(t) {
timezone_cache_time = t; timezone_cache_time = t;
timezone_cache_timezone = timezone; timezone_cache_timezone = timezone;
return timezone; return timezone;
}; }
function WeekDay(time) { function WeekDay(time) {
return Modulo(Day(time) + 4, 7); return Modulo(Day(time) + 4, 7);
}; }
function LocalTime(time) { function LocalTime(time) {
if ($isNaN(time)) return time; if ($isNaN(time)) return time;
return time + LocalTimeOffset() + DaylightSavingsOffset(time); return time + LocalTimeOffset() + DaylightSavingsOffset(time);
}; }
function UTC(time) { function UTC(time) {
if ($isNaN(time)) return time; if ($isNaN(time)) return time;
var tmp = time - LocalTimeOffset(); var tmp = time - LocalTimeOffset();
return tmp - DaylightSavingsOffset(tmp); return tmp - DaylightSavingsOffset(tmp);
}; }
// ECMA 262 - 15.9.1.10 // ECMA 262 - 15.9.1.10
function HourFromTime(time) { function HourFromTime(time) {
return Modulo($floor(time / msPerHour), HoursPerDay); return Modulo($floor(time / msPerHour), HoursPerDay);
}; }
function MinFromTime(time) { function MinFromTime(time) {
return Modulo($floor(time / msPerMinute), MinutesPerHour); return Modulo($floor(time / msPerMinute), MinutesPerHour);
}; }
function SecFromTime(time) { function SecFromTime(time) {
return Modulo($floor(time / msPerSecond), SecondsPerMinute); return Modulo($floor(time / msPerSecond), SecondsPerMinute);
}; }
function msFromTime(time) { function msFromTime(time) {
return Modulo(time, msPerSecond); return Modulo(time, msPerSecond);
}; }
// ECMA 262 - 15.9.1.11 // ECMA 262 - 15.9.1.11
...@@ -215,13 +215,13 @@ function MakeTime(hour, min, sec, ms) { ...@@ -215,13 +215,13 @@ function MakeTime(hour, min, sec, ms) {
+ TO_INTEGER(min) * msPerMinute + TO_INTEGER(min) * msPerMinute
+ TO_INTEGER(sec) * msPerSecond + TO_INTEGER(sec) * msPerSecond
+ TO_INTEGER(ms); + TO_INTEGER(ms);
}; }
// ECMA 262 - 15.9.1.12 // ECMA 262 - 15.9.1.12
function TimeInYear(year) { function TimeInYear(year) {
return DaysInYear(year) * msPerDay; return DaysInYear(year) * msPerDay;
}; }
// Compute modified Julian day from year, month, date. // Compute modified Julian day from year, month, date.
...@@ -231,7 +231,7 @@ function ToJulianDay(year, month, date) { ...@@ -231,7 +231,7 @@ function ToJulianDay(year, month, date) {
var jm = (month > 1) ? month + 2 : month + 14; var jm = (month > 1) ? month + 2 : month + 14;
var ja = $floor(0.01*jy); var ja = $floor(0.01*jy);
return $floor($floor(365.25*jy) + $floor(30.6001*jm) + date + 1720995) + 2 - ja + $floor(0.25*ja); return $floor($floor(365.25*jy) + $floor(30.6001*jm) + date + 1720995) + 2 - ja + $floor(0.25*ja);
}; }
var four_year_cycle_table; var four_year_cycle_table;
...@@ -264,7 +264,7 @@ function CalculateDateTable() { ...@@ -264,7 +264,7 @@ function CalculateDateTable() {
} }
} }
return four_year_cycle_table; return four_year_cycle_table;
}; }
...@@ -276,6 +276,7 @@ function DayTriplet(year, month, date) { ...@@ -276,6 +276,7 @@ function DayTriplet(year, month, date) {
this.date = date; this.date = date;
} }
// Compute year, month, and day from modified Julian day. // Compute year, month, and day from modified Julian day.
// The missing days in 1582 are ignored for JavaScript compatibility. // The missing days in 1582 are ignored for JavaScript compatibility.
function FromJulianDay(julian) { function FromJulianDay(julian) {
...@@ -308,7 +309,7 @@ function FromJulianDay(julian) { ...@@ -308,7 +309,7 @@ function FromJulianDay(julian) {
if (m > 2) { --y; --m; } if (m > 2) { --y; --m; }
var d = jb - jd - $floor(30.6001 * je); var d = jb - jd - $floor(30.6001 * je);
return new DayTriplet(y, m, d); return new DayTriplet(y, m, d);
}; }
// Compute number of days given a year, month, date. // Compute number of days given a year, month, date.
// Note that month and date can lie outside the normal range. // Note that month and date can lie outside the normal range.
...@@ -333,7 +334,7 @@ function MakeDay(year, month, date) { ...@@ -333,7 +334,7 @@ function MakeDay(year, month, date) {
// Return days relative to Jan 1 1970. // Return days relative to Jan 1 1970.
return ToJulianDay(year, month, date) - kDayZeroInJulianDay; return ToJulianDay(year, month, date) - kDayZeroInJulianDay;
}; }
// ECMA 262 - 15.9.1.13 // ECMA 262 - 15.9.1.13
...@@ -341,7 +342,7 @@ function MakeDate(day, time) { ...@@ -341,7 +342,7 @@ function MakeDate(day, time) {
if (!$isFinite(day)) return $NaN; if (!$isFinite(day)) return $NaN;
if (!$isFinite(time)) return $NaN; if (!$isFinite(time)) return $NaN;
return day * msPerDay + time; return day * msPerDay + time;
}; }
// ECMA 262 - 15.9.1.14 // ECMA 262 - 15.9.1.14
...@@ -349,7 +350,7 @@ function TimeClip(time) { ...@@ -349,7 +350,7 @@ function TimeClip(time) {
if (!$isFinite(time)) return $NaN; if (!$isFinite(time)) return $NaN;
if ($abs(time) > 8.64E15) return $NaN; if ($abs(time) > 8.64E15) return $NaN;
return TO_INTEGER(time); return TO_INTEGER(time);
}; }
%SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) {
...@@ -399,105 +400,105 @@ function TimeClip(time) { ...@@ -399,105 +400,105 @@ function TimeClip(time) {
function GetTimeFrom(aDate) { function GetTimeFrom(aDate) {
if (IS_DATE(aDate)) return %_ValueOf(aDate); if (IS_DATE(aDate)) return %_ValueOf(aDate);
throw new $TypeError('this is not a Date object.'); throw new $TypeError('this is not a Date object.');
}; }
function GetMillisecondsFrom(aDate) { function GetMillisecondsFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return msFromTime(LocalTime(t)); return msFromTime(LocalTime(t));
}; }
function GetUTCMillisecondsFrom(aDate) { function GetUTCMillisecondsFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return msFromTime(t); return msFromTime(t);
}; }
function GetSecondsFrom(aDate) { function GetSecondsFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return SecFromTime(LocalTime(t)); return SecFromTime(LocalTime(t));
}; }
function GetUTCSecondsFrom(aDate) { function GetUTCSecondsFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return SecFromTime(t); return SecFromTime(t);
}; }
function GetMinutesFrom(aDate) { function GetMinutesFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return MinFromTime(LocalTime(t)); return MinFromTime(LocalTime(t));
}; }
function GetUTCMinutesFrom(aDate) { function GetUTCMinutesFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return MinFromTime(t); return MinFromTime(t);
}; }
function GetHoursFrom(aDate) { function GetHoursFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return HourFromTime(LocalTime(t)); return HourFromTime(LocalTime(t));
}; }
function GetUTCHoursFrom(aDate) { function GetUTCHoursFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return HourFromTime(t); return HourFromTime(t);
}; }
function GetFullYearFrom(aDate) { function GetFullYearFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return YearFromTime(LocalTime(t)); return YearFromTime(LocalTime(t));
}; }
function GetUTCFullYearFrom(aDate) { function GetUTCFullYearFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return YearFromTime(t); return YearFromTime(t);
}; }
function GetMonthFrom(aDate) { function GetMonthFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return MonthFromTime(LocalTime(t)); return MonthFromTime(LocalTime(t));
}; }
function GetUTCMonthFrom(aDate) { function GetUTCMonthFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return MonthFromTime(t); return MonthFromTime(t);
}; }
function GetDateFrom(aDate) { function GetDateFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return DateFromTime(LocalTime(t)); return DateFromTime(LocalTime(t));
}; }
function GetUTCDateFrom(aDate) { function GetUTCDateFrom(aDate) {
var t = GetTimeFrom(aDate); var t = GetTimeFrom(aDate);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return DateFromTime(t); return DateFromTime(t);
}; }
%FunctionSetPrototype($Date, new $Date($NaN)); %FunctionSetPrototype($Date, new $Date($NaN));
...@@ -509,7 +510,7 @@ var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc ...@@ -509,7 +510,7 @@ var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc
function TwoDigitString(value) { function TwoDigitString(value) {
return value < 10 ? "0" + value : "" + value; return value < 10 ? "0" + value : "" + value;
}; }
function DateString(time) { function DateString(time) {
...@@ -518,14 +519,14 @@ function DateString(time) { ...@@ -518,14 +519,14 @@ function DateString(time) {
+ Months[YMD.month] + ' ' + Months[YMD.month] + ' '
+ TwoDigitString(YMD.date) + ' ' + TwoDigitString(YMD.date) + ' '
+ YMD.year; + YMD.year;
}; }
function TimeString(time) { function TimeString(time) {
return TwoDigitString(HourFromTime(time)) + ':' return TwoDigitString(HourFromTime(time)) + ':'
+ TwoDigitString(MinFromTime(time)) + ':' + TwoDigitString(MinFromTime(time)) + ':'
+ TwoDigitString(SecFromTime(time)); + TwoDigitString(SecFromTime(time));
}; }
function LocalTimezoneString(time) { function LocalTimezoneString(time) {
...@@ -535,12 +536,12 @@ function LocalTimezoneString(time) { ...@@ -535,12 +536,12 @@ function LocalTimezoneString(time) {
var min = $floor((sign * timezoneOffset)%60); var min = $floor((sign * timezoneOffset)%60);
var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + TwoDigitString(hours) + TwoDigitString(min); var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + TwoDigitString(hours) + TwoDigitString(min);
return gmt + ' (' + LocalTimezone(time) + ')'; return gmt + ' (' + LocalTimezone(time) + ')';
}; }
function DatePrintString(time) { function DatePrintString(time) {
return DateString(time) + ' ' + TimeString(time); return DateString(time) + ' ' + TimeString(time);
}; }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -553,13 +554,13 @@ function DateParse(string) { ...@@ -553,13 +554,13 @@ function DateParse(string) {
var day = MakeDay(arr[0], arr[1], arr[2]); var day = MakeDay(arr[0], arr[1], arr[2]);
var time = MakeTime(arr[3], arr[4], arr[5], 0); var time = MakeTime(arr[3], arr[4], arr[5], 0);
var date = MakeDate(day, time); var date = MakeDate(day, time);
if (IS_NULL(arr[6])) { if (IS_NULL(arr[6])) {
return TimeClip(UTC(date)); return TimeClip(UTC(date));
} else { } else {
return TimeClip(date - arr[6] * 1000); return TimeClip(date - arr[6] * 1000);
} }
}; }
// ECMA 262 - 15.9.4.3 // ECMA 262 - 15.9.4.3
...@@ -577,14 +578,14 @@ function DateUTC(year, month, date, hours, minutes, seconds, ms) { ...@@ -577,14 +578,14 @@ function DateUTC(year, month, date, hours, minutes, seconds, ms) {
var day = MakeDay(year, month, date); var day = MakeDay(year, month, date);
var time = MakeTime(hours, minutes, seconds, ms); var time = MakeTime(hours, minutes, seconds, ms);
return %_SetValueOf(this, TimeClip(MakeDate(day, time))); return %_SetValueOf(this, TimeClip(MakeDate(day, time)));
}; }
// Mozilla-specific extension. Returns the number of milliseconds // Mozilla-specific extension. Returns the number of milliseconds
// elapsed since 1 January 1970 00:00:00 UTC. // elapsed since 1 January 1970 00:00:00 UTC.
function DateNow() { function DateNow() {
return %DateCurrentTime(); return %DateCurrentTime();
}; }
// ECMA 262 - 15.9.5.2 // ECMA 262 - 15.9.5.2
...@@ -592,7 +593,7 @@ function DateToString() { ...@@ -592,7 +593,7 @@ function DateToString() {
var t = GetTimeFrom(this); var t = GetTimeFrom(this);
if ($isNaN(t)) return kInvalidDate; if ($isNaN(t)) return kInvalidDate;
return DatePrintString(LocalTime(t)) + LocalTimezoneString(t); return DatePrintString(LocalTime(t)) + LocalTimezoneString(t);
}; }
// ECMA 262 - 15.9.5.3 // ECMA 262 - 15.9.5.3
...@@ -600,7 +601,7 @@ function DateToDateString() { ...@@ -600,7 +601,7 @@ function DateToDateString() {
var t = GetTimeFrom(this); var t = GetTimeFrom(this);
if ($isNaN(t)) return kInvalidDate; if ($isNaN(t)) return kInvalidDate;
return DateString(LocalTime(t)); return DateString(LocalTime(t));
}; }
// ECMA 262 - 15.9.5.4 // ECMA 262 - 15.9.5.4
...@@ -609,7 +610,19 @@ function DateToTimeString() { ...@@ -609,7 +610,19 @@ function DateToTimeString() {
if ($isNaN(t)) return kInvalidDate; if ($isNaN(t)) return kInvalidDate;
var lt = LocalTime(t); var lt = LocalTime(t);
return TimeString(lt) + LocalTimezoneString(lt); return TimeString(lt) + LocalTimezoneString(lt);
}; }
// ECMA 262 - 15.9.5.5
function DateToLocaleString() {
return DateToString.call(this);
}
// ECMA 262 - 15.9.5.6
function DateToLocaleDateString() {
return DateToDateString.call(this);
}
// ECMA 262 - 15.9.5.7 // ECMA 262 - 15.9.5.7
...@@ -618,7 +631,13 @@ function DateToLocaleTimeString() { ...@@ -618,7 +631,13 @@ function DateToLocaleTimeString() {
if ($isNaN(t)) return kInvalidDate; if ($isNaN(t)) return kInvalidDate;
var lt = LocalTime(t); var lt = LocalTime(t);
return TimeString(lt); return TimeString(lt);
}; }
// ECMA 262 - 15.9.5.8
function DateValueOf() {
return GetTimeFrom(this);
}
// ECMA 262 - 15.9.5.9 // ECMA 262 - 15.9.5.9
...@@ -630,37 +649,37 @@ function DateGetTime() { ...@@ -630,37 +649,37 @@ function DateGetTime() {
// ECMA 262 - 15.9.5.10 // ECMA 262 - 15.9.5.10
function DateGetFullYear() { function DateGetFullYear() {
return GetFullYearFrom(this) return GetFullYearFrom(this)
}; }
// ECMA 262 - 15.9.5.11 // ECMA 262 - 15.9.5.11
function DateGetUTCFullYear() { function DateGetUTCFullYear() {
return GetUTCFullYearFrom(this) return GetUTCFullYearFrom(this)
}; }
// ECMA 262 - 15.9.5.12 // ECMA 262 - 15.9.5.12
function DateGetMonth() { function DateGetMonth() {
return GetMonthFrom(this); return GetMonthFrom(this);
}; }
// ECMA 262 - 15.9.5.13 // ECMA 262 - 15.9.5.13
function DateGetUTCMonth() { function DateGetUTCMonth() {
return GetUTCMonthFrom(this); return GetUTCMonthFrom(this);
}; }
// ECMA 262 - 15.9.5.14 // ECMA 262 - 15.9.5.14
function DateGetDate() { function DateGetDate() {
return GetDateFrom(this); return GetDateFrom(this);
}; }
// ECMA 262 - 15.9.5.15 // ECMA 262 - 15.9.5.15
function DateGetUTCDate() { function DateGetUTCDate() {
return GetUTCDateFrom(this); return GetUTCDateFrom(this);
}; }
// ECMA 262 - 15.9.5.16 // ECMA 262 - 15.9.5.16
...@@ -668,7 +687,7 @@ function DateGetDay() { ...@@ -668,7 +687,7 @@ function DateGetDay() {
var t = GetTimeFrom(this); var t = GetTimeFrom(this);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return WeekDay(LocalTime(t)); return WeekDay(LocalTime(t));
}; }
// ECMA 262 - 15.9.5.17 // ECMA 262 - 15.9.5.17
...@@ -676,55 +695,55 @@ function DateGetUTCDay() { ...@@ -676,55 +695,55 @@ function DateGetUTCDay() {
var t = GetTimeFrom(this); var t = GetTimeFrom(this);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return WeekDay(t); return WeekDay(t);
}; }
// ECMA 262 - 15.9.5.18 // ECMA 262 - 15.9.5.18
function DateGetHours() { function DateGetHours() {
return GetHoursFrom(this); return GetHoursFrom(this);
}; }
// ECMA 262 - 15.9.5.19 // ECMA 262 - 15.9.5.19
function DateGetUTCHours() { function DateGetUTCHours() {
return GetUTCHoursFrom(this); return GetUTCHoursFrom(this);
}; }
// ECMA 262 - 15.9.5.20 // ECMA 262 - 15.9.5.20
function DateGetMinutes() { function DateGetMinutes() {
return GetMinutesFrom(this); return GetMinutesFrom(this);
}; }
// ECMA 262 - 15.9.5.21 // ECMA 262 - 15.9.5.21
function DateGetUTCMinutes() { function DateGetUTCMinutes() {
return GetUTCMinutesFrom(this); return GetUTCMinutesFrom(this);
}; }
// ECMA 262 - 15.9.5.22 // ECMA 262 - 15.9.5.22
function DateGetSeconds() { function DateGetSeconds() {
return GetSecondsFrom(this); return GetSecondsFrom(this);
}; }
// ECMA 262 - 15.9.5.23 // ECMA 262 - 15.9.5.23
function DateGetUTCSeconds() { function DateGetUTCSeconds() {
return GetUTCSecondsFrom(this); return GetUTCSecondsFrom(this);
}; }
// ECMA 262 - 15.9.5.24 // ECMA 262 - 15.9.5.24
function DateGetMilliseconds() { function DateGetMilliseconds() {
return GetMillisecondsFrom(this); return GetMillisecondsFrom(this);
}; }
// ECMA 262 - 15.9.5.25 // ECMA 262 - 15.9.5.25
function DateGetUTCMilliseconds() { function DateGetUTCMilliseconds() {
return GetUTCMillisecondsFrom(this); return GetUTCMillisecondsFrom(this);
}; }
// ECMA 262 - 15.9.5.26 // ECMA 262 - 15.9.5.26
...@@ -732,14 +751,14 @@ function DateGetTimezoneOffset() { ...@@ -732,14 +751,14 @@ function DateGetTimezoneOffset() {
var t = GetTimeFrom(this); var t = GetTimeFrom(this);
if ($isNaN(t)) return t; if ($isNaN(t)) return t;
return (t - LocalTime(t)) / msPerMinute; return (t - LocalTime(t)) / msPerMinute;
}; }
// ECMA 262 - 15.9.5.27 // ECMA 262 - 15.9.5.27
function DateSetTime(ms) { function DateSetTime(ms) {
if (!IS_DATE(this)) throw new $TypeError('this is not a Date object.'); if (!IS_DATE(this)) throw new $TypeError('this is not a Date object.');
return %_SetValueOf(this, TimeClip(ToNumber(ms))); return %_SetValueOf(this, TimeClip(ToNumber(ms)));
}; }
// ECMA 262 - 15.9.5.28 // ECMA 262 - 15.9.5.28
...@@ -748,7 +767,7 @@ function DateSetMilliseconds(ms) { ...@@ -748,7 +767,7 @@ function DateSetMilliseconds(ms) {
ms = ToNumber(ms); ms = ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms); var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
}; }
// ECMA 262 - 15.9.5.29 // ECMA 262 - 15.9.5.29
...@@ -757,7 +776,7 @@ function DateSetUTCMilliseconds(ms) { ...@@ -757,7 +776,7 @@ function DateSetUTCMilliseconds(ms) {
ms = ToNumber(ms); ms = ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms); var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms);
return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
}; }
// ECMA 262 - 15.9.5.30 // ECMA 262 - 15.9.5.30
...@@ -767,7 +786,7 @@ function DateSetSeconds(sec, ms) { ...@@ -767,7 +786,7 @@ function DateSetSeconds(sec, ms) {
ms = %_ArgumentsLength() < 2 ? GetMillisecondsFrom(this) : ToNumber(ms); ms = %_ArgumentsLength() < 2 ? GetMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms); var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
}; }
// ECMA 262 - 15.9.5.31 // ECMA 262 - 15.9.5.31
...@@ -777,7 +796,7 @@ function DateSetUTCSeconds(sec, ms) { ...@@ -777,7 +796,7 @@ function DateSetUTCSeconds(sec, ms) {
ms = %_ArgumentsLength() < 2 ? GetUTCMillisecondsFrom(this) : ToNumber(ms); ms = %_ArgumentsLength() < 2 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms); var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms);
return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
}; }
// ECMA 262 - 15.9.5.33 // ECMA 262 - 15.9.5.33
...@@ -789,7 +808,7 @@ function DateSetMinutes(min, sec, ms) { ...@@ -789,7 +808,7 @@ function DateSetMinutes(min, sec, ms) {
ms = argc < 3 ? GetMillisecondsFrom(this) : ToNumber(ms); ms = argc < 3 ? GetMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(HourFromTime(t), min, sec, ms); var time = MakeTime(HourFromTime(t), min, sec, ms);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
}; }
// ECMA 262 - 15.9.5.34 // ECMA 262 - 15.9.5.34
...@@ -801,7 +820,7 @@ function DateSetUTCMinutes(min, sec, ms) { ...@@ -801,7 +820,7 @@ function DateSetUTCMinutes(min, sec, ms) {
ms = argc < 3 ? GetUTCMillisecondsFrom(this) : ToNumber(ms); ms = argc < 3 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(HourFromTime(t), min, sec, ms); var time = MakeTime(HourFromTime(t), min, sec, ms);
return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
}; }
// ECMA 262 - 15.9.5.35 // ECMA 262 - 15.9.5.35
...@@ -814,7 +833,7 @@ function DateSetHours(hour, min, sec, ms) { ...@@ -814,7 +833,7 @@ function DateSetHours(hour, min, sec, ms) {
ms = argc < 4 ? GetMillisecondsFrom(this) : ToNumber(ms); ms = argc < 4 ? GetMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(hour, min, sec, ms); var time = MakeTime(hour, min, sec, ms);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
}; }
// ECMA 262 - 15.9.5.34 // ECMA 262 - 15.9.5.34
...@@ -827,7 +846,7 @@ function DateSetUTCHours(hour, min, sec, ms) { ...@@ -827,7 +846,7 @@ function DateSetUTCHours(hour, min, sec, ms) {
ms = argc < 4 ? GetUTCMillisecondsFrom(this) : ToNumber(ms); ms = argc < 4 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(hour, min, sec, ms); var time = MakeTime(hour, min, sec, ms);
return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
}; }
// ECMA 262 - 15.9.5.36 // ECMA 262 - 15.9.5.36
...@@ -836,7 +855,7 @@ function DateSetDate(date) { ...@@ -836,7 +855,7 @@ function DateSetDate(date) {
date = ToNumber(date); date = ToNumber(date);
var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}; }
// ECMA 262 - 15.9.5.37 // ECMA 262 - 15.9.5.37
...@@ -845,7 +864,7 @@ function DateSetUTCDate(date) { ...@@ -845,7 +864,7 @@ function DateSetUTCDate(date) {
date = ToNumber(date); date = ToNumber(date);
var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
}; }
// ECMA 262 - 15.9.5.38 // ECMA 262 - 15.9.5.38
...@@ -855,7 +874,7 @@ function DateSetMonth(month, date) { ...@@ -855,7 +874,7 @@ function DateSetMonth(month, date) {
date = %_ArgumentsLength() < 2 ? GetDateFrom(this) : ToNumber(date); date = %_ArgumentsLength() < 2 ? GetDateFrom(this) : ToNumber(date);
var day = MakeDay(YearFromTime(t), month, date); var day = MakeDay(YearFromTime(t), month, date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}; }
// ECMA 262 - 15.9.5.39 // ECMA 262 - 15.9.5.39
...@@ -865,7 +884,7 @@ function DateSetUTCMonth(month, date) { ...@@ -865,7 +884,7 @@ function DateSetUTCMonth(month, date) {
date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date); date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date);
var day = MakeDay(YearFromTime(t), month, date); var day = MakeDay(YearFromTime(t), month, date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
}; }
// ECMA 262 - 15.9.5.40 // ECMA 262 - 15.9.5.40
...@@ -878,7 +897,7 @@ function DateSetFullYear(year, month, date) { ...@@ -878,7 +897,7 @@ function DateSetFullYear(year, month, date) {
date = argc < 3 ? DateFromTime(t) : ToNumber(date); date = argc < 3 ? DateFromTime(t) : ToNumber(date);
var day = MakeDay(year, month, date); var day = MakeDay(year, month, date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}; }
// ECMA 262 - 15.9.5.41 // ECMA 262 - 15.9.5.41
...@@ -891,7 +910,7 @@ function DateSetUTCFullYear(year, month, date) { ...@@ -891,7 +910,7 @@ function DateSetUTCFullYear(year, month, date) {
date = argc < 3 ? DateFromTime(t) : ToNumber(date); date = argc < 3 ? DateFromTime(t) : ToNumber(date);
var day = MakeDay(year, month, date); var day = MakeDay(year, month, date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
}; }
// ECMA 262 - 15.9.5.42 // ECMA 262 - 15.9.5.42
...@@ -904,7 +923,7 @@ function DateToUTCString() { ...@@ -904,7 +923,7 @@ function DateToUTCString() {
+ Months[MonthFromTime(t)] + ' ' + Months[MonthFromTime(t)] + ' '
+ YearFromTime(t) + ' ' + YearFromTime(t) + ' '
+ TimeString(t) + ' GMT'; + TimeString(t) + ' GMT';
}; }
// ECMA 262 - B.2.4 // ECMA 262 - B.2.4
...@@ -912,7 +931,7 @@ function DateGetYear() { ...@@ -912,7 +931,7 @@ function DateGetYear() {
var t = GetTimeFrom(this); var t = GetTimeFrom(this);
if ($isNaN(t)) return $NaN; if ($isNaN(t)) return $NaN;
return YearFromTime(LocalTime(t)) - 1900; return YearFromTime(LocalTime(t)) - 1900;
}; }
// ECMA 262 - B.2.5 // ECMA 262 - B.2.5
...@@ -925,67 +944,82 @@ function DateSetYear(year) { ...@@ -925,67 +944,82 @@ function DateSetYear(year) {
? 1900 + TO_INTEGER(year) : year; ? 1900 + TO_INTEGER(year) : year;
var day = MakeDay(year, GetMonthFrom(this), GetDateFrom(this)); var day = MakeDay(year, GetMonthFrom(this), GetDateFrom(this));
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}; }
// ECMA 262 - B.2.6
//
// Notice that this does not follow ECMA 262 completely. ECMA 262
// says that toGMTString should be the same Function object as
// toUTCString. JSC does not do this, so for compatibility we do not
// do that either. Instead, we create a new function whose name
// property will return toGMTString.
function DateToGMTString() {
return DateToUTCString.call(this);
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SetupDate() { function SetupDate() {
// Setup non-enumerable properties of the Date object itself. // Setup non-enumerable properties of the Date object itself.
InstallProperties($Date, DONT_ENUM, { InstallFunctions($Date, DONT_ENUM, $Array(
UTC: DateUTC, "UTC", DateUTC,
parse: DateParse, "parse", DateParse,
now: DateNow "now", DateNow
}); ));
// Setup non-enumerable properties of the Date prototype object. // Setup non-enumerable constructor property of the Date prototype object.
InstallProperties($Date.prototype, DONT_ENUM, { %AddProperty($Date.prototype, "constructor", $Date, DONT_ENUM);
constructor: $Date,
toString: DateToString, // Setup non-enumerable functions of the Date prototype object and
toDateString: DateToDateString, // set their names.
toTimeString: DateToTimeString, InstallFunctions($Date.prototype, DONT_ENUM, $Array(
toLocaleString: DateToString, "toString", DateToString,
toLocaleDateString: DateToDateString, "toDateString", DateToDateString,
toLocaleTimeString: DateToLocaleTimeString, "toTimeString", DateToTimeString,
valueOf: DateGetTime, "toLocaleString", DateToLocaleString,
getTime: DateGetTime, "toLocaleDateString", DateToLocaleDateString,
getFullYear: DateGetFullYear, "toLocaleTimeString", DateToLocaleTimeString,
getUTCFullYear: DateGetUTCFullYear, "valueOf", DateValueOf,
getMonth: DateGetMonth, "getTime", DateGetTime,
getUTCMonth: DateGetUTCMonth, "getFullYear", DateGetFullYear,
getDate: DateGetDate, "getUTCFullYear", DateGetUTCFullYear,
getUTCDate: DateGetUTCDate, "getMonth", DateGetMonth,
getDay: DateGetDay, "getUTCMonth", DateGetUTCMonth,
getUTCDay: DateGetUTCDay, "getDate", DateGetDate,
getHours: DateGetHours, "getUTCDate", DateGetUTCDate,
getUTCHours: DateGetUTCHours, "getDay", DateGetDay,
getMinutes: DateGetMinutes, "getUTCDay", DateGetUTCDay,
getUTCMinutes: DateGetUTCMinutes, "getHours", DateGetHours,
getSeconds: DateGetSeconds, "getUTCHours", DateGetUTCHours,
getUTCSeconds: DateGetUTCSeconds, "getMinutes", DateGetMinutes,
getMilliseconds: DateGetMilliseconds, "getUTCMinutes", DateGetUTCMinutes,
getUTCMilliseconds: DateGetUTCMilliseconds, "getSeconds", DateGetSeconds,
getTimezoneOffset: DateGetTimezoneOffset, "getUTCSeconds", DateGetUTCSeconds,
setTime: DateSetTime, "getMilliseconds", DateGetMilliseconds,
setMilliseconds: DateSetMilliseconds, "getUTCMilliseconds", DateGetUTCMilliseconds,
setUTCMilliseconds: DateSetUTCMilliseconds, "getTimezoneOffset", DateGetTimezoneOffset,
setSeconds: DateSetSeconds, "setTime", DateSetTime,
setUTCSeconds: DateSetUTCSeconds, "setMilliseconds", DateSetMilliseconds,
setMinutes: DateSetMinutes, "setUTCMilliseconds", DateSetUTCMilliseconds,
setUTCMinutes: DateSetUTCMinutes, "setSeconds", DateSetSeconds,
setHours: DateSetHours, "setUTCSeconds", DateSetUTCSeconds,
setUTCHours: DateSetUTCHours, "setMinutes", DateSetMinutes,
setDate: DateSetDate, "setUTCMinutes", DateSetUTCMinutes,
setUTCDate: DateSetUTCDate, "setHours", DateSetHours,
setMonth: DateSetMonth, "setUTCHours", DateSetUTCHours,
setUTCMonth: DateSetUTCMonth, "setDate", DateSetDate,
setFullYear: DateSetFullYear, "setUTCDate", DateSetUTCDate,
setUTCFullYear: DateSetUTCFullYear, "setMonth", DateSetMonth,
toUTCString: DateToUTCString, "setUTCMonth", DateSetUTCMonth,
toGMTString: DateToUTCString, "setFullYear", DateSetFullYear,
getYear: DateGetYear, "setUTCFullYear", DateSetUTCFullYear,
setYear: DateSetYear "toGMTString", DateToGMTString,
}); "toUTCString", DateToUTCString,
}; "getYear", DateGetYear,
"setYear", DateSetYear
));
}
SetupDate(); SetupDate();
...@@ -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);
...@@ -558,14 +558,14 @@ ObjectMirror.prototype.propertyNames = function(kind, limit) { ...@@ -558,14 +558,14 @@ ObjectMirror.prototype.propertyNames = function(kind, limit) {
var names = new Array(limit); var names = new Array(limit);
var index = 0; var index = 0;
// Copy names for named properties. // Copy names for named properties.
if (kind & PropertyKind.Named) { if (kind & PropertyKind.Named) {
for (var i = 0; index < limit && i < propertyNames.length; i++) { for (var i = 0; index < limit && i < propertyNames.length; i++) {
names[index++] = propertyNames[i]; names[index++] = propertyNames[i];
} }
} }
// Copy names for indexed properties. // Copy names for indexed properties.
if (kind & PropertyKind.Indexed) { if (kind & PropertyKind.Indexed) {
for (var i = 0; index < limit && i < elementNames.length; i++) { for (var i = 0; index < limit && i < elementNames.length; i++) {
...@@ -614,7 +614,7 @@ ObjectMirror.prototype.interceptorPropertyNames = function(kind, limit) { ...@@ -614,7 +614,7 @@ ObjectMirror.prototype.interceptorPropertyNames = function(kind, limit) {
if (this.hasNamedInterceptor() && kind & PropertyKind.Named) { if (this.hasNamedInterceptor() && kind & PropertyKind.Named) {
namedInterceptorNames = %DebugNamedInterceptorPropertyNames(this.value_); namedInterceptorNames = %DebugNamedInterceptorPropertyNames(this.value_);
} }
// Get names for indexed interceptor properties. // Get names for indexed interceptor properties.
if (this.hasIndexedInterceptor() && kind & PropertyKind.Indexed) { if (this.hasIndexedInterceptor() && kind & PropertyKind.Indexed) {
indexedInterceptorNames = %DebugIndexedInterceptorElementNames(this.value_); indexedInterceptorNames = %DebugIndexedInterceptorElementNames(this.value_);
...@@ -646,7 +646,7 @@ ObjectMirror.prototype.interceptorProperties = function(opt_kind, opt_names) { ...@@ -646,7 +646,7 @@ ObjectMirror.prototype.interceptorProperties = function(opt_kind, opt_names) {
var kind = opt_kind || PropertyKind.Named | PropertyKind.Indexed; var kind = opt_kind || PropertyKind.Named | PropertyKind.Indexed;
var namedInterceptorProperties; var namedInterceptorProperties;
var indexedInterceptorProperties; var indexedInterceptorProperties;
// Get values for named interceptor properties. // Get values for named interceptor properties.
if (kind & PropertyKind.Named) { if (kind & PropertyKind.Named) {
var names = opt_names || this.interceptorPropertyNames(PropertyKind.Named); var names = opt_names || this.interceptorPropertyNames(PropertyKind.Named);
...@@ -656,7 +656,7 @@ ObjectMirror.prototype.interceptorProperties = function(opt_kind, opt_names) { ...@@ -656,7 +656,7 @@ ObjectMirror.prototype.interceptorProperties = function(opt_kind, opt_names) {
namedInterceptorProperties[i] = new InterceptorPropertyMirror(this, names[i], value); namedInterceptorProperties[i] = new InterceptorPropertyMirror(this, names[i], value);
} }
} }
// Get values for indexed interceptor properties. // Get values for indexed interceptor properties.
if (kind & PropertyKind.Indexed) { if (kind & PropertyKind.Indexed) {
var names = opt_names || this.interceptorPropertyNames(PropertyKind.Indexed); var names = opt_names || this.interceptorPropertyNames(PropertyKind.Indexed);
...@@ -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);
...@@ -871,12 +871,12 @@ FunctionMirror.prototype.constructedBy = function(opt_max_instances) { ...@@ -871,12 +871,12 @@ FunctionMirror.prototype.constructedBy = function(opt_max_instances) {
if (this.resolved()) { if (this.resolved()) {
// Find all objects constructed from this function. // Find all objects constructed from this function.
var result = %DebugConstructedBy(this.value_, opt_max_instances || 0); var result = %DebugConstructedBy(this.value_, opt_max_instances || 0);
// Make mirrors for all the instances found. // Make mirrors for all the instances found.
for (var i = 0; i < result.length; i++) { for (var i = 0; i < result.length; i++) {
result[i] = MakeMirror(result[i]); result[i] = MakeMirror(result[i]);
} }
return result; return result;
} else { } else {
return []; return [];
...@@ -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);
...@@ -1641,7 +1641,7 @@ FrameMirror.prototype.invocationText = function() { ...@@ -1641,7 +1641,7 @@ FrameMirror.prototype.invocationText = function() {
// under which it was looked up. // under which it was looked up.
if (func.name() && func.name() != property.name()) { if (func.name() && func.name() != property.name()) {
result += '(aka ' + func.name() + ')'; result += '(aka ' + func.name() + ')';
} }
} else { } else {
// The function invoked was not found on the receiver. Use the function // The function invoked was not found on the receiver. Use the function
// name if available for the backtrace. // name if available for the backtrace.
...@@ -1665,7 +1665,7 @@ FrameMirror.prototype.invocationText = function() { ...@@ -1665,7 +1665,7 @@ FrameMirror.prototype.invocationText = function() {
} }
result += ')'; result += ')';
} }
return result; return result;
} }
...@@ -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);
...@@ -1793,8 +1793,8 @@ ScriptMirror.prototype.fillJSON_ = function(content, details) { ...@@ -1793,8 +1793,8 @@ ScriptMirror.prototype.fillJSON_ = function(content, details) {
content.push(MakeJSONPair_('lineCount', NumberToJSON_(this.lineCount()))); content.push(MakeJSONPair_('lineCount', NumberToJSON_(this.lineCount())));
content.push(MakeJSONPair_('scriptType', NumberToJSON_(this.scriptType()))); content.push(MakeJSONPair_('scriptType', NumberToJSON_(this.scriptType())));
} }
ScriptMirror.prototype.toText = function() { ScriptMirror.prototype.toText = function() {
var result = ''; var result = '';
result += this.name(); result += this.name();
...@@ -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) + '"';
}; }
...@@ -101,7 +101,7 @@ function DoConstructRegExp(object, pattern, flags, isConstructorCall) { ...@@ -101,7 +101,7 @@ function DoConstructRegExp(object, pattern, flags, isConstructorCall) {
// Call internal function to compile the pattern. // Call internal function to compile the pattern.
%RegExpCompile(object, pattern, flags); %RegExpCompile(object, pattern, flags);
}; }
function RegExpConstructor(pattern, flags) { function RegExpConstructor(pattern, flags) {
...@@ -114,7 +114,7 @@ function RegExpConstructor(pattern, flags) { ...@@ -114,7 +114,7 @@ function RegExpConstructor(pattern, flags) {
} }
return new $RegExp(pattern, flags); return new $RegExp(pattern, flags);
} }
}; }
// Deprecated RegExp.prototype.compile method. We behave like the constructor // Deprecated RegExp.prototype.compile method. We behave like the constructor
...@@ -144,25 +144,26 @@ function DoRegExpExec(regexp, string, index) { ...@@ -144,25 +144,26 @@ function DoRegExpExec(regexp, string, index) {
var matchIndices = %RegExpExec(regexp, string, index); var matchIndices = %RegExpExec(regexp, string, index);
if (!IS_NULL(matchIndices)) { if (!IS_NULL(matchIndices)) {
regExpCaptures = matchIndices; regExpCaptures = matchIndices;
regExpSubject = regexp_input = string; regExpSubject = regExpInput = string;
} }
return matchIndices; return matchIndices;
}; }
function DoRegExpExecGlobal(regexp, string) { function DoRegExpExecGlobal(regexp, string) {
// Here, matchIndices is an array of arrays of substring indices. // Here, matchIndices is an array of arrays of substring indices.
var matchIndices = %RegExpExecGlobal(regexp, string); var matchIndices = %RegExpExecGlobal(regexp, string);
if (matchIndices.length != 0) { if (matchIndices.length != 0) {
regExpCaptures = matchIndices[matchIndices.length - 1]; regExpCaptures = matchIndices[matchIndices.length - 1];
regExpSubject = regexp_input = string; regExpSubject = regExpInput = string;
} }
return matchIndices; return matchIndices;
}; }
function RegExpExec(string) { function RegExpExec(string) {
if (%_ArgumentsLength() == 0) { if (%_ArgumentsLength() == 0) {
string = regexp_input; string = regExpInput;
} }
var s = ToString(string); var s = ToString(string);
var length = s.length; var length = s.length;
...@@ -203,13 +204,13 @@ function RegExpExec(string) { ...@@ -203,13 +204,13 @@ function RegExpExec(string) {
result.index = matchIndices[0]; result.index = matchIndices[0];
result.input = s; result.input = s;
return result; return result;
}; }
function RegExpTest(string) { function RegExpTest(string) {
var result = (%_ArgumentsLength() == 0) ? this.exec() : this.exec(string); var result = (%_ArgumentsLength() == 0) ? this.exec() : this.exec(string);
return result != null; return result != null;
}; }
function RegExpToString() { function RegExpToString() {
...@@ -225,7 +226,7 @@ function RegExpToString() { ...@@ -225,7 +226,7 @@ function RegExpToString() {
if (this.multiline) if (this.multiline)
result += 'm'; result += 'm';
return result; return result;
}; }
// Getters for the static properties lastMatch, lastParen, leftContext, and // Getters for the static properties lastMatch, lastParen, leftContext, and
...@@ -234,7 +235,8 @@ function RegExpToString() { ...@@ -234,7 +235,8 @@ function RegExpToString() {
// of the last successful match. // of the last successful match.
function RegExpGetLastMatch() { function RegExpGetLastMatch() {
return regExpSubject.slice(regExpCaptures[0], regExpCaptures[1]); return regExpSubject.slice(regExpCaptures[0], regExpCaptures[1]);
}; }
function RegExpGetLastParen() { function RegExpGetLastParen() {
var length = regExpCaptures.length; var length = regExpCaptures.length;
...@@ -244,15 +246,17 @@ function RegExpGetLastParen() { ...@@ -244,15 +246,17 @@ function RegExpGetLastParen() {
// it is empty. // it is empty.
return regExpSubject.slice(regExpCaptures[length - 2], return regExpSubject.slice(regExpCaptures[length - 2],
regExpCaptures[length - 1]); regExpCaptures[length - 1]);
}; }
function RegExpGetLeftContext() { function RegExpGetLeftContext() {
return regExpSubject.slice(0, regExpCaptures[0]); return regExpSubject.slice(0, regExpCaptures[0]);
}; }
function RegExpGetRightContext() { function RegExpGetRightContext() {
return regExpSubject.slice(regExpCaptures[1], regExpSubject.length); return regExpSubject.slice(regExpCaptures[1], regExpSubject.length);
}; }
// The properties $1..$9 are the first nine capturing substrings of the last // The properties $1..$9 are the first nine capturing substrings of the last
...@@ -268,7 +272,7 @@ function RegExpMakeCaptureGetter(n) { ...@@ -268,7 +272,7 @@ function RegExpMakeCaptureGetter(n) {
if (matchStart == -1 || matchEnd == -1) return ''; if (matchStart == -1 || matchEnd == -1) return '';
return regExpSubject.slice(matchStart, matchEnd); return regExpSubject.slice(matchStart, matchEnd);
}; };
}; }
// Properties of the builtins object for recording the result of the last // Properties of the builtins object for recording the result of the last
...@@ -279,50 +283,54 @@ function RegExpMakeCaptureGetter(n) { ...@@ -279,50 +283,54 @@ function RegExpMakeCaptureGetter(n) {
// the last successful match. // the last successful match.
var regExpCaptures = [0, 0]; var regExpCaptures = [0, 0];
var regExpSubject = ''; var regExpSubject = '';
var regExpInput = "";
// -------------------------------------------------------------------
function SetupRegExp() {
%FunctionSetInstanceClassName($RegExp, 'RegExp');
%FunctionSetPrototype($RegExp, new $Object());
%AddProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM);
%SetCode($RegExp, RegExpConstructor);
InstallFunctions($RegExp.prototype, DONT_ENUM, $Array(
"exec", RegExpExec,
"test", RegExpTest,
"toString", RegExpToString,
"compile", CompileRegExp
));
// The spec says nothing about the length of exec and test, but
// SpiderMonkey and KJS have length equal to 0.
%FunctionSetLength($RegExp.prototype.exec, 0);
%FunctionSetLength($RegExp.prototype.test, 0);
// The length of compile is 1 in SpiderMonkey.
%FunctionSetLength($RegExp.prototype.compile, 1);
// The properties input, $input, and $_ are aliases for each other. When this
// value is set in SpiderMonkey, the value it is set to is coerced to a
// string. We mimic that behavior with a slight difference: in SpiderMonkey
// the value of the expression 'RegExp.input = null' (for instance) is the
// string "null" (ie, the value after coercion), while in V8 it is the value
// null (ie, the value before coercion).
// Getter and setter for the input.
function RegExpGetInput() { return regExpInput; }
function RegExpSetInput(string) { regExpInput = ToString(string); }
%DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE);
%DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE);
%DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE);
// The properties multiline and $* are aliases for each other. When this
// value is set in SpiderMonkey, the value it is set to is coerced to a
// boolean. We mimic that behavior with a slight difference: in SpiderMonkey
// the value of the expression 'RegExp.multiline = null' (for instance) is the
// boolean false (ie, the value after coercion), while in V8 it is the value
// null (ie, the value before coercion).
%FunctionSetInstanceClassName($RegExp, 'RegExp');
%FunctionSetPrototype($RegExp, new $Object());
%AddProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM);
%SetCode($RegExp, RegExpConstructor);
%AddProperty($RegExp.prototype, 'exec', RegExpExec, DONT_ENUM);
%AddProperty($RegExp.prototype, 'test', RegExpTest, DONT_ENUM);
%AddProperty($RegExp.prototype, 'toString', RegExpToString, DONT_ENUM);
%AddProperty($RegExp.prototype, 'compile', CompileRegExp, DONT_ENUM);
// The spec says nothing about the length of exec and test, but
// SpiderMonkey and KJS have length equal to 0.
%FunctionSetLength($RegExp.prototype.exec, 0);
%FunctionSetLength($RegExp.prototype.test, 0);
// The length of compile is 1 in SpiderMonkey.
%FunctionSetLength($RegExp.prototype.compile, 1);
// The properties input, $input, and $_ are aliases for each other. When this
// value is set in SpiderMonkey, the value it is set to is coerced to a
// string. We mimic that behavior with a slight difference: in SpiderMonkey
// the value of the expression 'RegExp.input = null' (for instance) is the
// string "null" (ie, the value after coercion), while in V8 it is the value
// null (ie, the value before coercion).
// Getter and setter for the input.
var regexp_input = "";
function RegExpGetInput() { return regexp_input; };
function RegExpSetInput(string) { regexp_input = ToString(string); };
%DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE);
%DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE);
%DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE);
// The properties multiline and $* are aliases for each other. When this
// value is set in SpiderMonkey, the value it is set to is coerced to a
// boolean. We mimic that behavior with a slight difference: in SpiderMonkey
// the value of the expression 'RegExp.multiline = null' (for instance) is the
// boolean false (ie, the value after coercion), while in V8 it is the value
// null (ie, the value before coercion).
(function () {
// Getter and setter for multiline. // Getter and setter for multiline.
var multiline = false; var multiline = false;
function RegExpGetMultiline() { return multiline; }; function RegExpGetMultiline() { return multiline; };
...@@ -332,34 +340,34 @@ function RegExpSetInput(string) { regexp_input = ToString(string); }; ...@@ -332,34 +340,34 @@ function RegExpSetInput(string) { regexp_input = ToString(string); };
%DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, DONT_DELETE); %DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, DONT_DELETE);
%DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, DONT_ENUM | DONT_DELETE);
})();
function NoOpSetter(ignored) {}
function NoOpSetter(ignored) {};
// Static properties set by a successful match.
// Static properties set by a successful match. %DefineAccessor($RegExp, 'lastMatch', GETTER, RegExpGetLastMatch, DONT_DELETE);
%DefineAccessor($RegExp, 'lastMatch', GETTER, RegExpGetLastMatch, DONT_DELETE); %DefineAccessor($RegExp, 'lastMatch', SETTER, NoOpSetter, DONT_DELETE);
%DefineAccessor($RegExp, 'lastMatch', SETTER, NoOpSetter, DONT_DELETE); %DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, '$&', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$&', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, 'lastParen', GETTER, RegExpGetLastParen, DONT_DELETE);
%DefineAccessor($RegExp, 'lastParen', GETTER, RegExpGetLastParen, DONT_DELETE); %DefineAccessor($RegExp, 'lastParen', SETTER, NoOpSetter, DONT_DELETE);
%DefineAccessor($RegExp, 'lastParen', SETTER, NoOpSetter, DONT_DELETE); %DefineAccessor($RegExp, '$+', GETTER, RegExpGetLastParen, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$+', GETTER, RegExpGetLastParen, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, '$+', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$+', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, 'leftContext', GETTER, RegExpGetLeftContext, DONT_DELETE);
%DefineAccessor($RegExp, 'leftContext', GETTER, RegExpGetLeftContext, DONT_DELETE); %DefineAccessor($RegExp, 'leftContext', SETTER, NoOpSetter, DONT_DELETE);
%DefineAccessor($RegExp, 'leftContext', SETTER, NoOpSetter, DONT_DELETE); %DefineAccessor($RegExp, '$`', GETTER, RegExpGetLeftContext, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$`', GETTER, RegExpGetLeftContext, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, '$`', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$`', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, 'rightContext', GETTER, RegExpGetRightContext, DONT_DELETE);
%DefineAccessor($RegExp, 'rightContext', GETTER, RegExpGetRightContext, DONT_DELETE); %DefineAccessor($RegExp, 'rightContext', SETTER, NoOpSetter, DONT_DELETE);
%DefineAccessor($RegExp, 'rightContext', SETTER, NoOpSetter, DONT_DELETE); %DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext, DONT_ENUM | DONT_DELETE); %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
// A local scope to hide the loop index i.
(function() {
for (var i = 1; i < 10; ++i) { for (var i = 1; i < 10; ++i) {
%DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_DELETE); %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_DELETE);
%DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE);
} }
})(); }
SetupRegExp();
...@@ -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());
...@@ -855,7 +857,7 @@ static Object* Runtime_SetCode(Arguments args) { ...@@ -855,7 +857,7 @@ static Object* Runtime_SetCode(Arguments args) {
target->set_code(fun->code()); target->set_code(fun->code());
target->shared()->set_length(fun->shared()->length()); target->shared()->set_length(fun->shared()->length());
target->shared()->set_formal_parameter_count( target->shared()->set_formal_parameter_count(
fun->shared()->formal_parameter_count()); fun->shared()->formal_parameter_count());
// Set the source code of the target function. // Set the source code of the target function.
target->shared()->set_script(fun->shared()->script()); target->shared()->set_script(fun->shared()->script());
target->shared()->set_start_position(fun->shared()->start_position()); target->shared()->set_start_position(fun->shared()->start_position());
......
...@@ -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);
} }
}; }
...@@ -152,7 +152,7 @@ function ADD(x) { ...@@ -152,7 +152,7 @@ function ADD(x) {
if (IS_NUMBER(this) && IS_NUMBER(x)) { if (IS_NUMBER(this) && IS_NUMBER(x)) {
return %NumberAdd(this, x); return %NumberAdd(this, x);
} }
var a = %ToPrimitive(this, NO_HINT); var a = %ToPrimitive(this, NO_HINT);
var b = %ToPrimitive(x, NO_HINT); var b = %ToPrimitive(x, NO_HINT);
...@@ -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,13 +457,13 @@ function ApplyReplacementFunction(replace, captures, subject) { ...@@ -454,13 +457,13 @@ 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);
if (lim === 0) return result; if (lim === 0) return result;
// ECMA-262 says that if separator is undefined, the result should // ECMA-262 says that if separator is undefined, the result should
// be an array of size 1 containing the entire string. SpiderMonkey // be an array of size 1 containing the entire string. SpiderMonkey
// and KJS have this behaviour only when no separator is given. If // and KJS have this behaviour only when no separator is given. If
...@@ -470,33 +473,33 @@ function ApplyReplacementFunction(replace, captures, subject) { ...@@ -470,33 +473,33 @@ function ApplyReplacementFunction(replace, captures, subject) {
result[result.length] = subject; result[result.length] = subject;
return result; return result;
} }
var length = subject.length; var length = subject.length;
var currentIndex = 0; var currentIndex = 0;
var startIndex = 0; var startIndex = 0;
var sep = IS_REGEXP(separator) ? separator : ToString(separator); var sep = IS_REGEXP(separator) ? separator : ToString(separator);
if (length === 0) { if (length === 0) {
if (splitMatch(sep, subject, 0, 0) != null) return result; if (splitMatch(sep, subject, 0, 0) != null) return result;
result[result.length] = subject; result[result.length] = subject;
return result; return result;
} }
while (true) { while (true) {
if (startIndex === length) { if (startIndex === length) {
result[result.length] = subject.slice(currentIndex, length); result[result.length] = subject.slice(currentIndex, length);
return result; return result;
} }
var match = splitMatch(sep, subject, currentIndex, startIndex); var match = splitMatch(sep, subject, currentIndex, startIndex);
if (IS_NULL(match)) { if (IS_NULL(match)) {
result[result.length] = subject.slice(currentIndex, length); result[result.length] = subject.slice(currentIndex, length);
return result; return result;
} }
var endIndex = match[0]; var endIndex = match[0];
// We ignore a zero-length match at the currentIndex. // We ignore a zero-length match at the currentIndex.
...@@ -507,12 +510,12 @@ function ApplyReplacementFunction(replace, captures, subject) { ...@@ -507,12 +510,12 @@ function ApplyReplacementFunction(replace, captures, subject) {
result[result.length] = match[1]; result[result.length] = match[1];
if (result.length === lim) return result; if (result.length === lim) return result;
for (var i = 2; i < match.length; i++) { for (var i = 2; i < match.length; i++) {
result[result.length] = match[i]; result[result.length] = match[i];
if (result.length === lim) return result; if (result.length === lim) return result;
} }
startIndex = currentIndex = endIndex; startIndex = currentIndex = endIndex;
} }
}, DONT_ENUM); }, DONT_ENUM);
...@@ -537,16 +540,16 @@ function splitMatch(separator, subject, current_index, start_index) { ...@@ -537,16 +540,16 @@ function splitMatch(separator, subject, current_index, start_index) {
} }
return result; return result;
} }
var separatorIndex = subject.indexOf(separator, start_index); var separatorIndex = subject.indexOf(separator, start_index);
if (separatorIndex === -1) return null; if (separatorIndex === -1) return null;
return [ separatorIndex + separator.length, subject.slice(current_index, separatorIndex) ]; return [ separatorIndex + separator.length, subject.slice(current_index, separatorIndex) ];
}; };
// 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