| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 using ::v8::Value; | 63 using ::v8::Value; |
| 64 | 64 |
| 65 static void ExpectInt32(int32_t expected, Local<Value> result) { | 65 static void ExpectInt32(int32_t expected, Local<Value> result) { |
| 66 CHECK(result->IsInt32()); | 66 CHECK(result->IsInt32()); |
| 67 CHECK_EQ(expected, result->Int32Value()); | 67 CHECK_EQ(expected, result->Int32Value()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 // Global variables. | 71 // Global variables. |
| 72 TEST(global_variables) { | 72 TEST(global_variables) { |
| 73 v8::HandleScope scope; | |
| 74 LocalContext env; | 73 LocalContext env; |
| 74 v8::HandleScope scope(env->GetIsolate()); |
| 75 Local<Value> result = CompileRun( | 75 Local<Value> result = CompileRun( |
| 76 "var x = 0;" | 76 "var x = 0;" |
| 77 "function f0() { return x; }" | 77 "function f0() { return x; }" |
| 78 "f0();"); | 78 "f0();"); |
| 79 ExpectInt32(0, result); | 79 ExpectInt32(0, result); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 // Parameters. | 83 // Parameters. |
| 84 TEST(parameters) { | 84 TEST(parameters) { |
| 85 v8::HandleScope scope; | |
| 86 LocalContext env; | 85 LocalContext env; |
| 86 v8::HandleScope scope(env->GetIsolate()); |
| 87 Local<Value> result = CompileRun( | 87 Local<Value> result = CompileRun( |
| 88 "function f1(x) { return x; }" | 88 "function f1(x) { return x; }" |
| 89 "f1(1);"); | 89 "f1(1);"); |
| 90 ExpectInt32(1, result); | 90 ExpectInt32(1, result); |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 // Stack-allocated locals. | 94 // Stack-allocated locals. |
| 95 TEST(stack_allocated_locals) { | 95 TEST(stack_allocated_locals) { |
| 96 v8::HandleScope scope; | |
| 97 LocalContext env; | 96 LocalContext env; |
| 97 v8::HandleScope scope(env->GetIsolate()); |
| 98 Local<Value> result = CompileRun( | 98 Local<Value> result = CompileRun( |
| 99 "function f2() { var x = 2; return x; }" | 99 "function f2() { var x = 2; return x; }" |
| 100 "f2();"); | 100 "f2();"); |
| 101 ExpectInt32(2, result); | 101 ExpectInt32(2, result); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 // Context-allocated locals. Local function forces x into f3's context. | 105 // Context-allocated locals. Local function forces x into f3's context. |
| 106 TEST(context_allocated_locals) { | 106 TEST(context_allocated_locals) { |
| 107 v8::HandleScope scope; | |
| 108 LocalContext env; | 107 LocalContext env; |
| 108 v8::HandleScope scope(env->GetIsolate()); |
| 109 Local<Value> result = CompileRun( | 109 Local<Value> result = CompileRun( |
| 110 "function f3(x) {" | 110 "function f3(x) {" |
| 111 " function g() { return x; }" | 111 " function g() { return x; }" |
| 112 " return x;" | 112 " return x;" |
| 113 "}" | 113 "}" |
| 114 "f3(3);"); | 114 "f3(3);"); |
| 115 ExpectInt32(3, result); | 115 ExpectInt32(3, result); |
| 116 } | 116 } |
| 117 | 117 |
| 118 | 118 |
| 119 // Local function reads x from an outer context. | 119 // Local function reads x from an outer context. |
| 120 TEST(read_from_outer_context) { | 120 TEST(read_from_outer_context) { |
| 121 v8::HandleScope scope; | |
| 122 LocalContext env; | 121 LocalContext env; |
| 122 v8::HandleScope scope(env->GetIsolate()); |
| 123 Local<Value> result = CompileRun( | 123 Local<Value> result = CompileRun( |
| 124 "function f4(x) {" | 124 "function f4(x) {" |
| 125 " function g() { return x; }" | 125 " function g() { return x; }" |
| 126 " return g();" | 126 " return g();" |
| 127 "}" | 127 "}" |
| 128 "f4(4);"); | 128 "f4(4);"); |
| 129 ExpectInt32(4, result); | 129 ExpectInt32(4, result); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 // Local function reads x from an outer context. | 133 // Local function reads x from an outer context. |
| 134 TEST(lookup_slots) { | 134 TEST(lookup_slots) { |
| 135 v8::HandleScope scope; | |
| 136 LocalContext env; | 135 LocalContext env; |
| 136 v8::HandleScope scope(env->GetIsolate()); |
| 137 Local<Value> result = CompileRun( | 137 Local<Value> result = CompileRun( |
| 138 "function f5(x) {" | 138 "function f5(x) {" |
| 139 " with ({}) return x;" | 139 " with ({}) return x;" |
| 140 "}" | 140 "}" |
| 141 "f5(5);"); | 141 "f5(5);"); |
| 142 ExpectInt32(5, result); | 142 ExpectInt32(5, result); |
| 143 } | 143 } |
| OLD | NEW |