Commit 4f1e60cc authored by lrn@chromium.org's avatar lrn@chromium.org

Revert r8516.

Revision 8516 contained a temporary hack that doesn't work on Windows.

TBR: ricow

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8519 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a48c03bb
......@@ -32,7 +32,6 @@
#include "allocation.h"
#include "utils.h"
#include "list.h"
#include "hashmap.h"
#include "scanner-base.h"
#include "preparse-data-format.h"
#include "preparse-data.h"
......
This diff is collapsed.
......@@ -31,8 +31,6 @@
namespace v8 {
namespace preparser {
typedef uint8_t byte;
// Preparsing checks a JavaScript program and emits preparse-data that helps
// a later parsing to be faster.
// See preparse-data-format.h for the data format.
......@@ -48,51 +46,6 @@ typedef uint8_t byte;
namespace i = v8::internal;
class DuplicateFinder {
public:
DuplicateFinder()
: backing_store_(16),
map_(new i::HashMap(&Match)) { }
~DuplicateFinder() {
delete map_;
}
int AddAsciiSymbol(i::Vector<const char> key, int value);
int AddUC16Symbol(i::Vector<const uint16_t> key, int value);
// Add a a number literal by converting it (if necessary)
// to the string that ToString(ToNumber(literal)) would generate.
// and then adding that string with AddAsciiSymbol.
// This string is the actual value used as key in an object literal,
// and the one that must be different from the other keys.
int AddNumber(i::Vector<const char> key, int value);
private:
int AddSymbol(i::Vector<const byte> key, bool is_ascii, int value);
// Backs up the key and its length in the backing store.
// The backup is stored with a base 127 encoding of the
// length (plus a bit saying whether the string is ASCII),
// followed by the bytes of the key.
byte* BackupKey(i::Vector<const byte> key, bool is_ascii);
// Compare two encoded keys (both pointing into the backing store)
// for having the same base-127 encoded lengths and ASCII-ness,
// and then having the same 'length' bytes following.
static bool Match(void* first, void* second);
// Creates a hash from a sequence of bytes.
static uint32_t Hash(i::Vector<const byte> key, bool is_ascii);
// Checks whether a string containing a JS number is its canonical
// form.
static bool IsNumberCanonical(i::Vector<const char> key);
static const int kBufferSize = 100;
// Buffer used for string->number->canonical string conversions.
char number_buffer_[kBufferSize];
// Backing store used to store strings used as hashmap keys.
i::SequenceCollector<unsigned char> backing_store_;
i::HashMap* map_;
};
class PreParser {
public:
enum PreParseResult {
......@@ -114,22 +67,6 @@ class PreParser {
}
private:
// Used to detect duplicates in object literals.
enum PropertyType {
kNone = 0,
// Bit patterns representing different object literal property types.
kGetterProperty = 1,
kSetterProperty = 2,
kValueProperty = 7,
// Helper constants.
kValueFlag = 4
};
void CheckDuplicate(DuplicateFinder* finder,
i::Token::Value property,
int type,
bool* ok);
// These types form an algebra over syntactic categories that is just
// rich enough to let us recognize and propagate the constructs that
// are either being counted in the preparser data, or is important
......@@ -427,11 +364,6 @@ class PreParser {
// Report syntax error
void ReportUnexpectedToken(i::Token::Value token);
void ReportMessageAt(i::Scanner::Location location,
const char* type,
const char* name_opt) {
log_->LogMessage(location.beg_pos, location.end_pos, type, name_opt);
}
void ReportMessageAt(int start_pos,
int end_pos,
const char* type,
......
......@@ -496,6 +496,9 @@ class Collector {
public:
explicit Collector(int initial_capacity = kMinCapacity)
: index_(0), size_(0) {
if (initial_capacity < kMinCapacity) {
initial_capacity = kMinCapacity;
}
current_chunk_ = Vector<T>::New(initial_capacity);
}
......@@ -597,21 +600,13 @@ class Collector {
// Creates a new current chunk, and stores the old chunk in the chunks_ list.
void Grow(int min_capacity) {
ASSERT(growth_factor > 1);
int new_capacity;
int current_length = current_chunk_.length();
if (current_length < kMinCapacity) {
// The collector started out as empty.
new_capacity = min_capacity * growth_factor;
if (new_capacity < kMinCapacity) new_capacity = kMinCapacity;
} else {
int growth = current_length * (growth_factor - 1);
if (growth > max_growth) {
growth = max_growth;
}
new_capacity = current_length + growth;
if (new_capacity < min_capacity) {
new_capacity = min_capacity + growth;
}
int growth = current_chunk_.length() * (growth_factor - 1);
if (growth > max_growth) {
growth = max_growth;
}
int new_capacity = current_chunk_.length() + growth;
if (new_capacity < min_capacity) {
new_capacity = min_capacity + growth;
}
Vector<T> new_chunk = Vector<T>::New(new_capacity);
int new_index = PrepareGrow(new_chunk);
......
# Copyright 2011 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.
# Templatated tests with duplicate parameter names.
# ----------------------------------------------------------------------
# Constants and utility functions
# A template that performs the same strict-mode test in different
# scopes (global scope, function scope, and nested function scope),
# and in non-strict mode too.
def DuplicateParameterTest(name, source):
expectation = "strict_param_dupe"
non_selfstrict = {"selfstrict":"", "id":"selfnormal"}
Template(name, '"use strict";\n' + source)(non_selfstrict, expectation)
Template(name + '-infunc',
'function foo() {\n "use strict";\n' + source +'\n}\n')(
non_selfstrict, expectation)
Template(name + '-infunc2',
'function foo() {\n "use strict";\n function bar() {\n' +
source +'\n }\n}\n')(non_selfstrict, expectation)
selfstrict = {"selfstrict": "\"use strict\";", "id": "selfstrict"}
nestedstrict = {"selfstrict": "function bar(){\"use strict\";}",
"id": "nestedstrict"}
selfstrictnestedclean = {"selfstrict": """
"use strict";
function bar(){}
""", "id": "selfstrictnestedclean"}
selftest = Template(name + '-$id', source)
selftest(selfstrict, expectation)
selftest(selfstrictnestedclean, expectation)
selftest(nestedstrict, None)
selftest(non_selfstrict, None)
# ----------------------------------------------------------------------
# Test templates
DuplicateParameterTest("dups", """
function foo(a, a) { $selfstrict }
""");
DuplicateParameterTest("dups-apart", """
function foo(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a) { $selfstrict }
""");
DuplicateParameterTest("dups-escaped", """
function foo(\u0061, b, c, d, e, f, g, h, i, j, k, l, m, n, a) { $selfstrict }
""");
DuplicateParameterTest("triples", """
function foo(a, b, c, d, e, f, g, h, a, i, j, k, l, m, n, a) { $selfstrict }
""");
# Copyright 2011 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.
# Tests of duplicate properties in object literals.
# ----------------------------------------------------------------------
# Utility functions to generate a number of tests for each property
# name pair.
def PropertyTest(name, propa, propb):
replacement = {"id1": propa, "id2": propb, "name": name}
def StrictTest(name, source, replacement, expectation):
Template("strict-" + name,
"\"use strict\";\n" + source)(replacement, expectation)
Template(name, source)(replacement, expectation)
Template("strict-$name-data-data", """
"use strict";
var o = {$id1: 42, $id2: 42};
""")(replacement, "strict_duplicate_property")
Template("$name-data-data", """
var o = {$id1: 42, $id2: 42};
""")(replacement, None)
StrictTest("$name-data-get", """
var o = {$id1: 42, get $id2(){}};
""", replacement, "accessor_data_property")
StrictTest("$name-data-set", """
var o = {$id1: 42, set $id2(v){}};
""", replacement, "accessor_data_property")
StrictTest("$name-get-data", """
var o = {get $id1(){}, $id2: 42};
""", replacement, "accessor_data_property")
StrictTest("$name-set-data", """
var o = {set $id1(v){}, $id2: 42};
""", replacement, "accessor_data_property")
StrictTest("$name-get-get", """
var o = {get $id1(){}, get $id2(){}};
""", replacement, "accessor_get_set")
StrictTest("$name-set-set", """
var o = {set $id1(v){}, set $id2(v){}};
""", replacement, "accessor_get_set")
StrictTest("$name-nested-get", """
var o = {get $id1(){}, o: {get $id2(){} } };
""", replacement, None)
StrictTest("$name-nested-set", """
var o = {set $id1(){}, o: {set $id2(){} } };
""", replacement, None)
def TestBothWays(name, propa, propb):
PropertyTest(name + "-1", propa, propb)
PropertyTest(name + "-2", propb, propa)
def TestSame(name, prop):
PropertyTest(name, prop, prop)
#-----------------------------------------------------------------------
# Simple identifier property
TestSame("a", "a")
# Get/set identifiers
TestSame("get-id", "get")
TestSame("set-id", "set")
# Number properties
TestSame("0", "0")
TestSame("0.1", "0.1")
TestSame("1.0", "1.0")
TestSame("42.33", "42.33")
TestSame("2^32-2", "4294967294")
TestSame("2^32", "4294967296")
TestSame("2^53", "9007199254740992")
TestSame("Hex20", "0x20")
TestSame("exp10", "1e10")
TestSame("exp20", "1e20")
# String properties
TestSame("str-a", '"a"')
TestSame("str-0", '"0"')
TestSame("str-42", '"42"')
TestSame("str-empty", '""')
# Keywords
TestSame("if", "if")
TestSame("case", "case")
# Future reserved keywords
TestSame("public", "public")
TestSame("class", "class")
# Test that numbers are converted to string correctly.
TestBothWays("hex-int", "0x20", "32")
TestBothWays("dec-int", "32.00", "32")
TestBothWays("dec-underflow-int",
"32.00000000000000000000000000000000000000001", "32")
TestBothWays("exp-int", "3.2e1", "32")
TestBothWays("exp-int", "3200e-2", "32")
TestBothWays("overflow-inf", "1e2000", "Infinity")
TestBothWays("underflow-0", "1e-2000", "0")
TestBothWays("precission-loss-high", "9007199254740992", "9007199254740993")
TestBothWays("precission-loss-low", "1.9999999999999998", "1.9999999999999997")
TestBothWays("hex-int-str", "0x20", '"32"')
TestBothWays("dec-int-str", "32.00", '"32"')
TestBothWays("exp-int-str", "3.2e1", '"32"')
TestBothWays("overflow-inf-str", "1e2000", '"Infinity"')
TestBothWays("underflow-0-str", "1e-2000", '"0"')
......@@ -98,6 +98,7 @@ class PreparserTestConfiguration(test.TestConfiguration):
def ParsePythonTestTemplates(self, result, filename,
executable, current_path, mode):
pathname = join(self.root, filename + ".pyt")
source = open(pathname).read();
def Test(name, source, expectation):
throws = None
if (expectation is not None):
......@@ -117,7 +118,8 @@ class PreparserTestConfiguration(test.TestConfiguration):
testsource = testsource.replace("$"+key, replacement[key]);
Test(testname, testsource, expectation)
return MkTest
execfile(pathname, {"Test": Test, "Template": Template})
eval(compile(source, pathname, "exec"),
{"Test": Test, "Template": Template}, {})
def ListTests(self, current_path, path, mode, variant_flags):
executable = join('obj', 'preparser', mode, 'preparser')
......@@ -141,9 +143,9 @@ class PreparserTestConfiguration(test.TestConfiguration):
filenames.sort()
for file in filenames:
# Each file as a python source file to be executed in a specially
# created environment (defining the Template and Test functions)
# perparsed environment (defining the Template and Test functions)
self.ParsePythonTestTemplates(result, file,
executable, current_path, mode)
executable, current_path, mode)
return result
def GetTestStatus(self, sections, defs):
......
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