Skip to content

Commit 5c932e6

Browse files
committed
Feature(runtime): Add V8 (only base)
1 parent 3213e58 commit 5c932e6

117 files changed

Lines changed: 34706 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/runtime/v8/.DS_Store

6 KB
Binary file not shown.

packages/runtime/v8/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/v8/v8
2+
3+
https://github.com/v8/v8/blob/master/LICENSE
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# The V8 public C++ API
2+
3+
# Overview
4+
5+
The V8 public C++ API aims to support four use cases:
6+
7+
1. Enable applications that embed V8 (called the embedder) to configure and run
8+
one or more instances of V8.
9+
2. Expose ECMAScript-like capabilities to the embedder.
10+
3. Enable the embedder to interact with ECMAScript by exposing API objects.
11+
4. Provide access to the V8 debugger (inspector).
12+
13+
# Configuring and running an instance of V8
14+
15+
V8 requires access to certain OS-level primitives such as the ability to
16+
schedule work on threads, or allocate memory.
17+
18+
The embedder can define how to access those primitives via the v8::Platform
19+
interface. While V8 bundles a basic implementation, embedders are highly
20+
encouraged to implement v8::Platform themselves.
21+
22+
Currently, the v8::ArrayBuffer::Allocator is passed to the v8::Isolate factory
23+
method, however, conceptually it should also be part of the v8::Platform since
24+
all instances of V8 should share one allocator.
25+
26+
Once the v8::Platform is configured, an v8::Isolate can be created. All
27+
further interactions with V8 should explicitly reference the v8::Isolate they
28+
refer to. All API methods should eventually take an v8::Isolate parameter.
29+
30+
When a given instance of V8 is no longer needed, it can be destroyed by
31+
disposing the respective v8::Isolate. If the embedder wishes to free all memory
32+
associated with the v8::Isolate, it has to first clear all global handles
33+
associated with that v8::Isolate.
34+
35+
# ECMAScript-like capabilities
36+
37+
In general, the C++ API shouldn't enable capabilities that aren't available to
38+
scripts running in V8. Experience has shown that it's not possible to maintain
39+
such API methods in the long term. However, capabilities also available to
40+
scripts, i.e., ones that are defined in the ECMAScript standard are there to
41+
stay, and we can safely expose them to embedders.
42+
43+
The C++ API should also be pleasant to use, and not require learning new
44+
paradigms. Similarly to how the API exposed to scripts aims to provide good
45+
ergonomics, we should aim to provide a reasonable developer experience for this
46+
API surface.
47+
48+
ECMAScript makes heavy use of exceptions, however, V8's C++ code doesn't use
49+
C++ exceptions. Therefore, all API methods that can throw exceptions should
50+
indicate so by returning a v8::Maybe<> or v8::MaybeLocal<> result,
51+
and by taking a v8::Local<v8::Context> parameter that indicates in which
52+
context a possible exception should be thrown.
53+
54+
# API objects
55+
56+
V8 allows embedders to define special objects that expose additional
57+
capabilities and APIs to scripts. The most prominent example is exposing the
58+
HTML DOM in Blink. Other examples are e.g. node.js. It is less clear what kind
59+
of capabilities we want to expose via this API surface. As a rule of thumb, we
60+
want to expose operations as defined in the WebIDL and HTML spec: we
61+
assume that those requirements are somewhat stable, and that they are a
62+
superset of the requirements of other embedders including node.js.
63+
64+
Ideally, the API surfaces defined in those specs hook into the ECMAScript spec
65+
which in turn guarantees long-term stability of the API.
66+
67+
# The V8 inspector
68+
69+
All debugging capabilities of V8 should be exposed via the inspector protocol.

packages/runtime/v8/include/DEPS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include_rules = [
2+
# v8-inspector-protocol.h depends on generated files under include/inspector.
3+
"+inspector",
4+
]

packages/runtime/v8/include/OWNERS

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set noparent
2+
3+
adamk@chromium.org
4+
danno@chromium.org
5+
ulan@chromium.org
6+
yangguo@chromium.org
7+
8+
per-file v8-internal.h=file://OWNERS
9+
per-file v8-inspector.h=dgozman@chromium.org
10+
per-file v8-inspector.h=pfeldman@chromium.org
11+
per-file v8-inspector.h=kozyatinskiy@chromium.org
12+
per-file v8-inspector-protocol.h=dgozman@chromium.org
13+
per-file v8-inspector-protocol.h=pfeldman@chromium.org
14+
per-file v8-inspector-protocol.h=kozyatinskiy@chromium.org
15+
16+
# COMPONENT: Blink>JavaScript>API
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include_rules = [
2+
"+libplatform/libplatform-export.h",
3+
]
4+
5+
specific_include_rules = {
6+
"libplatform\.h": [
7+
"+libplatform/v8-tracing.h",
8+
],
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
#ifndef V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
6+
#define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
7+
8+
#if defined(_WIN32)
9+
10+
#ifdef BUILDING_V8_PLATFORM_SHARED
11+
#define V8_PLATFORM_EXPORT __declspec(dllexport)
12+
#elif USING_V8_PLATFORM_SHARED
13+
#define V8_PLATFORM_EXPORT __declspec(dllimport)
14+
#else
15+
#define V8_PLATFORM_EXPORT
16+
#endif // BUILDING_V8_PLATFORM_SHARED
17+
18+
#else // defined(_WIN32)
19+
20+
// Setup for Linux shared library export.
21+
#ifdef BUILDING_V8_PLATFORM_SHARED
22+
#define V8_PLATFORM_EXPORT __attribute__((visibility("default")))
23+
#else
24+
#define V8_PLATFORM_EXPORT
25+
#endif
26+
27+
#endif // defined(_WIN32)
28+
29+
#endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2014 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+
#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
6+
#define V8_LIBPLATFORM_LIBPLATFORM_H_
7+
8+
#include "libplatform/libplatform-export.h"
9+
#include "libplatform/v8-tracing.h"
10+
#include "v8-platform.h" // NOLINT(build/include)
11+
#include "v8config.h" // NOLINT(build/include)
12+
13+
namespace v8 {
14+
namespace platform {
15+
16+
enum class IdleTaskSupport { kDisabled, kEnabled };
17+
enum class InProcessStackDumping { kDisabled, kEnabled };
18+
19+
enum class MessageLoopBehavior : bool {
20+
kDoNotWait = false,
21+
kWaitForWork = true
22+
};
23+
24+
/**
25+
* Returns a new instance of the default v8::Platform implementation.
26+
*
27+
* The caller will take ownership of the returned pointer. |thread_pool_size|
28+
* is the number of worker threads to allocate for background jobs. If a value
29+
* of zero is passed, a suitable default based on the current number of
30+
* processors online will be chosen.
31+
* If |idle_task_support| is enabled then the platform will accept idle
32+
* tasks (IdleTasksEnabled will return true) and will rely on the embedder
33+
* calling v8::platform::RunIdleTasks to process the idle tasks.
34+
* If |tracing_controller| is nullptr, the default platform will create a
35+
* v8::platform::TracingController instance and use it.
36+
*/
37+
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
38+
int thread_pool_size = 0,
39+
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
40+
InProcessStackDumping in_process_stack_dumping =
41+
InProcessStackDumping::kDisabled,
42+
std::unique_ptr<v8::TracingController> tracing_controller = {});
43+
44+
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
45+
"Use NewDefaultPlatform instead",
46+
v8::Platform* CreateDefaultPlatform(
47+
int thread_pool_size = 0,
48+
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
49+
InProcessStackDumping in_process_stack_dumping =
50+
InProcessStackDumping::kDisabled,
51+
v8::TracingController* tracing_controller = nullptr));
52+
53+
/**
54+
* Pumps the message loop for the given isolate.
55+
*
56+
* The caller has to make sure that this is called from the right thread.
57+
* Returns true if a task was executed, and false otherwise. Unless requested
58+
* through the |behavior| parameter, this call does not block if no task is
59+
* pending. The |platform| has to be created using |NewDefaultPlatform|.
60+
*/
61+
V8_PLATFORM_EXPORT bool PumpMessageLoop(
62+
v8::Platform* platform, v8::Isolate* isolate,
63+
MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);
64+
65+
/**
66+
* Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
67+
*
68+
* The caller has to make sure that this is called from the right thread.
69+
* This call does not block if no task is pending. The |platform| has to be
70+
* created using |NewDefaultPlatform|.
71+
*/
72+
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
73+
v8::Isolate* isolate,
74+
double idle_time_in_seconds);
75+
76+
/**
77+
* Attempts to set the tracing controller for the given platform.
78+
*
79+
* The |platform| has to be created using |NewDefaultPlatform|.
80+
*
81+
*/
82+
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
83+
"Access the DefaultPlatform directly",
84+
void SetTracingController(
85+
v8::Platform* platform,
86+
v8::platform::tracing::TracingController* tracing_controller));
87+
88+
} // namespace platform
89+
} // namespace v8
90+
91+
#endif // V8_LIBPLATFORM_LIBPLATFORM_H_

0 commit comments

Comments
 (0)