Revision: 11429
Author:   [email protected]
Date:     Wed Apr 25 01:45:45 2012
Log:      Make String::Empty inlineable.

[email protected]
TEST=cctest/test-api/StringEmpty

Review URL: https://chromiumcodereview.appspot.com/10199019
http://code.google.com/p/v8/source/detail?r=11429

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/heap.h
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Apr 24 07:37:53 2012
+++ /branches/bleeding_edge/include/v8.h        Wed Apr 25 01:45:45 2012
@@ -1084,6 +1084,7 @@
    * A zero length string.
    */
   V8EXPORT static v8::Local<v8::String> Empty();
+  inline static v8::Local<v8::String> Empty(Isolate* isolate);

   /**
    * Returns true if the string is external
@@ -3903,6 +3904,7 @@
   static const int kNullValueRootIndex = 7;
   static const int kTrueValueRootIndex = 8;
   static const int kFalseValueRootIndex = 9;
+  static const int kEmptySymbolRootIndex = 128;

   static const int kJSObjectType = 0xaa;
   static const int kFirstNonstringType = 0x80;
@@ -4219,6 +4221,15 @@
 #endif
   return static_cast<String*>(value);
 }
+
+
+Local<String> String::Empty(Isolate* isolate) {
+  typedef internal::Object* S;
+  typedef internal::Internals I;
+  if (!I::IsInitialized(isolate)) return Empty();
+  S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex);
+  return Local<String>(reinterpret_cast<String*>(slot));
+}


 String::ExternalStringResource* String::GetExternalStringResource() const {
=======================================
--- /branches/bleeding_edge/src/api.cc  Tue Apr 24 07:37:53 2012
+++ /branches/bleeding_edge/src/api.cc  Wed Apr 25 01:45:45 2012
@@ -4630,7 +4630,9 @@

 Local<String> v8::String::Empty() {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::String::Empty()");
+  if (!EnsureInitializedForIsolate(isolate, "v8::String::Empty()")) {
+    return v8::Local<String>();
+  }
   LOG_API(isolate, "String::Empty()");
   return Utils::ToLocal(isolate->factory()->empty_symbol());
 }
=======================================
--- /branches/bleeding_edge/src/heap.h  Mon Apr 23 08:09:59 2012
+++ /branches/bleeding_edge/src/heap.h  Wed Apr 25 01:45:45 2012
@@ -1423,6 +1423,7 @@
   STATIC_CHECK(kNullValueRootIndex == Internals::kNullValueRootIndex);
   STATIC_CHECK(kTrueValueRootIndex == Internals::kTrueValueRootIndex);
   STATIC_CHECK(kFalseValueRootIndex == Internals::kFalseValueRootIndex);
+  STATIC_CHECK(kempty_symbolRootIndex == Internals::kEmptySymbolRootIndex);

   MUST_USE_RESULT MaybeObject* NumberToString(
       Object* number, bool check_number_string_cache = true);
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Tue Apr 24 07:37:53 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Wed Apr 25 01:45:45 2012
@@ -16448,6 +16448,13 @@
 TEST(PrimaryStubCache) {
   StubCacheHelper(false);
 }
+
+
+static int fatal_error_callback_counter = 0;
+static void CountingErrorCallback(const char* location, const char* message) {
+  printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
+  fatal_error_callback_counter++;
+}


 TEST(StaticGetters) {
@@ -16466,24 +16473,12 @@
   i::Handle<i::Object> false_value = FACTORY->false_value();
   CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value);
   CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value);
-}
-
-
-static int fatal_error_callback_counter = 0;
-static void CountingErrorCallback(const char* location, const char* message) {
-  printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
-  fatal_error_callback_counter++;
-}
-
-
-TEST(StaticGettersAfterDeath) {
-  v8::HandleScope scope;
-  LocalContext context;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
+
+  // Test after-death behavior.
   CHECK(i::Internals::IsInitialized(isolate));
   CHECK_EQ(0, fatal_error_callback_counter);
   v8::V8::SetFatalErrorHandler(CountingErrorCallback);
-  v8::Utils::ReportApiFailure("StaticGettersAfterDeath()", "Kill V8");
+  v8::Utils::ReportApiFailure("StaticGetters()", "Kill V8");
   i::Isolate::Current()->TearDown();
   CHECK(!i::Internals::IsInitialized(isolate));
   CHECK_EQ(1, fatal_error_callback_counter);
@@ -16522,3 +16517,26 @@
   CHECK_EQ(data2, isolate->GetData());
   CHECK_EQ(data2, ISOLATE->GetData());
 }
+
+
+TEST(StringEmpty) {
+  v8::HandleScope scope;
+  LocalContext context;
+  v8::Isolate* isolate = v8::Isolate::GetCurrent();
+  i::Handle<i::Object> empty_string = FACTORY->empty_symbol();
+  CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
+ CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
+
+  // Test after-death behavior.
+  CHECK(i::Internals::IsInitialized(isolate));
+  CHECK_EQ(0, fatal_error_callback_counter);
+  v8::V8::SetFatalErrorHandler(CountingErrorCallback);
+  v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8");
+  i::Isolate::Current()->TearDown();
+  CHECK(!i::Internals::IsInitialized(isolate));
+  CHECK_EQ(1, fatal_error_callback_counter);
+  CHECK(v8::String::Empty().IsEmpty());
+  CHECK_EQ(2, fatal_error_callback_counter);
+  CHECK(v8::String::Empty(isolate).IsEmpty());
+  CHECK_EQ(3, fatal_error_callback_counter);
+}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to