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

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

Issue 7978028: Landing for miket@chromium.org: 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 4275 matching lines...) Expand 10 before | Expand all | Expand 10 after
4286 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 4286 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
4287 const char* extension_names[] = { "simpletest" }; 4287 const char* extension_names[] = { "simpletest" };
4288 v8::ExtensionConfiguration extensions(1, extension_names); 4288 v8::ExtensionConfiguration extensions(1, extension_names);
4289 v8::Handle<Context> context = Context::New(&extensions); 4289 v8::Handle<Context> context = Context::New(&extensions);
4290 Context::Scope lock(context); 4290 Context::Scope lock(context);
4291 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 4291 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
4292 CHECK_EQ(result, v8::Integer::New(4)); 4292 CHECK_EQ(result, v8::Integer::New(4));
4293 } 4293 }
4294 4294
4295 4295
4296 static const char* kEmbeddedExtensionSource =
4297 "function Ret54321(){return 54321;}~~@@$"
4298 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
4299 static const int kEmbeddedExtensionSourceValidLen = 34;
4300
4301
4302 THREADED_TEST(ExtensionMissingSourceLength) {
4303 v8::HandleScope handle_scope;
4304 v8::RegisterExtension(new Extension("srclentest_fail",
4305 kEmbeddedExtensionSource));
4306 const char* extension_names[] = { "srclentest_fail" };
4307 v8::ExtensionConfiguration extensions(1, extension_names);
4308 v8::Handle<Context> context = Context::New(&extensions);
4309 CHECK_EQ(0, *context);
4310 }
4311
4312
4313 THREADED_TEST(ExtensionWithSourceLength) {
4314 for (int source_len = kEmbeddedExtensionSourceValidLen - 1;
4315 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
4316 v8::HandleScope handle_scope;
4317 char extension_name[32];
4318 snprintf(extension_name, sizeof(extension_name), "ext #%d", source_len);
4319 v8::RegisterExtension(new Extension(extension_name,
4320 kEmbeddedExtensionSource, 0, 0,
4321 source_len));
4322 const char* extension_names[1] = { extension_name };
4323 v8::ExtensionConfiguration extensions(1, extension_names);
4324 v8::Handle<Context> context = Context::New(&extensions);
4325 if (source_len == kEmbeddedExtensionSourceValidLen) {
4326 Context::Scope lock(context);
4327 v8::Handle<Value> result = Script::Compile(v8_str("Ret54321()"))->Run();
4328 CHECK_EQ(v8::Integer::New(54321), result);
4329 } else {
4330 // Anything but exactly the right length should fail to compile.
4331 CHECK_EQ(0, *context);
4332 }
4333 }
4334 }
4335
4336
4296 static const char* kEvalExtensionSource1 = 4337 static const char* kEvalExtensionSource1 =
4297 "function UseEval1() {" 4338 "function UseEval1() {"
4298 " var x = 42;" 4339 " var x = 42;"
4299 " return eval('x');" 4340 " return eval('x');"
4300 "}"; 4341 "}";
4301 4342
4302 4343
4303 static const char* kEvalExtensionSource2 = 4344 static const char* kEvalExtensionSource2 =
4304 "(function() {" 4345 "(function() {"
4305 " var x = 42;" 4346 " var x = 42;"
(...skipping 10862 matching lines...) Expand 10 before | Expand all | Expand 10 after
15168 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 15209 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
15169 15210
15170 // TODO(1547): Make the following also return "i". 15211 // TODO(1547): Make the following also return "i".
15171 // Calling with environment record as base. 15212 // Calling with environment record as base.
15172 TestReceiver(o, context->Global(), "func()"); 15213 TestReceiver(o, context->Global(), "func()");
15173 // Calling with no base. 15214 // Calling with no base.
15174 TestReceiver(o, context->Global(), "(1,func)()"); 15215 TestReceiver(o, context->Global(), "(1,func)()");
15175 15216
15176 foreign_context.Dispose(); 15217 foreign_context.Dispose();
15177 } 15218 }
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