Reviewers: dcarney, ulan,

Message:
Committed patchset #1 manually as r18195 (presubmit successful).

Description:
Experimental scanner: support preparsing API.

This fixes some cctests, but not all.

[email protected],[email protected]
BUG=

Committed: https://code.google.com/p/v8/source/detail?r=18195

Please review this at https://codereview.chromium.org/98293004/

SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser

Affected files (+42, -22 lines):
  M src/api.cc
  M src/parser.h
  M src/parser.cc
  M test/cctest/test-parsing.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 65e73450239c352381676bedb560b332761ef3cd..f34bdd2ead20573210bf5f41766eb9dfe75b2f04 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1656,24 +1656,18 @@ void ObjectTemplate::SetInternalFieldCount(int value) {
 ScriptData* ScriptData::PreCompile(v8::Isolate* isolate,
                                    const char* input,
                                    int length) {
-  i::Utf8ToUtf16CharacterStream stream(
-      reinterpret_cast<const unsigned char*>(input), length);
-  return i::PreParserApi::PreParse(
-      reinterpret_cast<i::Isolate*>(isolate), &stream);
+  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  i::HandleScope handle_scope(internal_isolate);
+  i::Handle<i::String> source = internal_isolate->factory()
+      ->NewStringFromAscii(i::Vector<const char>(input, length));
+  return i::PreParserApi::PreParse(internal_isolate, source);
 }


 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) {
   i::Handle<i::String> str = Utils::OpenHandle(*source);
   i::Isolate* isolate = str->GetIsolate();
-  if (str->IsExternalTwoByteString()) {
-    i::ExternalTwoByteStringUtf16CharacterStream stream(
-      i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length());
-    return i::PreParserApi::PreParse(isolate, &stream);
-  } else {
-    i::GenericStringUtf16CharacterStream stream(str, 0, str->length());
-    return i::PreParserApi::PreParse(isolate, &stream);
-  }
+  return i::PreParserApi::PreParse(isolate, str);
 }


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b56e1fd15dd3ae5e8342f35fe50d0f08b7f37414..32f2ca7d8c7a001aacf427b5f98eb3b820ffee08 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -5608,9 +5608,35 @@ int ScriptDataImpl::ReadNumber(byte** source) {
 // Create a ScannerBase for the preparser to use as input, and preparse the
 // source.
 ScriptDataImpl* PreParserApi::PreParse(Isolate* isolate,
-                                       Utf16CharacterStream* source) {
-  // FIXME(experimental-scanner): implement
-  return NULL;
+                                       Handle<String> source) {
+  CompleteParserRecorder recorder;
+  HistogramTimerScope timer(isolate->counters()->pre_parse());
+  ScannerBase* scanner = NULL;
+  if (source->IsTwoByteRepresentation()) {
+    scanner = new ExperimentalScanner<uint16_t>(source, isolate);
+  } else {
+    scanner = new ExperimentalScanner<uint8_t>(source, isolate);
+  }
+  intptr_t stack_limit = isolate->stack_guard()->real_climit();
+  PreParser preparser(scanner, &recorder, stack_limit);
+  preparser.set_allow_lazy(true);
+  preparser.set_allow_generators(FLAG_harmony_generators);
+  preparser.set_allow_for_of(FLAG_harmony_iteration);
+  preparser.set_allow_harmony_scoping(FLAG_harmony_scoping);
+ preparser.set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
+  scanner->Init();
+  PreParser::PreParseResult result = preparser.PreParseProgram();
+  if (result == PreParser::kPreParseStackOverflow) {
+    isolate->StackOverflow();
+    delete scanner;
+    return NULL;
+  }
+
+  // Extract the accumulated data from the recorder as a single
+  // contiguous vector that we are responsible for disposing.
+  Vector<unsigned> store = recorder.ExtractData();
+  delete scanner;
+  return new ScriptDataImpl(store);
 }


Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index cdfcd92d25cfb52994ca5112d61fdc460db211ba..e0862a85ff84a9f43b002aad7decbb0f47fd568d 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -154,7 +154,7 @@ class PreParserApi {
// preparser recorder object that is suited to the parser's purposes. Also,
   // the preparser doesn't know about ScriptDataImpl.
   static ScriptDataImpl* PreParse(Isolate* isolate,
-                                  Utf16CharacterStream* source);
+                                  Handle<String> source);
 };


Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 9b1e8eb8500cda8b5331251d0729281f05f35062..eaa503b458cfa3101b667ea8f90b727e2cf330be 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -327,10 +327,11 @@ TEST(RegressChromium62639) {
   // and then used the invalid currently scanned literal. This always
   // failed in debug mode, and sometimes crashed in release mode.

-  i::Utf8ToUtf16CharacterStream stream(
-      reinterpret_cast<const i::byte*>(program),
-      static_cast<unsigned>(strlen(program)));
-  i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, &stream);
+  v8::HandleScope handles(CcTest::isolate());
+  i::Handle<i::String> source = isolate->factory()->NewStringFromAscii(
+      i::Vector<const char>(reinterpret_cast<const char*>(program),
+                            strlen(program)));
+  i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, source);
   CHECK(data->HasError());
   delete data;
 }
@@ -356,8 +357,7 @@ TEST(Regress928) {
   v8::HandleScope handles(CcTest::isolate());
   i::Handle<i::String> source(
       factory->NewStringFromAscii(i::CStrVector(program)));
-  i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
-  i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, &stream);
+  i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, source);
   CHECK(!data->HasError());

   data->Initialize();


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to