Chromium Code Reviews| Index: test/cctest/ffi/test-ffi.cc |
| diff --git a/test/cctest/ffi/test-ffi.cc b/test/cctest/ffi/test-ffi.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..06f7856c4d0a8c031b34cfa1cf0dfa810712d2c6 |
| --- /dev/null |
| +++ b/test/cctest/ffi/test-ffi.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
|
Michael Starzinger
2017/01/18 10:47:24
nit: 2017
mattloring
2017/01/18 17:48:18
Done.
|
| +// 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/ffi/ffi-compiler.h" |
| +#include "test/cctest/cctest.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| +namespace 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)); |
| +} |
| + |
| +} // namespace ffi |
| +} // namespace internal |
| +} // namespace v8 |