| Index: test/cctest/compiler/test-ffi.cc
|
| diff --git a/test/cctest/compiler/test-ffi.cc b/test/cctest/compiler/test-ffi.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5a3c2f29e8d21d33cc8ac3c39a2e0ff12837fcb3
|
| --- /dev/null
|
| +++ b/test/cctest/compiler/test-ffi.cc
|
| @@ -0,0 +1,36 @@
|
| +// Copyright 2016 the V8 project authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "src/codegen.h"
|
| +#include "src/compiler/ffi-compiler.h"
|
| +
|
| +#include "test/cctest/cctest.h"
|
| +
|
| +using namespace v8::internal;
|
| +using namespace v8::internal::compiler;
|
| +using namespace v8::internal::ffi;
|
| +
|
| +static void hello_world() { printf("hello world from native code\n"); }
|
| +
|
| +TEST(Run_FFI_Hello) {
|
| + Isolate* isolate = CcTest::InitIsolateOnce();
|
| + HandleScope scope(isolate);
|
| +
|
| + Handle<String> name =
|
| + isolate->factory()->InternalizeUtf8String("hello_world");
|
| + Handle<Object> undefined = isolate->factory()->undefined_value();
|
| +
|
| + AccountingAllocator allocator;
|
| + Zone zone(&allocator, ZONE_NAME);
|
| + FFISignature::Builder sig_builder(&zone, 0, 0);
|
| + NativeFunction func = {sig_builder.Build(),
|
| + reinterpret_cast<uint8_t*>(hello_world)};
|
| +
|
| + Handle<JSFunction> jsfunc = CompileJSToNativeWrapper(isolate, name, func);
|
| +
|
| + Handle<Object> result =
|
| + Execution::Call(isolate, jsfunc, undefined, 0, nullptr).ToHandleChecked();
|
| +
|
| + CHECK(result->IsUndefined(isolate));
|
| +}
|
|
|