| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 // Disable context specialization. | 212 // Disable context specialization. |
| 213 FunctionTester T(script); | 213 FunctionTester T(script); |
| 214 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 214 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 215 v8::Context::Scope scope(context); | 215 v8::Context::Scope scope(context); |
| 216 v8::Local<v8::Value> value = CompileRun(script); | 216 v8::Local<v8::Value> value = CompileRun(script); |
| 217 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 217 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
| 218 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 218 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
| 219 jsfun->set_code(T.function->code()); | 219 jsfun->set_code(T.function->code()); |
| 220 jsfun->set_shared(T.function->shared()); | 220 jsfun->set_shared(T.function->shared()); |
| 221 jsfun->set_literals(T.function->literals()); |
| 221 CHECK(context->Global() | 222 CHECK(context->Global() |
| 222 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) | 223 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) |
| 223 .FromJust()); | 224 .FromJust()); |
| 224 CompileRun("var x = 24;"); | 225 CompileRun("var x = 24;"); |
| 225 ExpectInt32("foo();", 24); | 226 ExpectInt32("foo();", 24); |
| 226 } | 227 } |
| 227 | 228 |
| 228 | 229 |
| 229 TEST(BuiltinLoadedFromActivation) { | 230 TEST(BuiltinLoadedFromActivation) { |
| 230 const char* script = | 231 const char* script = |
| 231 "var x = 42;" | 232 "var x = 42;" |
| 232 "(function() {" | 233 "(function() {" |
| 233 " return function () { return this; };" | 234 " return function () { return this; };" |
| 234 "})()"; | 235 "})()"; |
| 235 | 236 |
| 236 // Disable context specialization. | 237 // Disable context specialization. |
| 237 FunctionTester T(script); | 238 FunctionTester T(script); |
| 238 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 239 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 239 v8::Context::Scope scope(context); | 240 v8::Context::Scope scope(context); |
| 240 v8::Local<v8::Value> value = CompileRun(script); | 241 v8::Local<v8::Value> value = CompileRun(script); |
| 241 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 242 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
| 242 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 243 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
| 243 jsfun->set_code(T.function->code()); | 244 jsfun->set_code(T.function->code()); |
| 244 jsfun->set_shared(T.function->shared()); | 245 jsfun->set_shared(T.function->shared()); |
| 246 jsfun->set_literals(T.function->literals()); |
| 245 CHECK(context->Global() | 247 CHECK(context->Global() |
| 246 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) | 248 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) |
| 247 .FromJust()); | 249 .FromJust()); |
| 248 CompileRun("var x = 24;"); | 250 CompileRun("var x = 24;"); |
| 249 ExpectObject("foo()", context->Global()); | 251 ExpectObject("foo()", context->Global()); |
| 250 } | 252 } |
| 251 | 253 |
| 252 } // namespace compiler | 254 } // namespace compiler |
| 253 } // namespace internal | 255 } // namespace internal |
| 254 } // namespace v8 | 256 } // namespace v8 |
| OLD | NEW |