Commit c7fccff9 authored by lrn@chromium.org's avatar lrn@chromium.org

Clean up JavaScript files to better follow coding standard.

Multiline conditionals must use braces.
Semicolons are not optional.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10074 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ad356bd5
......@@ -328,8 +328,9 @@ function SimpleSlice(array, start_i, del_count, len, deleted_elements) {
// would be the appropriate test. We follow KJS in consulting the
// prototype.
var current = array[index];
if (!IS_UNDEFINED(current) || index in array)
if (!IS_UNDEFINED(current) || index in array) {
deleted_elements[i] = current;
}
}
}
......@@ -495,12 +496,12 @@ function SparseReverse(array, len) {
if (j_complement <= i) {
high = j;
while (keys[--high_counter] == j);
while (keys[--high_counter] == j) { }
low = j_complement;
}
if (j_complement >= i) {
low = i;
while (keys[++low_counter] == i);
while (keys[++low_counter] == i) { }
high = len - i - 1;
}
......@@ -576,10 +577,11 @@ function ArrayShift() {
var first = this[0];
if (IS_ARRAY(this))
if (IS_ARRAY(this)) {
SmartMove(this, 0, 1, len, 0);
else
} else {
SimpleMove(this, 0, 1, len, 0);
}
this.length = len - 1;
......@@ -596,10 +598,11 @@ function ArrayUnshift(arg1) { // length == 1
var len = TO_UINT32(this.length);
var num_arguments = %_ArgumentsLength();
if (IS_ARRAY(this))
if (IS_ARRAY(this)) {
SmartMove(this, 0, 0, len, num_arguments);
else
} else {
SimpleMove(this, 0, 0, len, num_arguments);
}
for (var i = 0; i < num_arguments; i++) {
this[i] = %_Arguments(i);
......
This diff is collapsed.
......@@ -304,7 +304,7 @@ function YearFromTime(t) {
}
%DateYMDFromTime(t, ymd_from_time_cache);
ymd_from_time_cached_time = t
ymd_from_time_cached_time = t;
}
return ymd_from_time_cache[0];
......@@ -316,7 +316,7 @@ function MonthFromTime(t) {
return $NaN;
}
%DateYMDFromTime(t, ymd_from_time_cache);
ymd_from_time_cached_time = t
ymd_from_time_cached_time = t;
}
return ymd_from_time_cache[1];
......@@ -329,7 +329,7 @@ function DateFromTime(t) {
}
%DateYMDFromTime(t, ymd_from_time_cache);
ymd_from_time_cached_time = t
ymd_from_time_cached_time = t;
}
return ymd_from_time_cache[2];
......@@ -445,8 +445,9 @@ var Date_cache = {
minutes = argc > 4 ? ToNumber(minutes) : 0;
seconds = argc > 5 ? ToNumber(seconds) : 0;
ms = argc > 6 ? ToNumber(ms) : 0;
year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
? 1900 + TO_INTEGER(year) : year;
year = (!NUMBER_IS_NAN(year) &&
0 <= TO_INTEGER(year) &&
TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
var day = MakeDay(year, month, date);
var time = MakeTime(hours, minutes, seconds, ms);
value = TimeClip(UTC(MakeDate(day, time)));
......@@ -459,7 +460,8 @@ var Date_cache = {
var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
function TwoDigitString(value) {
......@@ -475,8 +477,10 @@ function DateString(time) {
}
var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'];
var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
function LongDateString(time) {
......@@ -556,8 +560,9 @@ function DateUTC(year, month, date, hours, minutes, seconds, ms) {
minutes = argc > 4 ? ToNumber(minutes) : 0;
seconds = argc > 5 ? ToNumber(seconds) : 0;
ms = argc > 6 ? ToNumber(ms) : 0;
year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
? 1900 + TO_INTEGER(year) : year;
year = (!NUMBER_IS_NAN(year) &&
0 <= TO_INTEGER(year) &&
TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
var day = MakeDay(year, month, date);
var time = MakeTime(hours, minutes, seconds, ms);
return %_SetValueOf(this, TimeClip(MakeDate(day, time)));
......@@ -777,7 +782,10 @@ function DateSetTime(ms) {
function DateSetMilliseconds(ms) {
var t = LocalTime(DATE_VALUE(this));
ms = ToNumber(ms);
var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), SEC_FROM_TIME(t), ms);
var time = MakeTime(HOUR_FROM_TIME(t),
MIN_FROM_TIME(t),
SEC_FROM_TIME(t),
ms);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time))));
}
......@@ -786,7 +794,10 @@ function DateSetMilliseconds(ms) {
function DateSetUTCMilliseconds(ms) {
var t = DATE_VALUE(this);
ms = ToNumber(ms);
var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), SEC_FROM_TIME(t), ms);
var time = MakeTime(HOUR_FROM_TIME(t),
MIN_FROM_TIME(t),
SEC_FROM_TIME(t),
ms);
return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time)));
}
......
This diff is collapsed.
......@@ -345,4 +345,4 @@ function SetUpJSON() {
));
}
SetUpJSON()
SetUpJSON();
......@@ -325,9 +325,10 @@ Debug.LiveEdit = new function() {
if (old_node.children[i].live_shared_function_infos) {
old_node.children[i].live_shared_function_infos.
forEach(function (old_child_info) {
%LiveEditReplaceRefToNestedFunction(old_info.info,
corresponding_child_info,
old_child_info.info);
%LiveEditReplaceRefToNestedFunction(
old_info.info,
corresponding_child_info,
old_child_info.info);
});
}
}
......@@ -381,7 +382,7 @@ Debug.LiveEdit = new function() {
position: break_point_position,
line: break_point.line(),
column: break_point.column()
}
};
break_point_old_positions.push(old_position_description);
}
......@@ -418,7 +419,7 @@ Debug.LiveEdit = new function() {
position: updated_position,
line: new_location.line,
column: new_location.column
}
};
break_point.set(original_script);
......@@ -428,7 +429,7 @@ Debug.LiveEdit = new function() {
new_positions: new_position_description
} );
}
}
};
}
......@@ -465,7 +466,7 @@ Debug.LiveEdit = new function() {
}
PosTranslator.prototype.GetChunks = function() {
return this.chunks;
}
};
PosTranslator.prototype.Translate = function(pos, inside_chunk_handler) {
var array = this.chunks;
......@@ -492,18 +493,18 @@ Debug.LiveEdit = new function() {
inside_chunk_handler = PosTranslator.DefaultInsideChunkHandler;
}
return inside_chunk_handler(pos, chunk);
}
};
PosTranslator.DefaultInsideChunkHandler = function(pos, diff_chunk) {
Assert(false, "Cannot translate position in changed area");
}
};
PosTranslator.ShiftWithTopInsideChunkHandler =
function(pos, diff_chunk) {
// We carelessly do not check whether we stay inside the chunk after
// translation.
return pos - diff_chunk.pos1 + diff_chunk.pos2;
}
};
var FunctionStatus = {
// No change to function or its inner functions; however its positions
......@@ -517,7 +518,7 @@ Debug.LiveEdit = new function() {
CHANGED: "changed",
// Function is changed but cannot be patched.
DAMAGED: "damaged"
}
};
function CodeInfoTreeNode(code_info, children, array_index) {
this.info = code_info;
......@@ -585,14 +586,14 @@ Debug.LiveEdit = new function() {
var chunk_it = new function() {
var chunk_index = 0;
var pos_diff = 0;
this.current = function() { return chunks[chunk_index]; }
this.current = function() { return chunks[chunk_index]; };
this.next = function() {
var chunk = chunks[chunk_index];
pos_diff = chunk.pos2 + chunk.len2 - (chunk.pos1 + chunk.len1);
chunk_index++;
}
this.done = function() { return chunk_index >= chunks.length; }
this.TranslatePos = function(pos) { return pos + pos_diff; }
};
this.done = function() { return chunk_index >= chunks.length; };
this.TranslatePos = function(pos) { return pos + pos_diff; };
};
// A recursive function that processes internals of a function and all its
......@@ -946,16 +947,16 @@ Debug.LiveEdit = new function() {
BLOCKED_ON_OTHER_STACK: 3,
BLOCKED_UNDER_NATIVE_CODE: 4,
REPLACED_ON_ACTIVE_STACK: 5
}
};
FunctionPatchabilityStatus.SymbolName = function(code) {
var enum = FunctionPatchabilityStatus;
for (name in enum) {
if (enum[name] == code) {
var enumeration = FunctionPatchabilityStatus;
for (name in enumeration) {
if (enumeration[name] == code) {
return name;
}
}
}
};
// A logical failure in liveedit process. This means that change_log
......@@ -968,7 +969,7 @@ Debug.LiveEdit = new function() {
Failure.prototype.toString = function() {
return "LiveEdit Failure: " + this.message;
}
};
// A testing entry.
function GetPcFromSourcePos(func, source_pos) {
......@@ -1078,5 +1079,5 @@ Debug.LiveEdit = new function() {
PosTranslator: PosTranslator,
CompareStrings: CompareStrings,
ApplySingleChunkPatch: ApplySingleChunkPatch
}
}
};
};
......@@ -394,7 +394,7 @@ function ScriptLocationFromPosition(position,
}
return new SourceLocation(this, position, line, column, start, end);
};
}
/**
......@@ -424,7 +424,7 @@ function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) {
// resource.
var column = opt_column || 0;
if (line == 0) {
column -= this.column_offset
column -= this.column_offset;
}
var offset_position = opt_offset_position || 0;
......@@ -439,7 +439,8 @@ function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) {
return null;
}
return this.locationFromPosition(this.line_ends[offset_line + line - 1] + 1 + column); // line > 0 here.
return this.locationFromPosition(
this.line_ends[offset_line + line - 1] + 1 + column); // line > 0 here.
}
}
......@@ -455,8 +456,10 @@ function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) {
* invalid
*/
function ScriptSourceSlice(opt_from_line, opt_to_line) {
var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset : opt_from_line;
var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount() : opt_to_line
var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset
: opt_from_line;
var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount()
: opt_to_line;
// Adjust according to the offset within the resource.
from_line -= this.line_offset;
......@@ -476,8 +479,10 @@ function ScriptSourceSlice(opt_from_line, opt_to_line) {
var to_position = to_line == 0 ? 0 : line_ends[to_line - 1] + 1;
// Return a source slice with line numbers re-adjusted to the resource.
return new SourceSlice(this, from_line + this.line_offset, to_line + this.line_offset,
from_position, to_position);
return new SourceSlice(this,
from_line + this.line_offset,
to_line + this.line_offset,
from_position, to_position);
}
......@@ -510,7 +515,7 @@ function ScriptSourceLine(opt_line) {
function ScriptLineCount() {
// Return number of source lines.
return this.line_ends.length;
};
}
/**
......@@ -575,10 +580,10 @@ SetUpLockedPrototype(Script,
* position : position within the source
* start : position of start of source context (inclusive)
* end : position of end of source context (not inclusive)
* Source text for the source context is the character interval [start, end[. In
* most cases end will point to a newline character. It might point just past
* the final position of the source if the last source line does not end with a
* newline character.
* Source text for the source context is the character interval
* [start, end[. In most cases end will point to a newline character.
* It might point just past the final position of the source if the last
* source line does not end with a newline character.
* @param {Script} script The Script object for which this is a location
* @param {number} position Source position for the location
* @param {number} line The line number for the location
......@@ -645,7 +650,7 @@ function SourceLocationRestrict(opt_limit, opt_before) {
this.end = this.start + limit;
}
}
};
}
/**
......@@ -654,8 +659,11 @@ function SourceLocationRestrict(opt_limit, opt_before) {
* Source text for this location.
*/
function SourceLocationSourceText() {
return %_CallFunction(this.script.source, this.start, this.end, StringSubstring);
};
return %_CallFunction(this.script.source,
this.start,
this.end,
StringSubstring);
}
SetUpLockedPrototype(SourceLocation,
......@@ -663,7 +671,7 @@ SetUpLockedPrototype(SourceLocation,
$Array(
"restrict", SourceLocationRestrict,
"sourceText", SourceLocationSourceText
)
)
);
......@@ -703,7 +711,7 @@ function SourceSliceSourceText() {
this.from_position,
this.to_position,
StringSubstring);
};
}
SetUpLockedPrototype(SourceSlice,
$Array("script", "from_line", "to_line", "from_position", "to_position"),
......@@ -762,7 +770,7 @@ function CallSite(receiver, fun, pos) {
function CallSiteGetThis() {
return this.receiver;
};
}
function CallSiteGetTypeName() {
var constructor = this.receiver.constructor;
......@@ -774,33 +782,33 @@ function CallSiteGetTypeName() {
return %_CallFunction(this.receiver, ObjectToString);
}
return constructorName;
};
}
function CallSiteIsToplevel() {
if (this.receiver == null) {
return true;
}
return IS_GLOBAL(this.receiver);
};
}
function CallSiteIsEval() {
var script = %FunctionGetScript(this.fun);
return script && script.compilation_type == COMPILATION_TYPE_EVAL;
};
}
function CallSiteGetEvalOrigin() {
var script = %FunctionGetScript(this.fun);
return FormatEvalOrigin(script);
};
}
function CallSiteGetScriptNameOrSourceURL() {
var script = %FunctionGetScript(this.fun);
return script ? script.nameOrSourceURL() : null;
};
}
function CallSiteGetFunction() {
return this.fun;
};
}
function CallSiteGetFunctionName() {
// See if the function knows its own name
......@@ -816,15 +824,19 @@ function CallSiteGetFunctionName() {
return "eval";
}
return null;
};
}
function CallSiteGetMethodName() {
// See if we can find a unique property on the receiver that holds
// this function.
var ownName = this.fun.name;
if (ownName && this.receiver &&
(%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun ||
%_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun ||
(%_CallFunction(this.receiver,
ownName,
ObjectLookupGetter) === this.fun ||
%_CallFunction(this.receiver,
ownName,
ObjectLookupSetter) === this.fun ||
this.receiver[ownName] === this.fun)) {
// To handle DontEnum properties we guess that the method has
// the same name as the function.
......@@ -834,7 +846,8 @@ function CallSiteGetMethodName() {
for (var prop in this.receiver) {
if (this.receiver.__lookupGetter__(prop) === this.fun ||
this.receiver.__lookupSetter__(prop) === this.fun ||
(!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.fun)) {
(!this.receiver.__lookupGetter__(prop) &&
this.receiver[prop] === this.fun)) {
// If we find more than one match bail out to avoid confusion.
if (name) {
return null;
......@@ -846,12 +859,12 @@ function CallSiteGetMethodName() {
return name;
}
return null;
};
}
function CallSiteGetFileName() {
var script = %FunctionGetScript(this.fun);
return script ? script.name : null;
};
}
function CallSiteGetLineNumber() {
if (this.pos == -1) {
......@@ -863,7 +876,7 @@ function CallSiteGetLineNumber() {
location = script.locationFromPosition(this.pos, true);
}
return location ? location.line + 1 : null;
};
}
function CallSiteGetColumnNumber() {
if (this.pos == -1) {
......@@ -875,16 +888,16 @@ function CallSiteGetColumnNumber() {
location = script.locationFromPosition(this.pos, true);
}
return location ? location.column + 1: null;
};
}
function CallSiteIsNative() {
var script = %FunctionGetScript(this.fun);
return script ? (script.type == TYPE_NATIVE) : false;
};
}
function CallSiteGetPosition() {
return this.pos;
};
}
function CallSiteIsConstructor() {
var constructor = this.receiver ? this.receiver.constructor : null;
......@@ -892,7 +905,7 @@ function CallSiteIsConstructor() {
return false;
}
return this.fun === constructor;
};
}
SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array(
"getThis", CallSiteGetThis,
......@@ -935,12 +948,13 @@ function FormatEvalOrigin(script) {
// eval script originated from "real" source.
if (eval_from_script.name) {
eval_origin += " (" + eval_from_script.name;
var location = eval_from_script.locationFromPosition(script.eval_from_script_position, true);
var location = eval_from_script.locationFromPosition(
script.eval_from_script_position, true);
if (location) {
eval_origin += ":" + (location.line + 1);
eval_origin += ":" + (location.column + 1);
}
eval_origin += ")"
eval_origin += ")";
} else {
eval_origin += " (unknown source)";
}
......@@ -948,7 +962,7 @@ function FormatEvalOrigin(script) {
}
return eval_origin;
};
}
function FormatSourcePosition(frame) {
var fileName;
......@@ -957,8 +971,9 @@ function FormatSourcePosition(frame) {
fileLocation = "native";
} else if (frame.isEval()) {
fileName = frame.getScriptNameOrSourceURL();
if (!fileName)
if (!fileName) {
fileLocation = frame.getEvalOrigin();
}
} else {
fileName = frame.getFileName();
}
......@@ -1067,7 +1082,7 @@ function captureStackTrace(obj, cons_opt) {
DefineOneShotAccessor(obj, 'stack', function (obj) {
return FormatRawStackTrace(obj, raw_stack);
});
};
}
function SetUpError() {
......@@ -1157,7 +1172,7 @@ function ErrorToStringDetectCycle(error) {
if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker;
try {
var type = error.type;
var name = error.name
var name = error.name;
name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name);
var message = error.message;
var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty);
......
This diff is collapsed.
......@@ -419,14 +419,18 @@ function SetUpRegExp() {
}
function RegExpSetInput(string) {
LAST_INPUT(lastMatchInfo) = 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);
%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
......@@ -437,38 +441,51 @@ function SetUpRegExp() {
// Getter and setter for multiline.
var multiline = false;
function RegExpGetMultiline() { return multiline; };
function RegExpSetMultiline(flag) { multiline = flag ? true : false; };
function RegExpGetMultiline() { return multiline; }
function RegExpSetMultiline(flag) { multiline = flag ? true : false; }
%DefineAccessor($RegExp, 'multiline', GETTER, RegExpGetMultiline, DONT_DELETE);
%DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, DONT_DELETE);
%DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, 'multiline', GETTER, RegExpGetMultiline,
DONT_DELETE);
%DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline,
DONT_DELETE);
%DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline,
DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline,
DONT_ENUM | DONT_DELETE);
function NoOpSetter(ignored) {}
// 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, '$&', GETTER, RegExpGetLastMatch, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch,
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, '$+', GETTER, RegExpGetLastParen, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$+', GETTER, RegExpGetLastParen,
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, '$`', GETTER, RegExpGetLeftContext, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, '$`', GETTER, RegExpGetLeftContext,
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, "$'", GETTER, RegExpGetRightContext, DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext,
DONT_ENUM | DONT_DELETE);
%DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
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);
}
}
......
......@@ -458,7 +458,8 @@ function APPLY_PREPARE(args) {
}
if (!IS_SPEC_FUNCTION(this)) {
throw %MakeTypeError('apply_non_function', [ %ToString(this), typeof this ]);
throw %MakeTypeError('apply_non_function',
[ %ToString(this), typeof this ]);
}
// Make sure the arguments list has the right type.
......
......@@ -46,16 +46,18 @@
// ECMA-262 section 15.5.4.2
function StringToString() {
if (!IS_STRING(this) && !IS_STRING_WRAPPER(this))
if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
throw new $TypeError('String.prototype.toString is not generic');
}
return %_ValueOf(this);
}
// ECMA-262 section 15.5.4.3
function StringValueOf() {
if (!IS_STRING(this) && !IS_STRING_WRAPPER(this))
if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
throw new $TypeError('String.prototype.valueOf is not generic');
}
return %_ValueOf(this);
}
......@@ -91,7 +93,8 @@ function StringCharCodeAt(pos) {
// ECMA-262, section 15.5.4.6
function StringConcat() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
throw MakeTypeError("called_on_null_or_undefined", ["String.prototype.concat"]);
throw MakeTypeError("called_on_null_or_undefined",
["String.prototype.concat"]);
}
var len = %_ArgumentsLength();
var this_as_string = TO_STRING_INLINE(this);
......@@ -358,7 +361,7 @@ function ExpandReplacement(string, subject, matchInfo, builder) {
builder_elements.push(SubString(string, position, next));
}
}
};
}
// Compute the string of a given regular expression capture.
......@@ -371,7 +374,7 @@ function CaptureString(string, lastCaptureInfo, index) {
if (start < 0) return;
var end = lastCaptureInfo[CAPTURE(scaled + 1)];
return SubString(string, start, end);
};
}
// Add the string of a given regular expression capture to the
......@@ -384,7 +387,7 @@ function addCaptureString(builder, matchInfo, index) {
if (start < 0) return;
var end = matchInfo[CAPTURE(scaled + 1)];
builder.addSpecialSlice(start, end);
};
}
// TODO(lrn): This array will survive indefinitely if replace is never
// called again. However, it will be empty, since the contents are cleared
......@@ -531,30 +534,36 @@ function StringSlice(start, end) {
var s_len = s.length;
var start_i = TO_INTEGER(start);
var end_i = s_len;
if (end !== void 0)
if (end !== void 0) {
end_i = TO_INTEGER(end);
}
if (start_i < 0) {
start_i += s_len;
if (start_i < 0)
if (start_i < 0) {
start_i = 0;
}
} else {
if (start_i > s_len)
if (start_i > s_len) {
start_i = s_len;
}
}
if (end_i < 0) {
end_i += s_len;
if (end_i < 0)
if (end_i < 0) {
end_i = 0;
}
} else {
if (end_i > s_len)
if (end_i > s_len) {
end_i = s_len;
}
}
var num_c = end_i - start_i;
if (num_c < 0)
if (num_c < 0) {
num_c = 0;
}
return SubString(s, start_i, start_i + num_c);
}
......@@ -692,7 +701,7 @@ function StringSubstring(start, end) {
}
}
return (start_i + 1 == end_i
return ((start_i + 1 == end_i)
? %_StringCharAt(s, start_i)
: %_SubString(s, start_i, end_i));
}
......@@ -736,7 +745,7 @@ function StringSubstr(start, n) {
var end = start + len;
if (end > s.length) end = s.length;
return (start + 1 == end
return ((start + 1 == end)
? %_StringCharAt(s, start)
: %_SubString(s, start, end));
}
......@@ -836,7 +845,7 @@ function HtmlEscape(str) {
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
}
// Compatibility support for KJS.
......
......@@ -219,7 +219,7 @@ function Decode(uri, reserved) {
var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k));
if (cc >> 7) {
var n = 0;
while (((cc << ++n) & 0x80) != 0) ;
while (((cc << ++n) & 0x80) != 0) { }
if (n == 1 || n > 4) throw new $URIError("URI malformed");
var octets = new $Array(n);
octets[0] = cc;
......@@ -267,7 +267,7 @@ function URIDecode(uri) {
if (63 <= cc && cc <= 64) return true;
return false;
};
}
var string = ToString(uri);
return Decode(string, reservedPredicate);
}
......@@ -275,7 +275,7 @@ function URIDecode(uri) {
// ECMA-262 - 15.1.3.2.
function URIDecodeComponent(component) {
function reservedPredicate(cc) { return false; };
function reservedPredicate(cc) { return false; }
var string = ToString(component);
return Decode(string, reservedPredicate);
}
......@@ -316,7 +316,7 @@ function URIEncode(uri) {
if (cc == 126) return true;
return false;
};
}
var string = ToString(uri);
return Encode(string, unescapePredicate);
......@@ -339,7 +339,7 @@ function URIEncodeComponent(component) {
if (cc == 126) return true;
return false;
};
}
var string = ToString(component);
return Encode(string, unescapePredicate);
......
......@@ -127,8 +127,9 @@ function GlobalParseInt(string, radix) {
// The spec says ToString should be evaluated before ToInt32.
string = TO_STRING_INLINE(string);
radix = TO_INT32(radix);
if (!(radix == 0 || (2 <= radix && radix <= 36)))
if (!(radix == 0 || (2 <= radix && radix <= 36))) {
return $NaN;
}
}
if (%_HasCachedArrayIndex(string) &&
......@@ -283,7 +284,8 @@ function ObjectDefineGetter(name, fun) {
receiver = %GlobalReceiver(global);
}
if (!IS_SPEC_FUNCTION(fun)) {
throw new $TypeError('Object.prototype.__defineGetter__: Expecting function');
throw new $TypeError(
'Object.prototype.__defineGetter__: Expecting function');
}
var desc = new PropertyDescriptor();
desc.setGet(fun);
......@@ -329,8 +331,9 @@ function ObjectLookupSetter(name) {
function ObjectKeys(obj) {
if (!IS_SPEC_OBJECT(obj))
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("obj_ctor_property_non_object", ["keys"]);
}
if (%IsJSProxy(obj)) {
var handler = %GetHandler(obj);
var names = CallTrap0(handler, "keys", DerivedKeysTrap);
......@@ -461,7 +464,7 @@ function ToPropertyDescriptor(obj) {
// For Harmony proxies.
function ToCompletePropertyDescriptor(obj) {
var desc = ToPropertyDescriptor(obj)
var desc = ToPropertyDescriptor(obj);
if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) {
if (!desc.hasValue()) desc.setValue(void 0);
if (!desc.hasWritable()) desc.setWritable(false);
......@@ -845,17 +848,19 @@ function DefineOwnProperty(obj, p, desc, should_throw) {
// ES5 section 15.2.3.2.
function ObjectGetPrototypeOf(obj) {
if (!IS_SPEC_OBJECT(obj))
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]);
}
return %GetPrototype(obj);
}
// ES5 section 15.2.3.3
function ObjectGetOwnPropertyDescriptor(obj, p) {
if (!IS_SPEC_OBJECT(obj))
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("obj_ctor_property_non_object",
["getOwnPropertyDescriptor"]);
}
var desc = GetOwnProperty(obj, p);
return FromPropertyDescriptor(desc);
}
......@@ -868,11 +873,11 @@ function ToStringArray(obj, trap) {
}
var n = ToUint32(obj.length);
var array = new $Array(n);
var names = {} // TODO(rossberg): use sets once they are ready.
var names = {}; // TODO(rossberg): use sets once they are ready.
for (var index = 0; index < n; index++) {
var s = ToString(obj[index]);
if (s in names) {
throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s])
throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]);
}
array[index] = s;
names[s] = 0;
......@@ -883,9 +888,10 @@ function ToStringArray(obj, trap) {
// ES5 section 15.2.3.4.
function ObjectGetOwnPropertyNames(obj) {
if (!IS_SPEC_OBJECT(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"]);
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("obj_ctor_property_non_object",
["getOwnPropertyNames"]);
}
// Special handling for proxies.
if (%IsJSProxy(obj)) {
var handler = %GetHandler(obj);
......@@ -902,8 +908,9 @@ function ObjectGetOwnPropertyNames(obj) {
if (%GetInterceptorInfo(obj) & 1) {
var indexedInterceptorNames =
%GetIndexedInterceptorElementNames(obj);
if (indexedInterceptorNames)
if (indexedInterceptorNames) {
propertyNames = propertyNames.concat(indexedInterceptorNames);
}
}
// Find all the named properties.
......@@ -929,8 +936,9 @@ function ObjectGetOwnPropertyNames(obj) {
// We need to check for the exact property value since for intrinsic
// properties like toString if(propertySet["toString"]) will always
// succeed.
if (propertySet[name] === true)
if (propertySet[name] === true) {
continue;
}
propertySet[name] = true;
propertyNames[j++] = name;
}
......@@ -1006,8 +1014,9 @@ function GetOwnEnumerablePropertyNames(properties) {
// ES5 section 15.2.3.7.
function ObjectDefineProperties(obj, properties) {
if (!IS_SPEC_OBJECT(obj))
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]);
}
var props = ToObject(properties);
var names = GetOwnEnumerablePropertyNames(props);
var descriptors = new InternalArray();
......@@ -1232,8 +1241,9 @@ function BooleanToString() {
function BooleanValueOf() {
// NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this))
if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) {
throw new $TypeError('Boolean.prototype.valueOf is not generic');
}
return %_ValueOf(this);
}
......@@ -1273,8 +1283,9 @@ function NumberToString(radix) {
// 'this'. This is not as dictated by ECMA-262.
var number = this;
if (!IS_NUMBER(this)) {
if (!IS_NUMBER_WRAPPER(this))
if (!IS_NUMBER_WRAPPER(this)) {
throw new $TypeError('Number.prototype.toString is not generic');
}
// Get the value of this number in case it's an object.
number = %_ValueOf(this);
}
......@@ -1307,8 +1318,9 @@ function NumberToLocaleString() {
function NumberValueOf() {
// NOTE: Both Number objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this))
if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) {
throw new $TypeError('Number.prototype.valueOf is not generic');
}
return %_ValueOf(this);
}
......@@ -1334,7 +1346,8 @@ function NumberToExponential(fractionDigits) {
if (!IS_UNDEFINED(fractionDigits)) {
f = TO_INTEGER(fractionDigits);
if (f < 0 || f > 20) {
throw new $RangeError("toExponential() argument must be between 0 and 20");
throw new $RangeError(
"toExponential() argument must be between 0 and 20");
}
}
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
......@@ -1378,7 +1391,8 @@ function SetUpNumber() {
DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262 section 15.7.3.2.
%SetProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetProperty($Number, "MIN_VALUE", 5e-324,
DONT_ENUM | DONT_DELETE | READ_ONLY);
// ECMA-262 section 15.7.3.3.
%SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY);
......@@ -1496,7 +1510,8 @@ function FunctionBind(this_arg) { // Length is 1.
}
// This runtime function finds any remaining arguments on the stack,
// so we don't pass the arguments object.
var result = %FunctionBindArguments(boundFunction, this, this_arg, new_length);
var result = %FunctionBindArguments(boundFunction, this,
this_arg, new_length);
// We already have caller and arguments properties on functions,
// which are non-configurable. It therefore makes no sence to
......
......@@ -42,4 +42,4 @@ function C() {
assertEquals(23, new C().x);
C.prototype.__defineSetter__('x', function(value) { this.y = 23; });
assertEquals(void 0, new C().x));
assertEquals(void 0, new C().x);
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