Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 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/ffi/ffi-compiler.h" | |
| 7 #include "test/cctest/cctest.h" | |
| 8 | |
| 9 namespace v8 { | |
| 10 namespace internal { | |
| 11 namespace ffi { | |
| 12 | |
| 13 static void hello_world() { printf("hello world from native code\n"); } | |
| 14 | |
| 15 TEST(Run_FFI_Hello) { | |
| 16 Isolate* isolate = CcTest::InitIsolateOnce(); | |
| 17 HandleScope scope(isolate); | |
| 18 | |
| 19 Handle<String> name = | |
| 20 isolate->factory()->InternalizeUtf8String("hello_world"); | |
| 21 Handle<Object> undefined = isolate->factory()->undefined_value(); | |
| 22 | |
| 23 AccountingAllocator allocator; | |
| 24 Zone zone(&allocator, ZONE_NAME); | |
| 25 FFISignature::Builder sig_builder(&zone, 0, 0); | |
| 26 NativeFunction func = {sig_builder.Build(), | |
| 27 reinterpret_cast<uint8_t*>(hello_world)}; | |
| 28 | |
| 29 Handle<JSFunction> jsfunc = CompileJSToNativeWrapper(isolate, name, func); | |
| 30 | |
| 31 Handle<Object> result = | |
| 32 Execution::Call(isolate, jsfunc, undefined, 0, nullptr).ToHandleChecked(); | |
| 33 | |
| 34 CHECK(result->IsUndefined(isolate)); | |
| 35 } | |
| 36 | |
| 37 } // namespace ffi | |
| 38 } // namespace internal | |
| 39 } // namespace v8 | |
| OLD | NEW |