Revision: 12485
Author:   [email protected]
Date:     Tue Sep 11 07:16:56 2012
Log:      Fix edge case of extension with NULL as source string.

BUG=144649

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

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/test/cctest/test-api.cc
 /branches/bleeding_edge/test/cctest/test-strings.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Mon Sep 10 02:24:17 2012
+++ /branches/bleeding_edge/src/api.cc  Tue Sep 11 07:16:56 2012
@@ -541,7 +541,9 @@
       source_(source, source_length_),
       dep_count_(dep_count),
       deps_(deps),
-      auto_enable_(false) { }
+      auto_enable_(false) {
+  CHECK(source != NULL || source_length_ == 0);
+}


 v8::Handle<Primitive> Undefined() {
=======================================
--- /branches/bleeding_edge/src/objects.h       Mon Sep 10 06:38:21 2012
+++ /branches/bleeding_edge/src/objects.h       Tue Sep 11 07:16:56 2012
@@ -7386,7 +7386,7 @@
 #ifdef V8_HOST_CAN_READ_UNALIGNED
     ASSERT(kMaxAsciiCharCode == 0x7F);
     const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
-    while (chars <= limit - sizeof(uintptr_t)) {
+    while (chars + sizeof(uintptr_t) <= limit) {
       if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
         return false;
       }
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Thu Sep  6 04:05:40 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Sep 11 07:16:56 2012
@@ -4669,6 +4669,18 @@
   v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
   CHECK_EQ(result, v8::Integer::New(4));
 }
+
+
+THREADED_TEST(NullExtensions) {
+  v8::HandleScope handle_scope;
+  v8::RegisterExtension(new Extension("nulltest", NULL));
+  const char* extension_names[] = { "nulltest" };
+  v8::ExtensionConfiguration extensions(1, extension_names);
+  v8::Handle<Context> context = Context::New(&extensions);
+  Context::Scope lock(context);
+  v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run();
+  CHECK_EQ(result, v8::Integer::New(4));
+}


 static const char* kEmbeddedExtensionSource =
=======================================
--- /branches/bleeding_edge/test/cctest/test-strings.cc Tue Aug 28 02:37:41 2012 +++ /branches/bleeding_edge/test/cctest/test-strings.cc Tue Sep 11 07:16:56 2012
@@ -11,6 +11,7 @@

 #include "api.h"
 #include "factory.h"
+#include "objects.h"
 #include "cctest.h"
 #include "zone-inl.h"

@@ -708,3 +709,9 @@
   v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80");
   CHECK(expected->Equals(result));
 }
+
+
+TEST(IsAscii) {
+  CHECK(String::IsAscii(static_cast<char*>(NULL), 0));
+  CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0));
+}

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

Reply via email to