 Chromium Code Reviews
 Chromium Code Reviews Issue 7889046:
  Add an optional source length field to the Extension constructor.  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
    
  
    Issue 7889046:
  Add an optional source length field to the Extension constructor.  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/| Index: test/cctest/test-api.cc | 
| =================================================================== | 
| --- test/cctest/test-api.cc (revision 9266) | 
| +++ test/cctest/test-api.cc (working copy) | 
| @@ -4277,6 +4277,47 @@ | 
| } | 
| +static const char* kEmbeddedExtensionSource = | 
| + "function Ret54321(){return 54321;}~~@@$" | 
| + "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; | 
| +static const int kEmbeddedExtensionSourceValidLen = 34; | 
| + | 
| + | 
| +THREADED_TEST(ExtensionMissingSourceLength) { | 
| + v8::HandleScope handle_scope; | 
| + v8::RegisterExtension(new Extension("srclentest_fail", | 
| + kEmbeddedExtensionSource)); | 
| + const char* extension_names[] = { "srclentest_fail" }; | 
| + v8::ExtensionConfiguration extensions(1, extension_names); | 
| + v8::Handle<Context> context = Context::New(&extensions); | 
| + CHECK_EQ(0, *context); | 
| +} | 
| + | 
| + | 
| +THREADED_TEST(ExtensionWithSourceLength) { | 
| + for (int source_len = kEmbeddedExtensionSourceValidLen; | 
| 
fschneider
2011/09/19 07:58:57
Why does this loop go from kEmbeddedExtensionSourc
 
miket_OOO
2011/09/19 17:39:21
Thank you for catching this. I have changed the ra
 | 
| + source_len <= kEmbeddedExtensionSourceValidLen; ++source_len) { | 
| + v8::HandleScope handle_scope; | 
| + char extension_name[32]; | 
| + snprintf(extension_name, sizeof(extension_name), "ext #%d", source_len); | 
| + v8::RegisterExtension(new Extension(extension_name, | 
| + kEmbeddedExtensionSource, 0, 0, | 
| + source_len)); | 
| + const char* extension_names[1] = { extension_name }; | 
| + v8::ExtensionConfiguration extensions(1, extension_names); | 
| + v8::Handle<Context> context = Context::New(&extensions); | 
| + if (source_len == kEmbeddedExtensionSourceValidLen) { | 
| + Context::Scope lock(context); | 
| + v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run(); | 
| + CHECK_EQ(v8::Integer::New(54321), result); | 
| + } else { | 
| + // Anything but exactly the right length should fail to compile. | 
| + CHECK_EQ(0, *context); | 
| + } | 
| + } | 
| +} | 
| + | 
| + | 
| static const char* kEvalExtensionSource1 = | 
| "function UseEval1() {" | 
| " var x = 42;" |