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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.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 4139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4150 kNativeCallInExtensionSource)); 4150 kNativeCallInExtensionSource));
4151 const char* extension_names[] = { "nativecall" }; 4151 const char* extension_names[] = { "nativecall" };
4152 v8::ExtensionConfiguration extensions(1, extension_names); 4152 v8::ExtensionConfiguration extensions(1, extension_names);
4153 v8::Handle<Context> context = Context::New(&extensions); 4153 v8::Handle<Context> context = Context::New(&extensions);
4154 Context::Scope lock(context); 4154 Context::Scope lock(context);
4155 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 4155 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run();
4156 CHECK_EQ(result, v8::Integer::New(3)); 4156 CHECK_EQ(result, v8::Integer::New(3));
4157 } 4157 }
4158 4158
4159 4159
4160 class NativeFunctionExtension : public Extension {
4161 public:
4162 NativeFunctionExtension(const char* name,
4163 const char* source,
4164 v8::InvocationCallback fun = &Echo)
4165 : Extension(name, source),
4166 function_(fun) { }
4167
4168 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
4169 v8::Handle<v8::String> name) {
4170 return v8::FunctionTemplate::New(function_);
4171 }
4172
4173 static v8::Handle<v8::Value> Echo(const v8::Arguments& args) {
4174 if (args.Length() >= 1) return (args[0]);
4175 return v8::Undefined();
4176 }
4177 private:
4178 v8::InvocationCallback function_;
4179 };
4180
4181
4182 THREADED_TEST(NativeFunctionDeclaration) {
4183 v8::HandleScope handle_scope;
4184 const char* name = "nativedecl";
4185 v8::RegisterExtension(new NativeFunctionExtension(name,
4186 "native function foo();"));
4187 const char* extension_names[] = { name };
4188 v8::ExtensionConfiguration extensions(1, extension_names);
4189 v8::Handle<Context> context = Context::New(&extensions);
4190 Context::Scope lock(context);
4191 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run();
4192 CHECK_EQ(result, v8::Integer::New(42));
4193 }
4194
4195
4196 THREADED_TEST(NativeFunctionDeclarationError) {
4197 v8::HandleScope handle_scope;
4198 const char* name = "nativedecl";
4199 // Syntax error in extension code.
4200 v8::RegisterExtension(new NativeFunctionExtension(name,
4201 "native\nfunction foo();"));
4202 const char* extension_names[] = { name };
4203 v8::ExtensionConfiguration extensions(1, extension_names);
4204 v8::Handle<Context> context = Context::New(&extensions);
4205 ASSERT(context.IsEmpty());
4206 }
4207
4208 THREADED_TEST(NativeFunctionDeclarationErrorEscape) {
4209 v8::HandleScope handle_scope;
4210 const char* name = "nativedecl";
4211 // Syntax error in extension code - escape code in "native" means that
4212 // it's not treated as a keyword.
4213 v8::RegisterExtension(new NativeFunctionExtension(
4214 name,
4215 "nativ\\u0065 function foo();"));
4216 const char* extension_names[] = { name };
4217 v8::ExtensionConfiguration extensions(1, extension_names);
4218 v8::Handle<Context> context = Context::New(&extensions);
4219 ASSERT(context.IsEmpty());
4220 }
4221
4222
4160 static void CheckDependencies(const char* name, const char* expected) { 4223 static void CheckDependencies(const char* name, const char* expected) {
4161 v8::HandleScope handle_scope; 4224 v8::HandleScope handle_scope;
4162 v8::ExtensionConfiguration config(1, &name); 4225 v8::ExtensionConfiguration config(1, &name);
4163 LocalContext context(&config); 4226 LocalContext context(&config);
4164 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); 4227 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded")));
4165 } 4228 }
4166 4229
4167 4230
4168 /* 4231 /*
4169 * Configuration: 4232 * Configuration:
(...skipping 10326 matching lines...) Expand 10 before | Expand all | Expand 10 after
14496 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 14559 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
14497 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 14560 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
14498 obj->Set(v8_num(2), v8_str("foobar")); 14561 obj->Set(v8_num(2), v8_str("foobar"));
14499 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 14562 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
14500 14563
14501 // Test non-smi case. 14564 // Test non-smi case.
14502 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 14565 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
14503 obj->Set(v8_str("2000000000"), v8_str("foobar")); 14566 obj->Set(v8_str("2000000000"), v8_str("foobar"));
14504 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); 14567 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000")));
14505 } 14568 }
OLDNEW
« 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