Make check in GetExternalString a runtime check instead of ASSERT.
authordavemoore@chromium.org <davemoore@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 6 May 2009 18:30:37 +0000 (18:30 +0000)
committerdavemoore@chromium.org <davemoore@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 6 May 2009 18:30:37 +0000 (18:30 +0000)
This will allow us to remove the separate call to IsExternal() from our
chrome client code, speeding up the combination.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1887 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/api.cc

index 2e5d679..9f59e4e 100644 (file)
@@ -827,14 +827,14 @@ class V8EXPORT String : public Primitive {
   };
 
   /**
-   * Get the ExternalStringResource for an external string.  Only
-   * valid if IsExternal() returns true.
+   * Get the ExternalStringResource for an external string.  Returns
+   * NULL if IsExternal() doesn't return true.
    */
   ExternalStringResource* GetExternalStringResource() const;
 
   /**
    * Get the ExternalAsciiStringResource for an external ascii string.
-   * Only valid if IsExternalAscii() returns true.
+   * Returns NULL if IsExternalAscii() doesn't return true.
    */
   ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
 
index 793e10f..c250412 100644 (file)
@@ -2355,9 +2355,12 @@ v8::String::ExternalStringResource*
 v8::String::GetExternalStringResource() const {
   EnsureInitialized("v8::String::GetExternalStringResource()");
   i::Handle<i::String> str = Utils::OpenHandle(this);
-  ASSERT(str->IsExternalTwoByteString());
-  void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource();
-  return reinterpret_cast<ExternalStringResource*>(resource);
+  if (i::StringShape(*str).IsExternalTwoByte()) {
+    void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource();
+    return reinterpret_cast<ExternalStringResource*>(resource);
+  } else {
+    return NULL;
+  }
 }
 
 
@@ -2365,9 +2368,12 @@ v8::String::ExternalAsciiStringResource*
       v8::String::GetExternalAsciiStringResource() const {
   EnsureInitialized("v8::String::GetExternalAsciiStringResource()");
   i::Handle<i::String> str = Utils::OpenHandle(this);
-  ASSERT(str->IsExternalAsciiString());
-  void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource();
-  return reinterpret_cast<ExternalAsciiStringResource*>(resource);
+  if (i::StringShape(*str).IsExternalAscii()) {
+    void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource();
+    return reinterpret_cast<ExternalAsciiStringResource*>(resource);
+  } else {
+    return NULL;
+  }
 }