Skip to content

Commit

Permalink
commit v8 thiry lib for openharmony (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyang57 authored Mar 21, 2024
1 parent e6baa20 commit 3733f46
Show file tree
Hide file tree
Showing 143 changed files with 53,425 additions and 0 deletions.
31 changes: 31 additions & 0 deletions openharmony/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ set_target_properties(curl PROPERTIES
IMPORTED_LOCATION ${ohos_lib_dir}/libcurl.a
)

if(CC_USE_SE_V8)
add_library(v8_monolith STATIC IMPORTED GLOBAL)
set_target_properties(v8_monolith PROPERTIES
IMPORTED_LOCATION ${ohos_lib_dir}/libv8_monolith.a
INTERFACE_INCLUDE_DIRECTORIES ${platform_spec_path}/include/v8
)

set(OHOS_ARM64_MACROS
V8_31BIT_SMIS_ON_64BIT_ARCH
V8_DEPRECATION_WARNINGS
V8_IMMINENT_DEPRECATION_WARNINGS
V8_TARGET_ARCH_ARM64
V8_HAVE_TARGET_OS
V8_TARGET_OS_LINUX
V8_COMPRESS_POINTERS
)

if(OHOS_ARCH STREQUAL "arm64-v8a")
set_property(TARGET v8_monolith
APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ${OHOS_ARM64_MACROS}
)
endif()

set(se_libs_name v8_monolith)
endif()

############################# PhysX #############################
# if(USE_PHYSICS_PHYSX)
# set(PhysXSDK PhysXCooking PhysXCharacterKinematic PhysXVehicle PhysXExtensions PhysX PhysXPvdSDK PhysXCommon PhysXFoundation)
Expand Down Expand Up @@ -147,6 +173,11 @@ list(APPEND CC_EXTERNAL_INCLUDES
${platform_spec_path}/include/opengles-api
)

if(CC_USE_SE_V8)
list(APPEND CC_EXTERNAL_LIBS v8_monolith)
list(APPEND CC_EXTERNAL_INCLUDES ${platform_spec_path}/include/v8)
endif()

#TODO: remove in future version
link_directories(${platform_spec_path}/ext/usr/lib)
include_directories(${platform_spec_path}/ext/usr/include)
72 changes: 72 additions & 0 deletions openharmony/arm64-v8a/include/v8/APIDesign.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# The V8 public C++ API

# Overview

The V8 public C++ API aims to support four use cases:

1. Enable applications that embed V8 (called the embedder) to configure and run
one or more instances of V8.
2. Expose ECMAScript-like capabilities to the embedder.
3. Enable the embedder to interact with ECMAScript by exposing API objects.
4. Provide access to the V8 debugger (inspector).

# Configuring and running an instance of V8

V8 requires access to certain OS-level primitives such as the ability to
schedule work on threads, or allocate memory.

The embedder can define how to access those primitives via the v8::Platform
interface. While V8 bundles a basic implementation, embedders are highly
encouraged to implement v8::Platform themselves.

Currently, the v8::ArrayBuffer::Allocator is passed to the v8::Isolate factory
method, however, conceptually it should also be part of the v8::Platform since
all instances of V8 should share one allocator.

Once the v8::Platform is configured, an v8::Isolate can be created. All
further interactions with V8 should explicitly reference the v8::Isolate they
refer to. All API methods should eventually take an v8::Isolate parameter.

When a given instance of V8 is no longer needed, it can be destroyed by
disposing the respective v8::Isolate. If the embedder wishes to free all memory
associated with the v8::Isolate, it has to first clear all global handles
associated with that v8::Isolate.

# ECMAScript-like capabilities

In general, the C++ API shouldn't enable capabilities that aren't available to
scripts running in V8. Experience has shown that it's not possible to maintain
such API methods in the long term. However, capabilities also available to
scripts, i.e., ones that are defined in the ECMAScript standard are there to
stay, and we can safely expose them to embedders.

The C++ API should also be pleasant to use, and not require learning new
paradigms. Similarly to how the API exposed to scripts aims to provide good
ergonomics, we should aim to provide a reasonable developer experience for this
API surface.

ECMAScript makes heavy use of exceptions, however, V8's C++ code doesn't use
C++ exceptions. Therefore, all API methods that can throw exceptions should
indicate so by returning a v8::Maybe<> or v8::MaybeLocal<> result,
and by taking a v8::Local<v8::Context> parameter that indicates in which
context a possible exception should be thrown.

# API objects

V8 allows embedders to define special objects that expose additional
capabilities and APIs to scripts. The most prominent example is exposing the
HTML DOM in Blink. Other examples are e.g. node.js. It is less clear what kind
of capabilities we want to expose via this API surface. As a rule of thumb, we
want to expose operations as defined in the WebIDL and HTML spec: we
assume that those requirements are somewhat stable, and that they are a
superset of the requirements of other embedders including node.js.

Ideally, the API surfaces defined in those specs hook into the ECMAScript spec
which in turn guarantees long-term stability of the API.

# The V8 inspector

All debugging capabilities of V8 should be exposed via the inspector protocol.
The exception to this are profiling features exposed via v8-profiler.h.
Changes to the inspector protocol need to ensure backwards compatibility and
commitment to maintain.
10 changes: 10 additions & 0 deletions openharmony/arm64-v8a/include/v8/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include_rules = [
# v8-inspector-protocol.h depends on generated files under include/inspector.
"+inspector",
"+cppgc/common.h",
# Used by v8-cppgc.h to bridge to cppgc.
"+cppgc/custom-space.h",
"+cppgc/heap-statistics.h",
"+cppgc/internal/write-barrier.h",
"+cppgc/visitor.h",
]
11 changes: 11 additions & 0 deletions openharmony/arm64-v8a/include/v8/DIR_METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Metadata information for this directory.
#
# For more information on DIR_METADATA files, see:
# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
#
# For the schema of this file, see Metadata message:
# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto

monorail {
component: "Blink>JavaScript>API"
}
18 changes: 18 additions & 0 deletions openharmony/arm64-v8a/include/v8/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

per-file *DEPS=file:../COMMON_OWNERS
per-file v8-internal.h=file:../COMMON_OWNERS
per-file v8-inspector.h=file:../src/inspector/OWNERS
per-file v8-inspector-protocol.h=file:../src/inspector/OWNERS
per-file js_protocol.pdl=file:../src/inspector/OWNERS

# For branch updates:
per-file v8-version.h=file:../INFRA_OWNERS
per-file [email protected]
per-file [email protected]
8 changes: 8 additions & 0 deletions openharmony/arm64-v8a/include/v8/cppgc/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include_rules = [
"-include",
"+v8config.h",
"+v8-platform.h",
"+cppgc",
"-src",
"+libplatform/libplatform.h",
]
2 changes: 2 additions & 0 deletions openharmony/arm64-v8a/include/v8/cppgc/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[email protected]
[email protected]
5 changes: 5 additions & 0 deletions openharmony/arm64-v8a/include/v8/cppgc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# C++ Garbage Collection

This directory provides an open-source garbage collection library for C++.

The library is under construction, meaning that *all APIs in this directory are incomplete and considered unstable and should not be used*.
Loading

0 comments on commit 3733f46

Please sign in to comment.