Fix edge case of extension with NULL as source string.

BUG=144649

Review URL: https://chromiumcodereview.appspot.com/10914201

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12485 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2012-09-11 14:16:56 +00:00
parent bff3d2a8a6
commit 59b9a32b34
4 changed files with 23 additions and 2 deletions

View File

@ -541,7 +541,9 @@ Extension::Extension(const char* name,
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() {

View File

@ -7386,7 +7386,7 @@ class String: public HeapObject {
#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;
}

View File

@ -4671,6 +4671,18 @@ THREADED_TEST(SimpleExtensions) {
}
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 =
"function Ret54321(){return 54321;}~~@@$"
"$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";

View File

@ -11,6 +11,7 @@
#include "api.h"
#include "factory.h"
#include "objects.h"
#include "cctest.h"
#include "zone-inl.h"
@ -708,3 +709,9 @@ TEST(StringReplaceAtomTwoByteResult) {
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));
}