OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/cctest/compiler/function-tester.h" | 5 #include "test/cctest/compiler/function-tester.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace compiler { | 9 namespace compiler { |
10 | 10 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 // Disable context specialization. | 208 // Disable context specialization. |
209 FunctionTester T(script); | 209 FunctionTester T(script); |
210 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 210 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
211 v8::Context::Scope scope(context); | 211 v8::Context::Scope scope(context); |
212 v8::Local<v8::Value> value = CompileRun(script); | 212 v8::Local<v8::Value> value = CompileRun(script); |
213 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 213 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
214 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 214 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
215 jsfun->set_code(T.function->code()); | 215 jsfun->set_code(T.function->code()); |
216 jsfun->set_shared(T.function->shared()); | 216 jsfun->set_shared(T.function->shared()); |
217 jsfun->set_literals(T.function->literals()); | |
218 CHECK(context->Global() | 217 CHECK(context->Global() |
219 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) | 218 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) |
220 .FromJust()); | 219 .FromJust()); |
221 CompileRun("var x = 24;"); | 220 CompileRun("var x = 24;"); |
222 ExpectInt32("foo();", 24); | 221 ExpectInt32("foo();", 24); |
223 } | 222 } |
224 | 223 |
225 | 224 |
226 TEST(BuiltinLoadedFromActivation) { | 225 TEST(BuiltinLoadedFromActivation) { |
227 const char* script = | 226 const char* script = |
228 "var x = 42;" | 227 "var x = 42;" |
229 "(function() {" | 228 "(function() {" |
230 " return function () { return this; };" | 229 " return function () { return this; };" |
231 "})()"; | 230 "})()"; |
232 | 231 |
233 // Disable context specialization. | 232 // Disable context specialization. |
234 FunctionTester T(script); | 233 FunctionTester T(script); |
235 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 234 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
236 v8::Context::Scope scope(context); | 235 v8::Context::Scope scope(context); |
237 v8::Local<v8::Value> value = CompileRun(script); | 236 v8::Local<v8::Value> value = CompileRun(script); |
238 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 237 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
239 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 238 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
240 jsfun->set_code(T.function->code()); | 239 jsfun->set_code(T.function->code()); |
241 jsfun->set_shared(T.function->shared()); | 240 jsfun->set_shared(T.function->shared()); |
242 jsfun->set_literals(T.function->literals()); | |
243 CHECK(context->Global() | 241 CHECK(context->Global() |
244 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) | 242 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) |
245 .FromJust()); | 243 .FromJust()); |
246 CompileRun("var x = 24;"); | 244 CompileRun("var x = 24;"); |
247 ExpectObject("foo()", context->Global()); | 245 ExpectObject("foo()", context->Global()); |
248 } | 246 } |
249 | 247 |
250 } // namespace compiler | 248 } // namespace compiler |
251 } // namespace internal | 249 } // namespace internal |
252 } // namespace v8 | 250 } // namespace v8 |
OLD | NEW |