├── .gitignore ├── LICENSE ├── README.md ├── hello.cc ├── meson.build └── subprojects └── v8.wrap /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /subprojects/v8 3 | /subprojects/zlib* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014, the V8 project authors. All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are 4 | met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hello-v8 2 | 3 | An example V8 “Hello World” program. 4 | 5 | # Prerequisites 6 | 7 | - C++ compiler 8 | - Meson and Ninja (pip3 install meson ninja) 9 | 10 | # Building 11 | 12 | ```sh 13 | $ meson build 14 | $ ninja -C build 15 | ``` 16 | 17 | # Running 18 | 19 | ```sh 20 | $ ./build/hello-v8 21 | ``` 22 | -------------------------------------------------------------------------------- /hello.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Based on v8's samples/hello-world.cc: 3 | // 4 | // Copyright 2014 the V8 project authors. All rights reserved. 5 | // Use of this source code is governed by a BSD-style license that can be 6 | // found in the LICENSE file. 7 | // 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | int 15 | main (int argc, 16 | char * argv[]) 17 | { 18 | auto platform = v8::platform::NewDefaultPlatform (); 19 | v8::V8::InitializePlatform (platform.get ()); 20 | v8::V8::Initialize (); 21 | 22 | v8::Isolate::CreateParams create_params; 23 | create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator (); 24 | auto isolate = v8::Isolate::New (create_params); 25 | 26 | { 27 | v8::Isolate::Scope isolate_scope (isolate); 28 | v8::HandleScope handle_scope (isolate); 29 | auto context = v8::Context::New (isolate); 30 | v8::Context::Scope context_scope (context); 31 | 32 | auto source = v8::String::NewFromUtf8 (isolate, "'Hello' + ', V8!'", v8::NewStringType::kNormal).ToLocalChecked (); 33 | auto script = v8::Script::Compile (context, source).ToLocalChecked (); 34 | auto result = script->Run (context).ToLocalChecked (); 35 | 36 | v8::String::Utf8Value str (isolate, result); 37 | std::cout << *str << std::endl; 38 | } 39 | 40 | isolate->Dispose (); 41 | 42 | v8::V8::Dispose (); 43 | v8::V8::DisposePlatform (); 44 | delete create_params.array_buffer_allocator; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('hello-v8', 'cpp', 2 | default_options: [ 3 | 'cpp_std=c++17', 4 | 'optimization=s', 5 | 'b_ndebug=true', 6 | 'strip=true', 7 | ], 8 | ) 9 | 10 | v8_dep = dependency('v8-10.0') 11 | 12 | executable('hello-v8', 'hello.cc', 13 | dependencies: [v8_dep], 14 | ) 15 | -------------------------------------------------------------------------------- /subprojects/v8.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | url = https://github.com/frida/v8.git 3 | revision = main 4 | depth = 1 5 | 6 | [provide] 7 | dependency_names = v8-10.0 8 | --------------------------------------------------------------------------------