Commit 98390928 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

* Remove non-Open Source code from Douglas Crockford.

* Be more var-correct in JS files.
* Rename some JS variables to reflect the fact that they are instance
  variables on the global intrinsics object.
* Missing optimization in StringCharAt.
Review URL: http://codereview.chromium.org/215052

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2959 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent cf46d30d
......@@ -21,10 +21,6 @@ are:
This code is copyrighted by Sun Microsystems Inc. and released
under a 3-clause BSD license.
- JSMin JavaScript minifier, located at tools/jsmin.py. This code is
copyrighted by Douglas Crockford and Baruch Even and released under
an MIT license.
- Valgrind client API header, located at third_party/valgrind/valgrind.h
This is release under the BSD license.
......
......@@ -709,6 +709,8 @@ function ArraySort(comparefn) {
QuickSort(a, high_start, to);
}
var length;
// Copies elements in the range 0..length from obj's prototype chain
// to obj itself, if obj has holes. Returns one more than the maximal index
// of a prototype property.
......@@ -826,7 +828,7 @@ function ArraySort(comparefn) {
return first_undefined;
}
var length = ToUint32(this.length);
length = ToUint32(this.length);
if (length < 2) return this;
var is_array = IS_ARRAY(this);
......
......@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// jsminify this file, js2c: jsmin
// Default number of frames to include in the response to backtrace request.
const kDefaultBacktraceLength = 10;
......@@ -35,7 +33,7 @@ const Debug = {};
// Regular expression to skip "crud" at the beginning of a source line which is
// not really code. Currently the regular expression matches whitespace and
// comments.
const sourceLineBeginningSkip = /^(?:[ \v\h]*(?:\/\*.*?\*\/)*)*/;
const sourceLineBeginningSkip = /^(?:\s*(?:\/\*.*?\*\/)*)*/;
// Debug events which can occour in the V8 JavaScript engine. These originate
// from the API include file debug.h.
......
......@@ -32,6 +32,11 @@
var kVowelSounds = 0;
var kCapitalVowelSounds = 0;
// If this object gets passed to an error constructor the error will
// get an accessor for .message that constructs a descriptive error
// message on access.
var kAddMessageAccessorsMarker = { };
function GetInstanceName(cons) {
if (cons.length == 0) {
......@@ -565,11 +570,6 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
// ----------------------------------------------------------------------------
// Error implementation
// If this object gets passed to an error constructor the error will
// get an accessor for .message that constructs a descriptive error
// message on access.
var kAddMessageAccessorsMarker = { };
// Defines accessors for a property that is calculated the first time
// the property is read.
function DefineOneShotAccessor(obj, name, fun) {
......@@ -781,14 +781,15 @@ function FormatStackTrace(error, frames) {
}
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
var line;
try {
var line = FormatSourcePosition(frame);
line = FormatSourcePosition(frame);
} catch (e) {
try {
var line = "<error: " + e + ">";
line = "<error: " + e + ">";
} catch (ee) {
// Any code that reaches this point is seriously nasty!
var line = "<error>";
line = "<error>";
}
}
lines.push(" at " + line);
......
......@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// jsminify this file, js2c: jsmin
// Touch the RegExp and Date functions to make sure that date-delay.js and
// regexp-delay.js has been loaded. This is required as the mirrors use
// functions within these files through the builtins object.
......
......@@ -62,7 +62,7 @@ function StringValueOf() {
// ECMA-262, section 15.5.4.4
function StringCharAt(pos) {
var char_code = %_FastCharCodeAt(this, index);
var char_code = %_FastCharCodeAt(this, pos);
if (!%_IsSmi(char_code)) {
var subject = ToString(this);
var index = TO_INTEGER(pos);
......@@ -184,6 +184,14 @@ function SubString(string, start, end) {
}
// This has the same size as the lastMatchInfo array, and can be used for
// functions that expect that structure to be returned. It is used when the
// needle is a string rather than a regexp. In this case we can't update
// lastMatchArray without erroneously affecting the properties on the global
// RegExp object.
var reusableMatchInfo = [2, "", "", -1, -1];
// ECMA-262, section 15.5.4.11
function StringReplace(search, replace) {
var subject = ToString(this);
......@@ -224,14 +232,6 @@ function StringReplace(search, replace) {
}
// This has the same size as the lastMatchInfo array, and can be used for
// functions that expect that structure to be returned. It is used when the
// needle is a string rather than a regexp. In this case we can't update
// lastMatchArray without erroneously affecting the properties on the global
// RegExp object.
var reusableMatchInfo = [2, "", "", -1, -1];
// Helper function for regular expressions in String.prototype.replace.
function StringReplaceRegExp(subject, regexp, replace) {
replace = ToString(replace);
......@@ -370,8 +370,8 @@ function addCaptureString(builder, matchInfo, index) {
// 'abcd'.replace(/(.)/g, function() { return RegExp.$1; }
// should be 'abcd' and not 'dddd' (or anything else).
function StringReplaceRegExpWithFunction(subject, regexp, replace) {
var lastMatchInfo = DoRegExpExec(regexp, subject, 0);
if (IS_NULL(lastMatchInfo)) return subject;
var matchInfo = DoRegExpExec(regexp, subject, 0);
if (IS_NULL(matchInfo)) return subject;
var result = new ReplaceResultBuilder(subject);
// There's at least one match. If the regexp is global, we have to loop
......@@ -382,11 +382,11 @@ function StringReplaceRegExpWithFunction(subject, regexp, replace) {
if (regexp.global) {
var previous = 0;
do {
result.addSpecialSlice(previous, lastMatchInfo[CAPTURE0]);
var startOfMatch = lastMatchInfo[CAPTURE0];
previous = lastMatchInfo[CAPTURE1];
result.add(ApplyReplacementFunction(replace, lastMatchInfo, subject));
// Can't use lastMatchInfo any more from here, since the function could
result.addSpecialSlice(previous, matchInfo[CAPTURE0]);
var startOfMatch = matchInfo[CAPTURE0];
previous = matchInfo[CAPTURE1];
result.add(ApplyReplacementFunction(replace, matchInfo, subject));
// Can't use matchInfo any more from here, since the function could
// overwrite it.
// Continue with the next match.
// Increment previous if we matched an empty string, as per ECMA-262
......@@ -401,20 +401,20 @@ function StringReplaceRegExpWithFunction(subject, regexp, replace) {
// Per ECMA-262 15.10.6.2, if the previous index is greater than the
// string length, there is no match
lastMatchInfo = (previous > subject.length)
matchInfo = (previous > subject.length)
? null
: DoRegExpExec(regexp, subject, previous);
} while (!IS_NULL(lastMatchInfo));
} while (!IS_NULL(matchInfo));
// Tack on the final right substring after the last match, if necessary.
if (previous < subject.length) {
result.addSpecialSlice(previous, subject.length);
}
} else { // Not a global regexp, no need to loop.
result.addSpecialSlice(0, lastMatchInfo[CAPTURE0]);
var endOfMatch = lastMatchInfo[CAPTURE1];
result.add(ApplyReplacementFunction(replace, lastMatchInfo, subject));
// Can't use lastMatchInfo any more from here, since the function could
result.addSpecialSlice(0, matchInfo[CAPTURE0]);
var endOfMatch = matchInfo[CAPTURE1];
result.add(ApplyReplacementFunction(replace, matchInfo, subject));
// Can't use matchInfo any more from here, since the function could
// overwrite it.
result.addSpecialSlice(endOfMatch, subject.length);
}
......@@ -424,20 +424,20 @@ function StringReplaceRegExpWithFunction(subject, regexp, replace) {
// Helper function to apply a string replacement function once.
function ApplyReplacementFunction(replace, lastMatchInfo, subject) {
function ApplyReplacementFunction(replace, matchInfo, subject) {
// Compute the parameter list consisting of the match, captures, index,
// and subject for the replace function invocation.
var index = lastMatchInfo[CAPTURE0];
var index = matchInfo[CAPTURE0];
// The number of captures plus one for the match.
var m = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1;
var m = NUMBER_OF_CAPTURES(matchInfo) >> 1;
if (m == 1) {
var s = CaptureString(subject, lastMatchInfo, 0);
var s = CaptureString(subject, matchInfo, 0);
// Don't call directly to avoid exposing the built-in global object.
return replace.call(null, s, index, subject);
}
var parameters = $Array(m + 2);
for (var j = 0; j < m; j++) {
parameters[j] = CaptureString(subject, lastMatchInfo, j);
parameters[j] = CaptureString(subject, matchInfo, j);
}
parameters[j] = index;
parameters[j + 1] = subject;
......@@ -539,14 +539,14 @@ function StringSplit(separator, limit) {
return result;
}
var lastMatchInfo = splitMatch(separator, subject, currentIndex, startIndex);
var matchInfo = splitMatch(separator, subject, currentIndex, startIndex);
if (IS_NULL(lastMatchInfo)) {
if (IS_NULL(matchInfo)) {
result[result.length] = subject.slice(currentIndex, length);
return result;
}
var endIndex = lastMatchInfo[CAPTURE1];
var endIndex = matchInfo[CAPTURE1];
// We ignore a zero-length match at the currentIndex.
if (startIndex === endIndex && endIndex === currentIndex) {
......@@ -554,12 +554,12 @@ function StringSplit(separator, limit) {
continue;
}
result[result.length] = SubString(subject, currentIndex, lastMatchInfo[CAPTURE0]);
result[result.length] = SubString(subject, currentIndex, matchInfo[CAPTURE0]);
if (result.length === limit) return result;
for (var i = 2; i < NUMBER_OF_CAPTURES(lastMatchInfo); i += 2) {
var start = lastMatchInfo[CAPTURE(i)];
var end = lastMatchInfo[CAPTURE(i + 1)];
for (var i = 2; i < NUMBER_OF_CAPTURES(matchInfo); i += 2) {
var start = matchInfo[CAPTURE(i)];
var end = matchInfo[CAPTURE(i + 1)];
if (start != -1 && end != -1) {
result[result.length] = SubString(subject, start, end);
} else {
......@@ -574,16 +574,16 @@ function StringSplit(separator, limit) {
// ECMA-262 section 15.5.4.14
// Helper function used by split. This version returns the lastMatchInfo
// Helper function used by split. This version returns the matchInfo
// instead of allocating a new array with basically the same information.
function splitMatch(separator, subject, current_index, start_index) {
if (IS_REGEXP(separator)) {
var lastMatchInfo = DoRegExpExec(separator, subject, start_index);
if (lastMatchInfo == null) return null;
var matchInfo = DoRegExpExec(separator, subject, start_index);
if (matchInfo == null) return null;
// Section 15.5.4.14 paragraph two says that we do not allow zero length
// matches at the end of the string.
if (lastMatchInfo[CAPTURE0] === subject.length) return null;
return lastMatchInfo;
if (matchInfo[CAPTURE0] === subject.length) return null;
return matchInfo;
}
var separatorIndex = subject.indexOf(separator, start_index);
......
......@@ -30,6 +30,11 @@
// Expect $String = global.String;
// Lazily initialized.
var hexCharArray = 0;
var hexCharCodeArray = 0;
function URIAddEncodedOctetToBuffer(octet, result, index) {
result[index++] = 37; // Char code of '%'.
result[index++] = hexCharCodeArray[octet >> 4];
......@@ -320,11 +325,6 @@ function URIEncodeComponent(component) {
}
// Lazily initialized.
var hexCharArray = 0;
var hexCharCodeArray = 0;
function HexValueOf(c) {
var code = c.charCodeAt(0);
......
......@@ -52,20 +52,6 @@ def RemoveCommentsAndTrailingWhitespace(lines):
return lines
def CompressScript(lines, do_jsmin):
# If we're not expecting this code to be user visible, we can run it through
# a more aggressive minifier.
if do_jsmin:
return jsmin.jsmin(lines)
# Remove stuff from the source that we don't want to appear when
# people print the source code using Function.prototype.toString().
# Note that we could easily compress the scripts mode but don't
# since we want it to remain readable.
lines = RemoveCommentsAndTrailingWhitespace(lines)
return lines
def ReadFile(filename):
file = open(filename, "rt")
try:
......@@ -295,16 +281,18 @@ def JS2C(source, target, env):
# Build source code lines
source_lines = [ ]
minifier = jsmin.JavaScriptMinifier()
source_lines_empty = []
for module in modules:
filename = str(module)
delay = filename.endswith('-delay.js')
lines = ReadFile(filename)
do_jsmin = lines.find('// jsminify this file, js2c: jsmin') != -1
lines = ExpandConstants(lines, consts)
lines = ExpandMacros(lines, macros)
Validate(lines, filename)
lines = CompressScript(lines, do_jsmin)
lines = minifier.JSMinify(lines)
data = ToCArray(lines)
id = (os.path.split(filename)[1])[:-3]
if delay: id = id[:-6]
......
This diff is collapsed.
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