Reviewers: marja, Sven Panne,

Description:
Remove IsInitialized checks from inlined API functions.

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

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M include/v8.h
  M src/api.cc
  M src/isolate.cc
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 9ddde5294b168900f3c8fbf318673b978e04a4a9..e0bdcb0c7a0e0d36671b67f16210947870cac6c8 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5326,6 +5326,8 @@ class Internals {
   static const int kUndefinedOddballKind = 5;
   static const int kNullOddballKind = 3;

+  static void CheckInitialized(v8::Isolate* isolate);
+
   V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) {
     return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
             kHeapObjectTag);
@@ -5359,11 +5361,6 @@ class Internals {
     return representation == kExternalTwoByteRepresentationTag;
   }

-  V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) {
- uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
-    return *reinterpret_cast<int*>(addr) == 1;
-  }
-
V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) {
       uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
       return *addr & (1 << shift);
@@ -5939,7 +5936,9 @@ String* String::Cast(v8::Value* value) {
 Local<String> String::Empty(Isolate* isolate) {
   typedef internal::Object* S;
   typedef internal::Internals I;
-  if (!I::IsInitialized(isolate)) return Empty();
+#ifdef V8_ENABLE_CHECKS
+  I::CheckInitialized(isolate);
+#endif
   S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
   return Local<String>(reinterpret_cast<String*>(slot));
 }
@@ -6292,7 +6291,9 @@ ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
 Handle<Primitive> Undefined(Isolate* isolate) {
   typedef internal::Object* S;
   typedef internal::Internals I;
-  if (!I::IsInitialized(isolate)) return Undefined();
+#ifdef V8_ENABLE_CHECKS
+  I::CheckInitialized(isolate);
+#endif
   S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
   return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
 }
@@ -6301,7 +6302,9 @@ Handle<Primitive> Undefined(Isolate* isolate) {
 Handle<Primitive> Null(Isolate* isolate) {
   typedef internal::Object* S;
   typedef internal::Internals I;
-  if (!I::IsInitialized(isolate)) return Null();
+#ifdef V8_ENABLE_CHECKS
+  I::CheckInitialized(isolate);
+#endif
   S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
   return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
 }
@@ -6310,7 +6313,9 @@ Handle<Primitive> Null(Isolate* isolate) {
 Handle<Boolean> True(Isolate* isolate) {
   typedef internal::Object* S;
   typedef internal::Internals I;
-  if (!I::IsInitialized(isolate)) return True();
+#ifdef V8_ENABLE_CHECKS
+  I::CheckInitialized(isolate);
+#endif
   S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
   return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
 }
@@ -6319,7 +6324,9 @@ Handle<Boolean> True(Isolate* isolate) {
 Handle<Boolean> False(Isolate* isolate) {
   typedef internal::Object* S;
   typedef internal::Internals I;
-  if (!I::IsInitialized(isolate)) return False();
+#ifdef V8_ENABLE_CHECKS
+  I::CheckInitialized(isolate);
+#endif
   S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
   return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
 }
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index ee9e03f119a79e431c887f18e37804d9c9991021..ad717be2b944b9f3e567a978f26decb826336340 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2893,6 +2893,14 @@ Local<Integer> Value::ToInteger() const {
 }


+void i::Internals::CheckInitialized(v8::Isolate* external_isolate) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
+  ApiCheck(isolate != NULL && isolate->IsInitialized() && !i::V8::IsDead(),
+           "v8::internal::Internals::CheckInitialized()",
+           "Isolate is not initialized or V8 has died");
+}
+
+
 void External::CheckCast(v8::Value* that) {
   if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return;
   ApiCheck(Utils::OpenHandle(that)->IsExternal(),
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 17e80172c539890684eb2dc528795ebfadf20bd8..564fd7b64638694ba978725aa5776995a678f61a 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -2216,8 +2216,6 @@ bool Isolate::Init(Deserializer* des) {
     LOG(this, LogCompiledFunctions());
   }

-  CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, state_)),
-           Internals::kIsolateStateOffset);
   CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)),
            Internals::kIsolateEmbedderDataOffset);
   CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)),
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a07d528e7276cb39cf7b5b3f8595dcaaf0249054..a59d44a98b7877a1a78c98f2d99d8d4878d941fc 100755
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -18782,13 +18782,6 @@ TEST(PrimaryStubCache) {
 }


-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) {
   LocalContext context;
   i::Factory* factory = i::Isolate::Current()->factory();
@@ -18806,31 +18799,6 @@ TEST(StaticGetters) {
   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);
-
-  // Test after-death behavior.
-  CHECK(i::Internals::IsInitialized(isolate));
-  CHECK_EQ(0, fatal_error_callback_counter);
-  v8::V8::SetFatalErrorHandler(CountingErrorCallback);
-  v8::Utils::ReportApiFailure("StaticGetters()", "Kill V8");
-  i::Isolate::Current()->TearDown();
-  CHECK(!i::Internals::IsInitialized(isolate));
-  CHECK_EQ(1, fatal_error_callback_counter);
-  CHECK(v8::Undefined().IsEmpty());
-  CHECK_EQ(2, fatal_error_callback_counter);
-  CHECK(v8::Undefined(isolate).IsEmpty());
-  CHECK_EQ(3, fatal_error_callback_counter);
-  CHECK(v8::Null().IsEmpty());
-  CHECK_EQ(4, fatal_error_callback_counter);
-  CHECK(v8::Null(isolate).IsEmpty());
-  CHECK_EQ(5, fatal_error_callback_counter);
-  CHECK(v8::True().IsEmpty());
-  CHECK_EQ(6, fatal_error_callback_counter);
-  CHECK(v8::True(isolate).IsEmpty());
-  CHECK_EQ(7, fatal_error_callback_counter);
-  CHECK(v8::False().IsEmpty());
-  CHECK_EQ(8, fatal_error_callback_counter);
-  CHECK(v8::False(isolate).IsEmpty());
-  CHECK_EQ(9, fatal_error_callback_counter);
 }


@@ -18860,19 +18828,6 @@ TEST(StringEmpty) {
   i::Handle<i::Object> empty_string = factory->empty_string();
   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
--- 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