OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/codegen.h" |
| 6 #include "src/compiler/ffi-compiler.h" |
| 7 |
| 8 #include "test/cctest/cctest.h" |
| 9 |
| 10 using namespace v8::internal; |
| 11 using namespace v8::internal::compiler; |
| 12 using namespace v8::internal::ffi; |
| 13 |
| 14 static void hello_world() { printf("hello world from native code\n"); } |
| 15 |
| 16 TEST(Run_FFI_Hello) { |
| 17 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 18 HandleScope scope(isolate); |
| 19 |
| 20 Handle<String> name = |
| 21 isolate->factory()->InternalizeUtf8String("hello_world"); |
| 22 Handle<Object> undefined = isolate->factory()->undefined_value(); |
| 23 |
| 24 AccountingAllocator allocator; |
| 25 Zone zone(&allocator, ZONE_NAME); |
| 26 FFISignature::Builder sig_builder(&zone, 0, 0); |
| 27 NativeFunction func = {sig_builder.Build(), |
| 28 reinterpret_cast<uint8_t*>(hello_world)}; |
| 29 |
| 30 Handle<JSFunction> jsfunc = CompileJSToNativeWrapper(isolate, name, func); |
| 31 |
| 32 Handle<Object> result = |
| 33 Execution::Call(isolate, jsfunc, undefined, 0, nullptr).ToHandleChecked(); |
| 34 |
| 35 CHECK(result->IsUndefined(isolate)); |
| 36 } |
OLD | NEW |