OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2488 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); | 2488 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); |
2489 const char* extension_names[] = { "simpletest" }; | 2489 const char* extension_names[] = { "simpletest" }; |
2490 v8::ExtensionConfiguration extensions(1, extension_names); | 2490 v8::ExtensionConfiguration extensions(1, extension_names); |
2491 v8::Handle<Context> context = Context::New(&extensions); | 2491 v8::Handle<Context> context = Context::New(&extensions); |
2492 Context::Scope lock(context); | 2492 Context::Scope lock(context); |
2493 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 2493 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
2494 CHECK_EQ(result, v8::Integer::New(4)); | 2494 CHECK_EQ(result, v8::Integer::New(4)); |
2495 } | 2495 } |
2496 | 2496 |
2497 | 2497 |
| 2498 static const char* kEvalExtensionSource = |
| 2499 "function UseEval() {" |
| 2500 " var x = 42;" |
| 2501 " return eval('x');" |
| 2502 "}"; |
| 2503 |
| 2504 |
| 2505 THREADED_TEST(UseEvalFromExtension) { |
| 2506 v8::HandleScope handle_scope; |
| 2507 v8::RegisterExtension(new Extension("evaltest", kEvalExtensionSource)); |
| 2508 const char* extension_names[] = { "evaltest" }; |
| 2509 v8::ExtensionConfiguration extensions(1, extension_names); |
| 2510 v8::Handle<Context> context = Context::New(&extensions); |
| 2511 Context::Scope lock(context); |
| 2512 v8::Handle<Value> result = Script::Compile(v8_str("UseEval()"))->Run(); |
| 2513 CHECK_EQ(result, v8::Integer::New(42)); |
| 2514 } |
| 2515 |
| 2516 |
| 2517 static const char* kWithExtensionSource = |
| 2518 "function UseWith() {" |
| 2519 " var x = 42;" |
| 2520 " with({x:87}) { return x; }" |
| 2521 "}"; |
| 2522 |
| 2523 |
| 2524 THREADED_TEST(UseWithFromExtension) { |
| 2525 v8::HandleScope handle_scope; |
| 2526 v8::RegisterExtension(new Extension("withtest", kWithExtensionSource)); |
| 2527 const char* extension_names[] = { "withtest" }; |
| 2528 v8::ExtensionConfiguration extensions(1, extension_names); |
| 2529 v8::Handle<Context> context = Context::New(&extensions); |
| 2530 Context::Scope lock(context); |
| 2531 v8::Handle<Value> result = Script::Compile(v8_str("UseWith()"))->Run(); |
| 2532 CHECK_EQ(result, v8::Integer::New(87)); |
| 2533 } |
| 2534 |
| 2535 |
2498 THREADED_TEST(AutoExtensions) { | 2536 THREADED_TEST(AutoExtensions) { |
2499 v8::HandleScope handle_scope; | 2537 v8::HandleScope handle_scope; |
2500 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 2538 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
2501 extension->set_auto_enable(true); | 2539 extension->set_auto_enable(true); |
2502 v8::RegisterExtension(extension); | 2540 v8::RegisterExtension(extension); |
2503 v8::Handle<Context> context = Context::New(); | 2541 v8::Handle<Context> context = Context::New(); |
2504 Context::Scope lock(context); | 2542 Context::Scope lock(context); |
2505 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 2543 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
2506 CHECK_EQ(result, v8::Integer::New(4)); | 2544 CHECK_EQ(result, v8::Integer::New(4)); |
2507 } | 2545 } |
(...skipping 3634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6142 // Check without 'eval' or 'with'. | 6180 // Check without 'eval' or 'with'. |
6143 v8::Handle<v8::Value> res = | 6181 v8::Handle<v8::Value> res = |
6144 CompileRun("function f() { x = 42; return x; }; f()"); | 6182 CompileRun("function f() { x = 42; return x; }; f()"); |
6145 // Check with 'eval'. | 6183 // Check with 'eval'. |
6146 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); | 6184 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); |
6147 CHECK_EQ(v8::Integer::New(42), res); | 6185 CHECK_EQ(v8::Integer::New(42), res); |
6148 // Check with 'with'. | 6186 // Check with 'with'. |
6149 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); | 6187 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); |
6150 CHECK_EQ(v8::Integer::New(42), res); | 6188 CHECK_EQ(v8::Integer::New(42), res); |
6151 } | 6189 } |
OLD | NEW |