Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1290)

Side by Side Diff: test/cctest/test-api.cc

Issue 7889046: Add an optional source length field to the Extension constructor. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4259 matching lines...) Expand 10 before | Expand all | Expand 10 after
4270 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 4270 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
4271 const char* extension_names[] = { "simpletest" }; 4271 const char* extension_names[] = { "simpletest" };
4272 v8::ExtensionConfiguration extensions(1, extension_names); 4272 v8::ExtensionConfiguration extensions(1, extension_names);
4273 v8::Handle<Context> context = Context::New(&extensions); 4273 v8::Handle<Context> context = Context::New(&extensions);
4274 Context::Scope lock(context); 4274 Context::Scope lock(context);
4275 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 4275 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
4276 CHECK_EQ(result, v8::Integer::New(4)); 4276 CHECK_EQ(result, v8::Integer::New(4));
4277 } 4277 }
4278 4278
4279 4279
4280 static const char* kEmbeddedExtensionSource =
4281 "function Ret54321(){return 54321;}~~@@$"
4282 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
4283 static const int kEmbeddedExtensionSourceValidLen = 34;
4284
4285
4286 THREADED_TEST(ExtensionMissingSourceLength) {
4287 v8::HandleScope handle_scope;
4288 v8::RegisterExtension(new Extension("srclentest_fail",
4289 kEmbeddedExtensionSource));
4290 const char* extension_names[] = { "srclentest_fail" };
4291 v8::ExtensionConfiguration extensions(1, extension_names);
4292 v8::Handle<Context> context = Context::New(&extensions);
4293 CHECK_EQ(0, *context);
4294 }
4295
4296
4297 THREADED_TEST(ExtensionWithSourceLength) {
4298 for (int source_len = kEmbeddedExtensionSourceValidLen - 1;
4299 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
4300 v8::HandleScope handle_scope;
4301 char extension_name[32];
4302 snprintf(extension_name, sizeof(extension_name), "ext #%d", source_len);
4303 v8::RegisterExtension(new Extension(extension_name,
4304 kEmbeddedExtensionSource, 0, 0,
4305 source_len));
4306 const char* extension_names[1] = { extension_name };
4307 v8::ExtensionConfiguration extensions(1, extension_names);
4308 v8::Handle<Context> context = Context::New(&extensions);
4309 if (source_len == kEmbeddedExtensionSourceValidLen) {
4310 Context::Scope lock(context);
4311 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run();
4312 CHECK_EQ(v8::Integer::New(54321), result);
4313 } else {
4314 // Anything but exactly the right length should fail to compile.
4315 CHECK_EQ(0, *context);
4316 }
4317 }
4318 }
4319
4320
4280 static const char* kEvalExtensionSource1 = 4321 static const char* kEvalExtensionSource1 =
4281 "function UseEval1() {" 4322 "function UseEval1() {"
4282 " var x = 42;" 4323 " var x = 42;"
4283 " return eval('x');" 4324 " return eval('x');"
4284 "}"; 4325 "}";
4285 4326
4286 4327
4287 static const char* kEvalExtensionSource2 = 4328 static const char* kEvalExtensionSource2 =
4288 "(function() {" 4329 "(function() {"
4289 " var x = 42;" 4330 " var x = 42;"
(...skipping 10857 matching lines...) Expand 10 before | Expand all | Expand 10 after
15147 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 15188 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
15148 15189
15149 // TODO(1547): Make the following also return "i". 15190 // TODO(1547): Make the following also return "i".
15150 // Calling with environment record as base. 15191 // Calling with environment record as base.
15151 TestReceiver(o, context->Global(), "func()"); 15192 TestReceiver(o, context->Global(), "func()");
15152 // Calling with no base. 15193 // Calling with no base.
15153 TestReceiver(o, context->Global(), "(1,func)()"); 15194 TestReceiver(o, context->Global(), "(1,func)()");
15154 15195
15155 foreign_context.Dispose(); 15196 foreign_context.Dispose();
15156 } 15197 }
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698