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

Unified Diff: test/cctest/test-api.cc

Issue 7206022: Made parser not accept unicode escapes inside "native" when used as a keyword. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 0b66955c96fdbf758fb8f5bef6624999717e92fc..e0bcbc92cfabfcdace40f8c63937d20167879516 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -4157,6 +4157,69 @@ THREADED_TEST(NativeCallInExtensions) {
}
+class NativeFunctionExtension : public Extension {
+ public:
+ NativeFunctionExtension(const char* name,
+ const char* source,
+ v8::InvocationCallback fun = &Echo)
+ : Extension(name, source),
+ function_(fun) { }
+
+ virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+ v8::Handle<v8::String> name) {
+ return v8::FunctionTemplate::New(function_);
+ }
+
+ static v8::Handle<v8::Value> Echo(const v8::Arguments& args) {
+ if (args.Length() >= 1) return (args[0]);
+ return v8::Undefined();
+ }
+ private:
+ v8::InvocationCallback function_;
+};
+
+
+THREADED_TEST(NativeFunctionDeclaration) {
+ v8::HandleScope handle_scope;
+ const char* name = "nativedecl";
+ v8::RegisterExtension(new NativeFunctionExtension(name,
+ "native function foo();"));
+ const char* extension_names[] = { name };
+ 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("foo(42);"))->Run();
+ CHECK_EQ(result, v8::Integer::New(42));
+}
+
+
+THREADED_TEST(NativeFunctionDeclarationError) {
+ v8::HandleScope handle_scope;
+ const char* name = "nativedecl";
+ // Syntax error in extension code.
+ v8::RegisterExtension(new NativeFunctionExtension(name,
+ "native\nfunction foo();"));
+ const char* extension_names[] = { name };
+ v8::ExtensionConfiguration extensions(1, extension_names);
+ v8::Handle<Context> context = Context::New(&extensions);
+ ASSERT(context.IsEmpty());
+}
+
+THREADED_TEST(NativeFunctionDeclarationErrorEscape) {
+ v8::HandleScope handle_scope;
+ const char* name = "nativedecl";
+ // Syntax error in extension code - escape code in "native" means that
+ // it's not treated as a keyword.
+ v8::RegisterExtension(new NativeFunctionExtension(
+ name,
+ "nativ\\u0065 function foo();"));
+ const char* extension_names[] = { name };
+ v8::ExtensionConfiguration extensions(1, extension_names);
+ v8::Handle<Context> context = Context::New(&extensions);
+ ASSERT(context.IsEmpty());
+}
+
+
static void CheckDependencies(const char* name, const char* expected) {
v8::HandleScope handle_scope;
v8::ExtensionConfiguration config(1, &name);
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698