Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Unified Diff: src/messages.js

Issue 7830036: Optimize isFinite and isNaN. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Made the change general by moving putting it in the NUMBER_IS_FINITE macro. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/math.js ('k') | src/mips/code-stubs-mips.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index 3c85d9416af035f37c302e4e7df5c29fee9c234b..e38dc3e9dcde521a022acf892b996d89010be0f1 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -116,11 +116,10 @@ function MakeGenericError(constructor, type, args) {
/**
- * Set up the Script function and constructor.
+ * Setup the Script function and constructor.
*/
%FunctionSetInstanceClassName(Script, 'Script');
-%SetProperty(Script.prototype, 'constructor', Script,
- DONT_ENUM | DONT_DELETE | READ_ONLY);
+%SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM);
%SetCode(Script, function(x) {
// Script objects can only be created by the VM.
throw new $Error("Not supported");
@@ -321,7 +320,7 @@ function MakeError(type, args) {
* @return {number} 0 if input too small, -1 if input too large,
else the line number.
*/
-function ScriptLineFromPosition(position) {
+Script.prototype.lineFromPosition = function(position) {
var lower = 0;
var upper = this.lineCount() - 1;
var line_ends = this.line_ends;
@@ -360,8 +359,8 @@ function ScriptLineFromPosition(position) {
* @return {SourceLocation}
* If line is negative or not in the source null is returned.
*/
-function ScriptLocationFromPosition(position,
- include_resource_offset) {
+Script.prototype.locationFromPosition = function (position,
+ include_resource_offset) {
var line = this.lineFromPosition(position);
if (line == -1) return null;
@@ -369,9 +368,7 @@ function ScriptLocationFromPosition(position,
var line_ends = this.line_ends;
var start = line == 0 ? 0 : line_ends[line - 1] + 1;
var end = line_ends[line];
- if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') {
- end--;
- }
+ if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') end--;
var column = position - start;
// Adjust according to the offset within the resource.
@@ -396,12 +393,11 @@ function ScriptLocationFromPosition(position,
* @param {number} opt_line The line within the source. Default value is 0
* @param {number} opt_column The column in within the line. Default value is 0
* @param {number} opt_offset_position The offset from the begining of the
- * source from where the line and column calculation starts.
- * Default value is 0
+ * source from where the line and column calculation starts. Default value is 0
* @return {SourceLocation}
* If line is negative or not in the source null is returned.
*/
-function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) {
+Script.prototype.locationFromLine = function (opt_line, opt_column, opt_offset_position) {
// Default is the first line in the script. Lines in the script is relative
// to the offset within the resource.
var line = 0;
@@ -443,7 +439,7 @@ function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) {
* @return {SourceSlice} The source slice or null of the parameters where
* invalid
*/
-function ScriptSourceSlice(opt_from_line, opt_to_line) {
+Script.prototype.sourceSlice = function (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
@@ -470,7 +466,7 @@ function ScriptSourceSlice(opt_from_line, opt_to_line) {
}
-function ScriptSourceLine(opt_line) {
+Script.prototype.sourceLine = function (opt_line) {
// Default is the first line in the script. Lines in the script are relative
// to the offset within the resource.
var line = 0;
@@ -496,7 +492,7 @@ function ScriptSourceLine(opt_line) {
* @return {number}
* Number of source lines.
*/
-function ScriptLineCount() {
+Script.prototype.lineCount = function() {
// Return number of source lines.
return this.line_ends.length;
};
@@ -512,10 +508,9 @@ function ScriptLineCount() {
* @return {?string} script name if present, value for //@ sourceURL comment
* otherwise.
*/
-function ScriptNameOrSourceURL() {
- if (this.name) {
+Script.prototype.nameOrSourceURL = function() {
+ if (this.name)
return this.name;
- }
// TODO(608): the spaces in a regexp below had to be escaped as \040
// because this file is being processed by js2c whose handling of spaces
// in regexps is broken. Also, ['"] are excluded from allowed URLs to
@@ -541,20 +536,6 @@ function ScriptNameOrSourceURL() {
}
-SetUpLockedPrototype(Script,
- $Array("source", "name", "line_ends", "line_offset", "column_offset"),
- $Array(
- "lineFromPosition", ScriptLineFromPosition,
- "locationFromPosition", ScriptLocationFromPosition,
- "locationFromLine", ScriptLocationFromLine,
- "sourceSlice", ScriptSourceSlice,
- "sourceLine", ScriptSourceLine,
- "lineCount", ScriptLineCount,
- "nameOrSourceURL", ScriptNameOrSourceURL
- )
-);
-
-
/**
* Class for source location. A source location is a position within some
* source with the following properties:
@@ -585,6 +566,8 @@ function SourceLocation(script, position, line, column, start, end) {
this.end = end;
}
+SourceLocation.prototype.__proto__ = null;
+
const kLineLengthLimit = 78;
/**
@@ -595,7 +578,7 @@ const kLineLengthLimit = 78;
* @param {number} opt_before The number of characters to prefer before the
* position with a default value of 10 less that the limit
*/
-function SourceLocationRestrict(opt_limit, opt_before) {
+SourceLocation.prototype.restrict = function (opt_limit, opt_before) {
// Find the actual limit to use.
var limit;
var before;
@@ -642,20 +625,11 @@ function SourceLocationRestrict(opt_limit, opt_before) {
* @return {String}
* Source text for this location.
*/
-function SourceLocationSourceText() {
+SourceLocation.prototype.sourceText = function () {
return %_CallFunction(this.script.source, this.start, this.end, StringSubstring);
};
-SetUpLockedPrototype(SourceLocation,
- $Array("script", "position", "line", "column", "start", "end"),
- $Array(
- "restrict", SourceLocationRestrict,
- "sourceText", SourceLocationSourceText
- )
-);
-
-
/**
* Class for a source slice. A source slice is a part of a script source with
* the following properties:
@@ -682,23 +656,20 @@ function SourceSlice(script, from_line, to_line, from_position, to_position) {
this.to_position = to_position;
}
+SourceSlice.prototype.__proto__ = null;
+
/**
* Get the source text for a SourceSlice
* @return {String} Source text for this slice. The last line will include
* the line terminating characters (if any)
*/
-function SourceSliceSourceText() {
+SourceSlice.prototype.sourceText = function () {
return %_CallFunction(this.script.source,
this.from_position,
this.to_position,
StringSubstring);
};
-SetUpLockedPrototype(SourceSlice,
- $Array("script", "from_line", "to_line", "from_position", "to_position"),
- $Array("sourceText", SourceSliceSourceText)
-);
-
// Returns the offset of the given position within the containing
// line.
@@ -753,11 +724,13 @@ function CallSite(receiver, fun, pos) {
this.pos = pos;
}
-function CallSiteGetThis() {
+CallSite.prototype.__proto__ = null;
+
+CallSite.prototype.getThis = function () {
return this.receiver;
};
-function CallSiteGetTypeName() {
+CallSite.prototype.getTypeName = function () {
var constructor = this.receiver.constructor;
if (!constructor) {
return %_CallFunction(this.receiver, ObjectToString);
@@ -769,33 +742,33 @@ function CallSiteGetTypeName() {
return constructorName;
};
-function CallSiteIsToplevel() {
+CallSite.prototype.isToplevel = function () {
if (this.receiver == null) {
return true;
}
return IS_GLOBAL(this.receiver);
};
-function CallSiteIsEval() {
+CallSite.prototype.isEval = function () {
var script = %FunctionGetScript(this.fun);
return script && script.compilation_type == COMPILATION_TYPE_EVAL;
};
-function CallSiteGetEvalOrigin() {
+CallSite.prototype.getEvalOrigin = function () {
var script = %FunctionGetScript(this.fun);
return FormatEvalOrigin(script);
};
-function CallSiteGetScriptNameOrSourceURL() {
+CallSite.prototype.getScriptNameOrSourceURL = function () {
var script = %FunctionGetScript(this.fun);
return script ? script.nameOrSourceURL() : null;
};
-function CallSiteGetFunction() {
+CallSite.prototype.getFunction = function () {
return this.fun;
};
-function CallSiteGetFunctionName() {
+CallSite.prototype.getFunctionName = function () {
// See if the function knows its own name
var name = this.fun.name;
if (name) {
@@ -811,7 +784,7 @@ function CallSiteGetFunctionName() {
return null;
};
-function CallSiteGetMethodName() {
+CallSite.prototype.getMethodName = function () {
// See if we can find a unique property on the receiver that holds
// this function.
var ownName = this.fun.name;
@@ -841,12 +814,12 @@ function CallSiteGetMethodName() {
return null;
};
-function CallSiteGetFileName() {
+CallSite.prototype.getFileName = function () {
var script = %FunctionGetScript(this.fun);
return script ? script.name : null;
};
-function CallSiteGetLineNumber() {
+CallSite.prototype.getLineNumber = function () {
if (this.pos == -1) {
return null;
}
@@ -858,7 +831,7 @@ function CallSiteGetLineNumber() {
return location ? location.line + 1 : null;
};
-function CallSiteGetColumnNumber() {
+CallSite.prototype.getColumnNumber = function () {
if (this.pos == -1) {
return null;
}
@@ -870,16 +843,16 @@ function CallSiteGetColumnNumber() {
return location ? location.column + 1: null;
};
-function CallSiteIsNative() {
+CallSite.prototype.isNative = function () {
var script = %FunctionGetScript(this.fun);
return script ? (script.type == TYPE_NATIVE) : false;
};
-function CallSiteGetPosition() {
+CallSite.prototype.getPosition = function () {
return this.pos;
};
-function CallSiteIsConstructor() {
+CallSite.prototype.isConstructor = function () {
var constructor = this.receiver ? this.receiver.constructor : null;
if (!constructor) {
return false;
@@ -887,25 +860,6 @@ function CallSiteIsConstructor() {
return this.fun === constructor;
};
-SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array(
- "getThis", CallSiteGetThis,
- "getTypeName", CallSiteGetTypeName,
- "isToplevel", CallSiteIsToplevel,
- "isEval", CallSiteIsEval,
- "getEvalOrigin", CallSiteGetEvalOrigin,
- "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL,
- "getFunction", CallSiteGetFunction,
- "getFunctionName", CallSiteGetFunctionName,
- "getMethodName", CallSiteGetMethodName,
- "getFileName", CallSiteGetFileName,
- "getLineNumber", CallSiteGetLineNumber,
- "getColumnNumber", CallSiteGetColumnNumber,
- "isNative", CallSiteIsNative,
- "getPosition", CallSiteGetPosition,
- "isConstructor", CallSiteIsConstructor
-));
-
-
function FormatEvalOrigin(script) {
var sourceURL = script.nameOrSourceURL();
if (sourceURL) {
@@ -1047,7 +1001,6 @@ function FormatRawStackTrace(error, raw_stack) {
}
}
-
function captureStackTrace(obj, cons_opt) {
var stackTraceLimit = $Error.stackTraceLimit;
if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
@@ -1063,7 +1016,7 @@ function captureStackTrace(obj, cons_opt) {
};
-function SetUpError() {
+(function () {
// Define special error type constructors.
function DefineError(f) {
@@ -1132,9 +1085,7 @@ function SetUpError() {
DefineError(function ReferenceError() { });
DefineError(function EvalError() { });
DefineError(function URIError() { });
-}
-
-SetUpError();
+})();
$Error.captureStackTrace = captureStackTrace;
« no previous file with comments | « src/math.js ('k') | src/mips/code-stubs-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698