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 4000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4011 " if (str.indexOf('#<a Fun>') == -1) return 3;" | 4011 " if (str.indexOf('#<a Fun>') == -1) return 3;" |
4012 " return 0;" | 4012 " return 0;" |
4013 " }" | 4013 " }" |
4014 " return 4;" | 4014 " return 4;" |
4015 "}" | 4015 "}" |
4016 "test();"); | 4016 "test();"); |
4017 CHECK_EQ(0, value->Int32Value()); | 4017 CHECK_EQ(0, value->Int32Value()); |
4018 } | 4018 } |
4019 | 4019 |
4020 | 4020 |
4021 THREADED_TEST(Eval) { | 4021 THREADED_TEST(EvalAliasedDynamic) { |
4022 v8::HandleScope scope; | 4022 v8::HandleScope scope; |
4023 LocalContext current; | 4023 LocalContext current; |
4024 | 4024 |
4025 // Test that un-aliased eval uses local context. | 4025 // This sets 'global' to the real global object (as opposed to the |
| 4026 // proxy). It is highly implementation dependent, so take care. |
| 4027 current->Global()->Set(v8_str("global"), current->Global()->GetPrototype()); |
| 4028 |
| 4029 // Tests where aliased eval can only be resolved dynamically. |
4026 Local<Script> script = | 4030 Local<Script> script = |
4027 Script::Compile(v8_str("foo = 0;" | 4031 Script::Compile(v8_str("function f(x) { " |
4028 "(function() {" | |
4029 " var foo = 2;" | 4032 " var foo = 2;" |
4030 " return eval('foo');" | 4033 " with (x) { return eval('foo'); }" |
4031 "})();")); | 4034 "}" |
4032 Local<Value> result = script->Run(); | 4035 "foo = 0;" |
4033 CHECK_EQ(2, result->Int32Value()); | 4036 "result1 = f(new Object());" |
| 4037 "result2 = f(global);" |
| 4038 "var x = new Object();" |
| 4039 "x.eval = function(x) { return 1; };" |
| 4040 "result3 = f(x);")); |
| 4041 script->Run(); |
| 4042 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value()); |
| 4043 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value()); |
| 4044 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value()); |
4034 | 4045 |
4035 // Test that un-aliased eval has right this. | 4046 v8::TryCatch try_catch; |
4036 script = | 4047 script = |
4037 Script::Compile(v8_str("function MyObject() { this.self = eval('this'); }" | 4048 Script::Compile(v8_str("function f(x) { " |
4038 "var o = new MyObject();" | 4049 " var bar = 2;" |
4039 "o === o.self")); | 4050 " with (x) { return eval('bar'); }" |
4040 result = script->Run(); | 4051 "}" |
4041 CHECK(result->IsTrue()); | 4052 "f(global)")); |
| 4053 script->Run(); |
| 4054 CHECK(try_catch.HasCaught()); |
| 4055 try_catch.Reset(); |
4042 } | 4056 } |
4043 | 4057 |
4044 | 4058 |
4045 THREADED_TEST(CrossEval) { | 4059 THREADED_TEST(CrossEval) { |
4046 v8::HandleScope scope; | 4060 v8::HandleScope scope; |
4047 LocalContext other; | 4061 LocalContext other; |
4048 LocalContext current; | 4062 LocalContext current; |
4049 | 4063 |
4050 Local<String> token = v8_str("<security token>"); | 4064 Local<String> token = v8_str("<security token>"); |
4051 other->SetSecurityToken(token); | 4065 other->SetSecurityToken(token); |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5338 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5352 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
5339 } | 5353 } |
5340 // Test CallIC. | 5354 // Test CallIC. |
5341 for (int i = 0; i < 2; i++) { | 5355 for (int i = 0; i < 2; i++) { |
5342 LocalContext context; | 5356 LocalContext context; |
5343 context->Global()->Set(v8_str("tmp"), v8::True()); | 5357 context->Global()->Set(v8_str("tmp"), v8::True()); |
5344 context->Global()->Delete(v8_str("tmp")); | 5358 context->Global()->Delete(v8_str("tmp")); |
5345 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5359 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
5346 } | 5360 } |
5347 } | 5361 } |
OLD | NEW |