Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b379fd475c | ||
|
|
c65aed1a97 |
|
|
@ -1,24 +0,0 @@
|
|||
# Exclude external third-party libraries
|
||||
/escargot/third_party/double_conversion/double-conversion.cc
|
||||
/escargot/third_party/double_conversion/bignum.h
|
||||
/escargot/third_party/GCutil/
|
||||
/escargot/third_party/libbf/libbf.c
|
||||
/escargot/third_party/lz4/lz4.cpp
|
||||
/escargot/third_party/rapidjson/include/rapidjson/document.h
|
||||
/escargot/third_party/rapidjson/include/rapidjson/reader.h
|
||||
/escargot/third_party/rapidjson/include/rapidjson/encodings.h
|
||||
/escargot/third_party/yarr/
|
||||
|
||||
# Exclude parser/interpreter codes which have intensive control statements and similar patterns essentially used for compilation and execution
|
||||
/escargot/src/parser/Lexer.h
|
||||
/escargot/src/parser/Lexer.cpp
|
||||
/escargot/src/parser/esprima_cpp/esprima.cpp
|
||||
/escargot/src/interpreter/ByteCodeInterpreter.h
|
||||
/escargot/src/interpreter/ByteCodeInterpreter.cpp
|
||||
/escargot/src/parser/CodeBlock.h
|
||||
|
||||
# Exclude huge-scaled Object classes that represent built-in JavaScript Objects
|
||||
/escargot/src/runtime/GlobalObject.h
|
||||
/escargot/src/runtime/Object.h
|
||||
/escargot/src/runtime/DateObject.h
|
||||
/escargot/src/runtime/Value.h
|
||||
88
.github/workflows/analysis-actions.yml
vendored
|
|
@ -1,88 +0,0 @@
|
|||
name: Analysis
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# trigger on every monday, wednesday and friday
|
||||
- cron: '30 22 * * 1,3,5'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
coverity-scan:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Build ICU(64)
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Download Coverity Tool
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
run: |
|
||||
wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=Samsung%2Fescargot" -O cov-analysis-linux64.tar.gz
|
||||
mkdir cov-analysis-linux64
|
||||
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_CODE_CACHE=ON -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export PATH=$GITHUB_WORKSPACE/cov-analysis-linux64/bin:$PATH
|
||||
LDFLAGS="-L$GITHUB_WORKSPACE/icu64/lib/ -Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" PKG_CONFIG_PATH="$GITHUB_WORKSPACE/icu64/lib/pkgconfig/" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/coverity_scan $BUILD_OPTIONS
|
||||
cov-build --dir cov-int ninja -Cout/coverity_scan
|
||||
- name: Submit
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
NOTI_MAIL: ${{ secrets.COVERITY_SCAN_MAIL }}
|
||||
run: |
|
||||
tar czvf escargot.tgz cov-int
|
||||
curl \
|
||||
--form token=$TOKEN \
|
||||
--form email=$NOTI_MAIL \
|
||||
--form file=@escargot.tgz \
|
||||
--form version="4.3.0" \
|
||||
--form description="escargot coverity scan" \
|
||||
https://scan.coverity.com/builds?project=Samsung%2Fescargot
|
||||
|
||||
coverage-scan:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, x64, test]
|
||||
timeout-minutes: 600
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_COVERAGE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/coverage64 -DESCARGOT_ARCH=x64 $BUILD_OPTIONS
|
||||
ninja -Cout/coverage64
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/coverage32 -DESCARGOT_ARCH=x86 $BUILD_OPTIONS
|
||||
ninja -Cout/coverage32
|
||||
- name: Run test262 and collect coverage data
|
||||
# test262 is unstable in actions env, but coverage data will be accumulated
|
||||
continue-on-error: true
|
||||
run: |
|
||||
# set locale
|
||||
sudo locale-gen en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
locale
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/coverage64/escargot" new-es regression-tests test262 octane chakracore sunspider-js modifiedVendorTest jsc-stress v8 spidermonkey intl jetstream-only-cdjs
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86 --engine="$GITHUB_WORKSPACE/out/coverage32/escargot" new-es regression-tests test262 octane chakracore sunspider-js modifiedVendorTest jsc-stress v8 spidermonkey intl jetstream-only-cdjs
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
gcovr --gcov-ignore-parse-errors --exclude-unreachable-branches --exclude-throw-branches --exclude '.*third_party/' --exclude '.*shell/' --exclude '.*api/' -r . --xml coverage.xml
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
fail_ci_if_error: true
|
||||
files: ./coverage.xml
|
||||
name: codecov-umbrella
|
||||
verbose: true
|
||||
97
.github/workflows/android-release.yml
vendored
|
|
@ -1,97 +0,0 @@
|
|||
name: Android-Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
build-android-on-ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4.1.0
|
||||
with:
|
||||
distribution: "zulu"
|
||||
java-version: 17
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
- name: Build with Gradle
|
||||
working-directory: ./build/android
|
||||
run: |
|
||||
./gradlew bundleHostJar
|
||||
./gradlew javadocJar
|
||||
./gradlew sourcesJar
|
||||
./gradlew :escargot:testDebugUnitTest
|
||||
mv ./escargot/build/libs/escargot.jar ./escargot/build/libs/escargot-ubuntu.jar
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-ubuntu
|
||||
path: |
|
||||
./build/android/escargot/build/**/escargot-*.aar
|
||||
./build/android/escargot/build/**/escargot-*.jar
|
||||
!./build/android/escargot/build/**/escargot-*Shell.aar
|
||||
if-no-files-found: error
|
||||
|
||||
build-android-on-macos:
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4.1.0
|
||||
with:
|
||||
distribution: "zulu"
|
||||
java-version: 17
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
- name: Build with Gradle
|
||||
working-directory: ./build/android
|
||||
run: |
|
||||
./gradlew bundleHostJar
|
||||
./gradlew :escargot:testDebugUnitTest
|
||||
mv ./escargot/build/libs/escargot.jar ./escargot/build/libs/escargot-mac.jar
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-mac
|
||||
path: |
|
||||
./build/android/escargot/build/libs/escargot-mac.jar
|
||||
if-no-files-found: error
|
||||
|
||||
merge-update-release:
|
||||
needs: [build-android-on-ubuntu, build-android-on-macos]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-*
|
||||
merge-multiple: true
|
||||
- name: Set release date
|
||||
run: |
|
||||
echo "RELEASE_DATE=$(date --rfc-3339=date)" >> $GITHUB_ENV
|
||||
- name: Merge build artifacts
|
||||
working-directory: ./artifacts
|
||||
run: |
|
||||
ls -R ./
|
||||
echo ${RELEASE_DATE}
|
||||
find . -type f -name "escargot-*.aar" -exec mv {} . \;
|
||||
find . -type f -name "escargot-*.jar" -exec mv {} . \;
|
||||
ls -R ./
|
||||
find ./ -type f -name "escargot-*.aar" -o -name "escargot-*.jar" | zip Android-Release-${{ env.RELEASE_DATE }}.zip -@
|
||||
- name: Upload to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
artifacts/Android-Release-${{ env.RELEASE_DATE }}.zip
|
||||
110
.github/workflows/code-review.yml
vendored
|
|
@ -1,110 +0,0 @@
|
|||
name: Review Bot (PR)
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches: [ "master" ]
|
||||
|
||||
concurrency:
|
||||
group: review-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
review:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, escargot-review]
|
||||
|
||||
steps:
|
||||
- name: Compute diff range (incremental on synchronize)
|
||||
id: shas
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const action = context.payload.action;
|
||||
const pr = context.payload.pull_request.number;
|
||||
const baseSha = context.payload.pull_request.base.sha;
|
||||
const headSha = context.payload.pull_request.head.sha;
|
||||
|
||||
let base = baseSha;
|
||||
let skip = false;
|
||||
if (action === 'synchronize') {
|
||||
const before = context.payload.before;
|
||||
if (before) {
|
||||
base = before;
|
||||
} else {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
core.setOutput('base', base);
|
||||
core.setOutput('head', headSha);
|
||||
core.setOutput('pr', pr);
|
||||
core.setOutput('skip', String(skip));
|
||||
- name: Skip review (no before on synchronize)
|
||||
if: ${{ steps.shas.outputs.skip == 'true' }}
|
||||
run: |
|
||||
echo "[Review Bot] Skipping review: 'before' SHA missing on synchronize event."
|
||||
- name: Call review server
|
||||
id: call
|
||||
if: ${{ steps.shas.outputs.skip != 'true' }}
|
||||
env:
|
||||
REVIEW_SERVER: ${{ secrets.REVIEW_SERVER }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
REVIEW_SERVER="${REVIEW_SERVER}"
|
||||
BASE_SHA="${{ steps.shas.outputs.base }}"
|
||||
HEAD_SHA="${{ steps.shas.outputs.head }}"
|
||||
PR_NUMBER="${{ steps.shas.outputs.pr }}"
|
||||
|
||||
curl -sS --fail-with-body --show-error \
|
||||
--connect-timeout 10 --max-time 7200 \
|
||||
-X POST "${REVIEW_SERVER}/review" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"base_sha\":\"${BASE_SHA}\",\"head_sha\":\"${HEAD_SHA}\",\"pull_request_number\":${PR_NUMBER}}" \
|
||||
-o review.json
|
||||
|
||||
echo "==== review.json ===="
|
||||
cat review.json
|
||||
|
||||
- name: Post review comments
|
||||
if: ${{ steps.shas.outputs.skip != 'true' }}
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const pr = context.payload.pull_request.number;
|
||||
let raw;
|
||||
try {
|
||||
raw = fs.readFileSync('review.json', 'utf8');
|
||||
} catch (e) {
|
||||
core.warning(`review.json not found: ${e}`);
|
||||
return;
|
||||
}
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(raw);
|
||||
} catch (e) {
|
||||
core.warning(`Failed to parse review.json as JSON: ${e}`);
|
||||
return;
|
||||
}
|
||||
const comments = Array.isArray(data.comments) ? data.comments : [];
|
||||
|
||||
for (const c of comments) {
|
||||
await github.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: pr,
|
||||
body: c.body,
|
||||
commit_id: c.commit_id,
|
||||
path: c.path,
|
||||
line: c.line,
|
||||
side: c.side,
|
||||
headers: { 'accept': 'application/vnd.github+json' }
|
||||
});
|
||||
|
||||
await new Promise(r => setTimeout(r, 200));
|
||||
}
|
||||
783
.github/workflows/es-actions.yml
vendored
|
|
@ -5,633 +5,290 @@ on:
|
|||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
RUNNER: tools/run-tests.py
|
||||
|
||||
jobs:
|
||||
check-tidy:
|
||||
runs-on: ubuntu-24.04
|
||||
check_tidy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
|
||||
sudo add-apt-repository "deb [trusted=yes] http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main"
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang-format-20
|
||||
sudo apt update
|
||||
sudo apt install -y clang-format-6.0
|
||||
- name: Test
|
||||
run: tools/check_tidy.py
|
||||
|
||||
build-on-macos:
|
||||
runs-on: macos-15
|
||||
windows_build:
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
submodules: true
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.3
|
||||
- name: Build Win32 Release
|
||||
run: |
|
||||
cd build/windows/escargot
|
||||
msbuild escargot.sln /p:configuration=release /p:platform=win32
|
||||
|
||||
clang_build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Patch WABT
|
||||
working-directory: ./third_party/wasm/wabt
|
||||
run: |
|
||||
cp ../../../tools/test/wasm-js/wabt_patch .
|
||||
patch -p0 < wabt_patch
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_ARCH=x86 -DESCARGOT_HOST=linux -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
CC=clang CXX=clang++ cmake -H. -Bout/clang/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/clang/x86
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_ARCH=x64 -DESCARGOT_HOST=linux -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
# check cpu
|
||||
sysctl -a | grep machdep.cpu
|
||||
# add icu path to pkg_config_path
|
||||
export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
|
||||
echo $PKG_CONFIG_PATH
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/debug/ -DESCARGOT_MODE=debug $BUILD_OPTIONS
|
||||
ninja -Cout/debug/
|
||||
$RUNNER --engine="./out/debug/escargot" new-es
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/release/ -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
ninja -Cout/release/
|
||||
cp test/octane/*.js .
|
||||
./out/release/escargot run.js
|
||||
CC=clang CXX=clang++ cmake -H. -Bout/clang/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/clang/x64
|
||||
|
||||
build-on-macos-arm64:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c
|
||||
- name: Build arm64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
# check cpu
|
||||
sysctl -a | grep machdep.cpu
|
||||
# add icu path to pkg_config_path
|
||||
export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
|
||||
echo $PKG_CONFIG_PATH
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/debug/ -DESCARGOT_MODE=debug $BUILD_OPTIONS
|
||||
ninja -Cout/debug/
|
||||
$RUNNER --engine="./out/debug/escargot" new-es
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/release/ -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
ninja -Cout/release/
|
||||
cp test/octane/*.js .
|
||||
./out/release/escargot run.js
|
||||
|
||||
build-test-on-android:
|
||||
release_x86_test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x86, x86_64]
|
||||
api: [28]
|
||||
tc: ['octane', 'v8 chakracore spidermonkey', 'jetstream-only-simple-parallel-1', 'jetstream-only-simple-parallel-2 jsc-stress', 'jetstream-only-simple-parallel-3 jetstream-only-cdjs']
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- name: Enable KVM
|
||||
run: |
|
||||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger --name-match=kvm
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4.1.0
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
distribution: "zulu"
|
||||
java-version: 17
|
||||
- name: Gradle cache
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
- name: Create AVD and run tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
with:
|
||||
api-level: ${{ matrix.api }}
|
||||
arch: ${{ matrix.arch }}
|
||||
force-avd-creation: false
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -camera-back none -no-snapshot-save -gpu swiftshader_indirect -noaudio -no-boot-anim
|
||||
disable-animations: true
|
||||
script: cd build/android/;./gradlew connectedDebugAndroidTest -DESCARGOT_BUILD_TLS_ACCESS_BY_PTHREAD_KEY=ON
|
||||
|
||||
build-test-tizen:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: prepare deb sources for GBS
|
||||
run: echo "deb [trusted=yes] http://download.tizen.org/tools/latest-release/Ubuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/tizen.list
|
||||
- name: install GBS
|
||||
run: sudo apt-get update && sudo apt-get install -y gbs
|
||||
- name: build
|
||||
run: |
|
||||
gbs -c .github/workflows/gbs.conf build -A armv7l -P profile.tizen --incremental --define "enable_shell 1"
|
||||
|
||||
test-on-windows-clang-cl:
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
# clang-cl with cannot generate c++ exception code well
|
||||
# if clang-cl bug fixed, we can add x64
|
||||
# clang version and STL version are sometimes not matched in github actions,
|
||||
# so I add -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH
|
||||
arch: [
|
||||
{cpu: "x86", flag: "-m32 -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH"}
|
||||
#, {cpu: "x64", flag: "-D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH"}
|
||||
]
|
||||
steps:
|
||||
- name: Set git cllf config
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: szenius/set-timezone@v2.0
|
||||
with:
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: "~3.25.0"
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Download and Install Visual C++ Redistributable
|
||||
shell: powershell
|
||||
run: |
|
||||
$vcRedistUrl64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath64 = "$env:TEMP\vc_redist.x64.exe"
|
||||
$vcRedistUrl32 = "https://aka.ms/vs/17/release/vc_redist.x86.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath32 = "$env:TEMP\vc_redist.x86.exe"
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl64"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl64 -OutFile $vcRedistPath64
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl32"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl32 -OutFile $vcRedistPath32
|
||||
|
||||
Write-Host "Installing Visual C++ Redistributable silently"
|
||||
Start-Process -FilePath $vcRedistPath64 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Start-Process -FilePath $vcRedistPath32 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Write-Host "Visual C++ Redistributable installation complete."
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: ${{ matrix.arch.cpu }}
|
||||
sdk: "10.0.26100.0"
|
||||
- uses: egor-tensin/setup-clang@v1
|
||||
with:
|
||||
version: 19.1.7
|
||||
platform: ${{ matrix.arch.cpu }}
|
||||
- name: Build ${{ matrix.arch.cpu }} Release
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch.cpu }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=release -DCMAKE_C_FLAGS="${{ matrix.arch.flag }}" -DCMAKE_CXX_FLAGS="${{ matrix.arch.flag }}"
|
||||
CMake --build out/ --config Release
|
||||
- name: Run octane
|
||||
run: |
|
||||
copy test\octane\*.js
|
||||
dir
|
||||
.\out\escargot.exe run.js
|
||||
# clang-cl with cannot generate c++ exception code well. if clang-cl bug fixed, we can enable test262
|
||||
# - name: Run test262
|
||||
# run: |
|
||||
# set GC_FREE_SPACE_DIVISOR=1
|
||||
# pip install chardet
|
||||
# python tools\run-tests.py --engine=%cd%\out\escargot.exe test262 --test262-extra-arg="--skip Temporal --skip intl402 --skip Atomics"
|
||||
# shell: cmd
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
test-on-windows-x86-x64:
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x86, x64]
|
||||
steps:
|
||||
- name: Set git cllf config
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: szenius/set-timezone@v2.0
|
||||
with:
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Download and Install Visual C++ Redistributable
|
||||
shell: powershell
|
||||
run: |
|
||||
$vcRedistUrl64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath64 = "$env:TEMP\vc_redist.x64.exe"
|
||||
$vcRedistUrl32 = "https://aka.ms/vs/17/release/vc_redist.x86.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath32 = "$env:TEMP\vc_redist.x86.exe"
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl64"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl64 -OutFile $vcRedistPath64
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl32"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl32 -OutFile $vcRedistPath32
|
||||
|
||||
Write-Host "Installing Visual C++ Redistributable silently"
|
||||
Start-Process -FilePath $vcRedistPath64 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Start-Process -FilePath $vcRedistPath32 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Write-Host "Visual C++ Redistributable installation complete."
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: ${{ matrix.arch }}
|
||||
sdk: "10.0.26100.0"
|
||||
- name: Build ${{ matrix.arch }} Release
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -DESCARGOT_ARCH=${{ matrix.arch }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_WASM=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake --build out/ --config Release
|
||||
# windows internal ICU doesn't support Temporal and intl402 well
|
||||
# github action windows runner only have 2 CPUs. that's why I disable Atomics(timeout occured with some tests)
|
||||
- name: Run test262
|
||||
run: |
|
||||
set GC_FREE_SPACE_DIVISOR=1
|
||||
pip install chardet
|
||||
python tools\run-tests.py --engine=%cd%\out\escargot.exe test262 --test262-extra-arg="--skip Temporal --skip intl402 --skip Atomics --skip sm"
|
||||
shell: cmd
|
||||
- name: Run octane
|
||||
run: |
|
||||
copy test\octane\*.js
|
||||
dir
|
||||
.\out\escargot.exe run.js
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
build-on-windows-x64-uwp-x86-shared:
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Set git cllf config
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: x64
|
||||
sdk: "10.0.26100.0"
|
||||
uwp: true
|
||||
- name: Build x64 UWP Release
|
||||
run: |
|
||||
CMake -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=x64 -Bout/win64_release_uwp/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON
|
||||
CMake --build out\win64_release_uwp --config Release
|
||||
shell: cmd
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: x86
|
||||
sdk: "10.0.26100.0"
|
||||
- name: Build x86 DLL Release
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=x86 -Bout/win32_release_shared/ -DESCARGOT_OUTPUT=shared_lib -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake --build out/win32_release_shared --config Release
|
||||
shell: cmd
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
build-test-on-x86-release:
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
tc: ['new-es octane', 'v8 chakracore spidermonkey', 'jetstream-only-simple-parallel-1', 'jetstream-only-simple-parallel-2 jsc-stress', 'jetstream-only-simple-parallel-3 jetstream-only-cdjs']
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib make g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build python2
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
run: |
|
||||
mkdir $GITHUB_WORKSPACE/python2-build/
|
||||
cd $GITHUB_WORKSPACE/python2-build/
|
||||
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
|
||||
tar xzf Python-2.7.18.tgz
|
||||
cd Python-2.7.18
|
||||
./configure --prefix=/usr/local/python2.7
|
||||
make -j8
|
||||
sudo make install
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/local/python2.7/bin/python2.7 1
|
||||
- name: Build ICU
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu-build/
|
||||
cd $GITHUB_WORKSPACE/icu-build/icu4c/source
|
||||
LDFLAGS="-m32 -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/" CFLAGS="-m32" CXXFLAGS="-m32" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu32/"
|
||||
make -j8
|
||||
make install
|
||||
ls $GITHUB_WORKSPACE/icu32/lib/
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_i386.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=release -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/lib/ -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/lib/pkgconfig
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/release/x86 $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/release/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/release/x86
|
||||
- name: Run release-x86 test
|
||||
env:
|
||||
GC_FREE_SPACE_DIVISOR: 1
|
||||
run: LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu32/lib $RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/release/x86/escargot" ${{ matrix.tc }}
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
run: $RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/release/x86/escargot" ${{ matrix.tc }}
|
||||
|
||||
build-test-on-x64-release:
|
||||
runs-on: ubuntu-24.04
|
||||
release_x64_test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
tc: ['octane v8 web-tooling-benchmark', 'chakracore spidermonkey new-es']
|
||||
build_opt: ['', '-DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON', '-DESCARGOT_SMALL_CONFIG=ON -DESCARGOT_USE_CUSTOM_LOGGING=ON']
|
||||
tc: ['octane', 'v8 chakracore spidermonkey']
|
||||
build_opt: ['', '-DESCARGOT_THREADING=ON', '-DESCARGOT_SMALL_CONFIG=ON -DESCARGOT_USE_CUSTOM_LOGGING=ON']
|
||||
exclude:
|
||||
# exclude octane, v8, web-tooling-benchmark due to low performance incurred by SMALL_CONFIG
|
||||
- tc: 'octane v8 web-tooling-benchmark'
|
||||
# exclude spidermonkey on threading-enabled build (TODO)
|
||||
- tc: 'v8 chakracore spidermonkey'
|
||||
build_opt: '-DESCARGOT_THREADING=ON'
|
||||
# exclue octane due to low performance incurred by SMALL_CONFIG
|
||||
- tc: 'octane'
|
||||
build_opt: '-DESCARGOT_SMALL_CONFIG=ON -DESCARGOT_USE_CUSTOM_LOGGING=ON'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build ICU(64)
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build
|
||||
- name: Install ICU
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build python2
|
||||
run: |
|
||||
mkdir $GITHUB_WORKSPACE/python2-build/
|
||||
cd $GITHUB_WORKSPACE/python2-build/
|
||||
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
|
||||
tar xzf Python-2.7.18.tgz
|
||||
cd Python-2.7.18
|
||||
./configure --prefix=/usr/local/python2.7
|
||||
make -j8
|
||||
sudo make install
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/local/python2.7/bin/python2.7 1
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_amd64.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/lib -Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/lib/pkgconfig
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/release/x64 $BUILD_OPTIONS ${{ matrix.build_opt }}
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/release/x64 $BUILD_OPTIONS ${{ matrix.build_opt }}
|
||||
ninja -Cout/release/x64
|
||||
- name: Run release-x64 test
|
||||
env:
|
||||
GC_FREE_SPACE_DIVISOR: 1
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu64/lib
|
||||
# set locale
|
||||
sudo locale-gen en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
locale
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/release/x64/escargot" ${{ matrix.tc }}
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
run: $RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/release/x64/escargot" ${{ matrix.tc }}
|
||||
|
||||
build-test-on-x86-x64-debug:
|
||||
runs-on: ubuntu-24.04
|
||||
debug_mode_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib make g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build ICU(32)
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu32-build/
|
||||
cd $GITHUB_WORKSPACE/icu32-build/icu4c/source
|
||||
LDFLAGS="-m32 -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/" CFLAGS="-m32" CXXFLAGS="-m32" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu32/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build ICU(64)
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_i386.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_amd64.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
- name: Build x86/x64
|
||||
env:
|
||||
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS_X86: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/debug/x86 $BUILD_OPTIONS_X86
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/debug/x64 $BUILD_OPTIONS_X64
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/debug/x86 $BUILD_OPTIONS_X86
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/debug/x64 $BUILD_OPTIONS_X64
|
||||
ninja -Cout/debug/x86
|
||||
ninja -Cout/debug/x64
|
||||
- name: Run debug-mode test
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu32/lib
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/debug/x86/escargot" modifiedVendorTest regression-tests new-es intl sunspider-js
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu64/lib
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/debug/x64/escargot" modifiedVendorTest regression-tests new-es intl sunspider-js
|
||||
|
||||
build-test-on-self-hosted-linux:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, x64, test]
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_TCO_DEBUG=ON $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux_release -DESCARGOT_ARCH=x86 $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux_release_clang -DESCARGOT_ARCH=x86 $BUILD_OPTIONS
|
||||
gcc -shared -m32 -fPIC -o backtrace-hooking-32.so tools/test/test262/backtrace-hooking.c
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux64 -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_TCO_DEBUG=ON $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux64_release -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux64_release_clang -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
cmake --build build/out_linux/
|
||||
cmake --build build/out_linux64/
|
||||
cmake --build build/out_linux_release/
|
||||
cmake --build build/out_linux_release_clang/
|
||||
cmake --build build/out_linux64_release/
|
||||
cmake --build build/out_linux64_release_clang/
|
||||
- name: Test
|
||||
run: |
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86 --engine="${{ github.workspace }}/build/out_linux_release/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86 --engine="${{ github.workspace }}/build/out_linux_release_clang/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 ESCARGOT_LD_PRELOAD=${{ github.workspace }}/backtrace-hooking-32.so $RUNNER --arch=x86 --engine="${{ github.workspace }}/build/out_linux/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86_64 --engine="${{ github.workspace }}/build/out_linux64_release/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86_64 --engine="${{ github.workspace }}/build/out_linux64_release_clang/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ python tools/kangax/run-kangax.py --engine="${{ github.workspace }}/build/out_linux64/escargot"
|
||||
|
||||
build-test-on-self-hosted-arm-linux:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, arm, test]
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: [ {cxx: g++, cc: gcc}, {cxx: clang++, cc: clang} ]
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bout -DCMAKE_C_COMPILER=${{ matrix.compiler.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=arm32 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=OFF -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=${{ matrix.compiler.tls }} -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
cmake --build ./out/
|
||||
- name: Test
|
||||
run: |
|
||||
GC_FREE_SPACE_DIVISOR=1 $RUNNER --engine="${{ github.workspace }}/out/escargot" --test262-extra-arg="--skip intl402 --skip sm --skip Temporal" new-es v8 spidermonkey chakracore test262
|
||||
|
||||
build-test-on-self-hosted-arm64-linux:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, arm64, test]
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: [ {cxx: g++-11, cc: gcc-11}, {cxx: clang++, cc: clang} ]
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build
|
||||
run: |
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=${{ matrix.compiler.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bout -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
cmake --build ./out/
|
||||
- name: Test
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=/usr/icu78-64/lib/
|
||||
GC_FREE_SPACE_DIVISOR=1 $RUNNER --engine="${{ github.workspace }}/out/escargot" --test262-extra-arg="--skip intl402 --skip sm" test262 chakracore spidermonkey v8 new-es
|
||||
|
||||
build-test-on-riscv64-release:
|
||||
debugger_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build in riscv64 container
|
||||
uses: uraimo/run-on-arch-action@v3
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
arch: riscv64
|
||||
distro: ubuntu22.04
|
||||
|
||||
# Install deps into the container. With the token, the container will be cached
|
||||
# The image is cached publically like a package
|
||||
githubToken: ${{ github.token }}
|
||||
|
||||
install: |
|
||||
apt-get update
|
||||
apt-get install -y cmake build-essential ninja-build pkg-config python3 git libicu-dev
|
||||
run: |
|
||||
cmake -H. -Bout/riscv64 -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
ninja -Cout/riscv64
|
||||
python3 ./tools/run-tests.py --engine="./out/riscv64/escargot" new-es intl sunspider-js
|
||||
|
||||
build-test-debugger:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
python-version: '3.x'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build
|
||||
- name: Install ICU
|
||||
run: |
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_amd64.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_DEBUGGER=1 -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_DEBUGGER=1 -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/debugger $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/debugger $BUILD_OPTIONS
|
||||
ninja -Cout/debugger
|
||||
- name: Debugger Test
|
||||
run: |
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/debugger/escargot" debugger-server-source
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/debugger/escargot" debugger-client-source
|
||||
|
||||
build-test-api:
|
||||
api_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
run: |
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_i386.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_amd64.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
- name: Build x86/x64
|
||||
env:
|
||||
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_DEBUGGER=1 -DESCARGOT_USE_EXTENDED_API=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_USE_EXTENDED_API=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
BUILD_OPTIONS_X86: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/cctest/x86 $BUILD_OPTIONS_X86
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/cctest/x86 $BUILD_OPTIONS_X86
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/cctest/x64 $BUILD_OPTIONS_X64
|
||||
ninja -Cout/cctest/x86
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/cctest/x64 $BUILD_OPTIONS_X64
|
||||
ninja -Cout/cctest/x64
|
||||
- name: Run Test
|
||||
run: |
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/cctest/x86/cctest" cctest
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/cctest/x64/cctest" cctest
|
||||
|
||||
build-test-codecache:
|
||||
codecache_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
# for i386 ICU
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
|
||||
sudo apt-get install -y libicu-dev:i386 # install i386 ICU
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
run: |
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_i386.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_amd64.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_CODE_CACHE=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/codecache/x86 $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/codecache/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/codecache/x86
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_CODE_CACHE=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/codecache/x64 $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/codecache/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/codecache/x64
|
||||
- name: Build x64 Release Mode
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/codecache/release/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/codecache/release/x64
|
||||
- name: Run x86 test
|
||||
run: |
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/codecache/x86/escargot" sunspider-js
|
||||
|
|
@ -650,67 +307,103 @@ jobs:
|
|||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" octane-loading
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" octane-loading
|
||||
rm -rf $HOME/Escargot-cache/
|
||||
- name: Run x64 release test
|
||||
run: |
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/release/x64/escargot" web-tooling-benchmark
|
||||
rm -rf $HOME/Escargot-cache/
|
||||
- name: Handle error cases
|
||||
run: |
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
rm $HOME/Escargot-cache/2728638815_17149
|
||||
rm $HOME/Escargot-cache/3217641879501852439
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
ls -1q $HOME/Escargot-cache/ | wc -l
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
rm $HOME/Escargot-cache/cache_list
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
build-test-wasmjs:
|
||||
wasm_js_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
submodules: true
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '2.7'
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib make g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build ICU(32)
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu-build/
|
||||
cd $GITHUB_WORKSPACE/icu-build/icu4c/source
|
||||
LDFLAGS="-m32 -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/" CFLAGS="-m32" CXXFLAGS="-m32" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu32/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build ICU(64)
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_i386.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_67.1-6ubuntu2_amd64.deb
|
||||
dpkg -X libicu-dev_67.1-6ubuntu2_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
- name: Patch WABT
|
||||
working-directory: ./third_party/wasm/wabt
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
cp ../../../tools/test/wasm-js/wabt_patch .
|
||||
patch -p0 < wabt_patch
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_WASM=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/wasm/x86 $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/wasm/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/wasm/x86
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/wasm/x64 $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/wasm/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/wasm/x64
|
||||
- name: Run x86 test
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu32/lib
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/wasm/x86/escargot" wasm-js
|
||||
run: $RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/wasm/x86/escargot" wasm-js
|
||||
- name: Run x64 test
|
||||
run: $RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/wasm/x64/escargot" wasm-js
|
||||
|
||||
coverity_scan:
|
||||
if: ${{ github.repository == 'Samsung/escargot' && github.event_name == 'push' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu64/lib
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/wasm/x64/escargot" wasm-js
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 60
|
||||
sudo apt update
|
||||
sudo apt install -y ninja-build
|
||||
- name: Patch WABT
|
||||
working-directory: ./third_party/wasm/wabt
|
||||
run: |
|
||||
cp ../../../tools/test/wasm-js/wabt_patch .
|
||||
patch -p0 < wabt_patch
|
||||
- name: Download Coverity Tool
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
run: |
|
||||
wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=Samsung%2Fescargot" -O cov-analysis-linux64.tar.gz
|
||||
mkdir cov-analysis-linux64
|
||||
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_CODE_CACHE=ON -DESCARGOT_WASM=ON -DESCARGOT_OUTPUT=shell_test -GNinja
|
||||
run: |
|
||||
export PATH=$GITHUB_WORKSPACE/cov-analysis-linux64/bin:$PATH
|
||||
cmake -H. -Bout/coverity_scan $BUILD_OPTIONS
|
||||
cov-build --dir cov-int ninja -Cout/coverity_scan
|
||||
- name: Submit
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
NOTI_MAIL: ${{ secrets.COVERITY_SCAN_MAIL }}
|
||||
run: |
|
||||
tar czvf escargot.tgz cov-int
|
||||
curl \
|
||||
--form token=$TOKEN \
|
||||
--form email=$NOTI_MAIL \
|
||||
--form file=@escargot.tgz \
|
||||
--form version="3.0.0" \
|
||||
--form description="escargot coverity scan" \
|
||||
https://scan.coverity.com/builds?project=Samsung%2Fescargot
|
||||
|
|
|
|||
11
.github/workflows/gbs.conf
vendored
|
|
@ -1,11 +0,0 @@
|
|||
[general]
|
||||
profile = profile.tizen
|
||||
|
||||
[profile.tizen]
|
||||
repos = repo.tizen_base_reference,repo.tizen_reference
|
||||
|
||||
[repo.tizen_reference]
|
||||
url = https://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Unified/reference/repos/standard/packages/
|
||||
|
||||
[repo.tizen_base_reference]
|
||||
url = https://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base/reference/repos/standard/packages/
|
||||
322
.github/workflows/release.yml
vendored
|
|
@ -1,322 +0,0 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
RUNNER: tools/run-tests.py
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_DEPLOY=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
|
||||
jobs:
|
||||
build-macOS:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-15, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c zip
|
||||
- name: Build x64
|
||||
run: |
|
||||
# check cpu
|
||||
sysctl -a | grep machdep.cpu
|
||||
# add icu path to pkg_config_path
|
||||
export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
|
||||
echo $PKG_CONFIG_PATH
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/ $BUILD_OPTIONS
|
||||
ninja -Cout/
|
||||
- name: Check
|
||||
run: |
|
||||
file out/escargot
|
||||
strip out/escargot
|
||||
|
||||
# set deploy directory
|
||||
mkdir -p deploy
|
||||
|
||||
# set escargot
|
||||
cp out/escargot ./deploy/.
|
||||
LIBS=$(otool -L ./deploy/escargot | grep "icu" | awk '{print $1}')
|
||||
for LIB in $LIBS; do
|
||||
BASENAME=$(basename "$LIB")
|
||||
install_name_tool -change "$LIB" "@executable_path/$BASENAME" deploy/escargot
|
||||
done
|
||||
|
||||
# set icu libs
|
||||
ICU_LIBS=("libicuuc" "libicui18n" "libicudata")
|
||||
ICU_SOURCE_PATH="$(brew --prefix icu4c)/lib"
|
||||
ICU_VERSION=$(find "$ICU_SOURCE_PATH" -name "libicuuc.*.dylib" | grep -oE '\.[0-9]+\.' | head -n 1 | tr -d '.')
|
||||
|
||||
if [ -z "$ICU_VERSION" ]; then
|
||||
echo "ICU version could not be detected."
|
||||
exit 1
|
||||
else
|
||||
echo "Detected ICU Version: $ICU_VERSION"
|
||||
fi
|
||||
|
||||
for LIB in "${ICU_LIBS[@]}"; do
|
||||
cp -a $ICU_SOURCE_PATH/$LIB.*.dylib ./deploy/.
|
||||
install_name_tool -id "@loader_path/$LIB.$ICU_VERSION.dylib" "./deploy/$LIB.$ICU_VERSION.dylib"
|
||||
done
|
||||
|
||||
# check results
|
||||
echo "Check results..."
|
||||
ls ./deploy
|
||||
otool -L ./deploy/escargot
|
||||
otool -L ./deploy/libicu*.dylib
|
||||
|
||||
# Ad-hoc sign
|
||||
set -e
|
||||
cd deploy
|
||||
for f in libicu*.dylib; do [ -e "$f" ] || continue; codesign -f -s - "$f"; done
|
||||
codesign --force --deep -s - ./escargot
|
||||
for f in ./escargot libicu*.dylib; do [ -e "$f" ] || continue; codesign --verify --strict --verbose=6 "$f"; done
|
||||
cd ..
|
||||
|
||||
# run test
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/deploy/escargot" new-es
|
||||
|
||||
# zip results
|
||||
if [ "${{ matrix.os }}" == "macos-15" ]; then
|
||||
zip -j escargot-mac64.zip deploy/*
|
||||
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
|
||||
zip -j escargot-mac64arm.zip deploy/*
|
||||
fi
|
||||
- name: Upload mac64
|
||||
if: ${{ matrix.os == 'macos-15' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-mac64
|
||||
path: ./escargot-mac64.zip
|
||||
- name: Upload mac64arm
|
||||
if: ${{ matrix.os == 'macos-latest' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-mac64arm
|
||||
path: ./escargot-mac64arm.zip
|
||||
|
||||
build-linux:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
# for i386 ICU
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build libicu-dev gcc-multilib g++-multilib zip patchelf
|
||||
sudo apt-get install -y libicu-dev:i386 # install i386 ICU
|
||||
- name: Build x86/x64
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/x86 -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_TEMPORAL=ON $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/x64 -DESCARGOT_TEMPORAL=ON $BUILD_OPTIONS
|
||||
ninja -Cout/x86
|
||||
ninja -Cout/x64
|
||||
- name: Check
|
||||
run: |
|
||||
file out/x86/escargot
|
||||
file out/x64/escargot
|
||||
strip out/x86/escargot
|
||||
strip out/x64/escargot
|
||||
# set locale
|
||||
sudo locale-gen en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
locale
|
||||
|
||||
# set deploy directory and copy escargot binary
|
||||
mkdir -p deploy-x86
|
||||
mkdir -p deploy-x64
|
||||
cp out/x86/escargot ./deploy-x86/.
|
||||
cp out/x64/escargot ./deploy-x64/.
|
||||
|
||||
# set icu libs
|
||||
ldd deploy-x86/escargot | grep "icu" | grep "=>" | awk '{print $3}' | xargs -I '{}' cp '{}' deploy-x86/
|
||||
ldd deploy-x64/escargot | grep "icu" | grep "=>" | awk '{print $3}' | xargs -I '{}' cp '{}' deploy-x64/
|
||||
for LIB in ./deploy-x86/libicu*; do
|
||||
patchelf --set-rpath '$ORIGIN' "$LIB"
|
||||
done
|
||||
for LIB in ./deploy-x64/libicu*; do
|
||||
patchelf --set-rpath '$ORIGIN' "$LIB"
|
||||
done
|
||||
|
||||
# check results
|
||||
echo "Check results..."
|
||||
ls ./deploy-x86
|
||||
ldd deploy-x86/escargot
|
||||
ldd deploy-x86/libicu*
|
||||
ls ./deploy-x64
|
||||
ldd deploy-x64/escargot
|
||||
ldd deploy-x64/libicu*
|
||||
|
||||
# run test
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/deploy-x86/escargot" new-es
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/deploy-x64/escargot" new-es
|
||||
|
||||
# zip results
|
||||
zip -j escargot-linux-x86.zip deploy-x86/*
|
||||
zip -j escargot-linux-x64.zip deploy-x64/*
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-linux
|
||||
path: escargot-linux-*.zip
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x86, x64]
|
||||
steps:
|
||||
- name: Set git cllf config
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: szenius/set-timezone@v2.0
|
||||
with:
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: "~3.25.0"
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Download and Install Visual C++ Redistributable
|
||||
shell: powershell
|
||||
run: |
|
||||
$vcRedistUrl64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath64 = "$env:TEMP\vc_redist.x64.exe"
|
||||
$vcRedistUrl32 = "https://aka.ms/vs/17/release/vc_redist.x86.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath32 = "$env:TEMP\vc_redist.x86.exe"
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl64"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl64 -OutFile $vcRedistPath64
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl32"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl32 -OutFile $vcRedistPath32
|
||||
|
||||
Write-Host "Installing Visual C++ Redistributable silently"
|
||||
Start-Process -FilePath $vcRedistPath64 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Start-Process -FilePath $vcRedistPath32 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Write-Host "Visual C++ Redistributable installation complete."
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: ${{ matrix.arch }}
|
||||
sdk: "10.0.26100.0"
|
||||
- name: Install zip if not available
|
||||
run: |
|
||||
if (-Not (Get-Command zip -ErrorAction SilentlyContinue)) {
|
||||
choco install zip -y
|
||||
}
|
||||
- name: Build ${{ matrix.arch }}
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -DESCARGOT_ARCH=${{ matrix.arch }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_WASM=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake --build out/ --config Release
|
||||
- name: Check
|
||||
run: |
|
||||
python tools\run-tests.py --engine=%cd%\out\escargot.exe new-es
|
||||
rename out\escargot.exe escargot-win-${{ matrix.arch }}.exe
|
||||
zip -j escargot-win-${{ matrix.arch}}.zip out\escargot-win-${{ matrix.arch }}.exe
|
||||
shell: cmd
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-win-${{ matrix.arch }}
|
||||
path: escargot-win-${{ matrix.arch }}.zip
|
||||
|
||||
check-build-mac64:
|
||||
needs: [build-macOS]
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-mac64
|
||||
merge-multiple: true
|
||||
- name: Check
|
||||
run: |
|
||||
unzip artifacts/escargot-mac64.zip -d artifacts
|
||||
otool -L artifacts/escargot
|
||||
otool -L artifacts/*.dylib
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/artifacts/escargot" new-es
|
||||
|
||||
check-build-mac64arm:
|
||||
needs: [build-macOS]
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-mac64arm
|
||||
merge-multiple: true
|
||||
- name: Check
|
||||
run: |
|
||||
unzip artifacts/escargot-mac64arm.zip -d artifacts
|
||||
otool -L artifacts/escargot
|
||||
otool -L artifacts/*.dylib
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/artifacts/escargot" new-es
|
||||
|
||||
check-build-linux:
|
||||
needs: [build-linux]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-linux
|
||||
merge-multiple: true
|
||||
- name: Check
|
||||
run: |
|
||||
dpkg -l | grep libicu-dev
|
||||
mkdir -p result-x86
|
||||
mkdir -p result-x64
|
||||
unzip artifacts/escargot-linux-x86.zip -d result-x86
|
||||
unzip artifacts/escargot-linux-x64.zip -d result-x64
|
||||
ldd result-x86/escargot
|
||||
ldd result-x86/libicu*
|
||||
ldd result-x64/escargot
|
||||
ldd result-x64/libicu*
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/result-x86/escargot" new-es
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/result-x64/escargot" new-es
|
||||
|
||||
update-release:
|
||||
needs: [check-build-mac64, check-build-mac64arm, check-build-linux, build-windows]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-*
|
||||
merge-multiple: true
|
||||
- name: Upload to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
artifacts/escargot-*
|
||||
8
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
#error_report
|
||||
/escargot
|
||||
escargot
|
||||
escargot.x*
|
||||
.project
|
||||
.cproject
|
||||
|
|
@ -18,7 +18,7 @@ cscope.out
|
|||
#memps
|
||||
escargot.asm
|
||||
escargot.elf
|
||||
out/*
|
||||
out
|
||||
build.ninja
|
||||
rules.ninja
|
||||
.ninja_deps
|
||||
|
|
@ -38,6 +38,4 @@ cmake_install.cmake
|
|||
#etc
|
||||
.vscode
|
||||
EscargotInfo.h
|
||||
escargot.pc
|
||||
escargot_generated/*
|
||||
.vs/*
|
||||
third_party/wasm/config.h
|
||||
|
|
|
|||
421
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,421 @@
|
|||
image: 10.113.64.54:5000/escargot/escargot:latest
|
||||
build_x64_release:
|
||||
stage: build
|
||||
tags:
|
||||
- escargot_main_build
|
||||
before_script:
|
||||
- unset TIZEN_SDK_HOME
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/third_party/GCutil/index.lock
|
||||
- git submodule deinit -f third_party/GCutil
|
||||
- git submodule init
|
||||
- git submodule update third_party/GCutil
|
||||
- ARCH=x64 MODE=release ./build_third_party.sh
|
||||
- make clean
|
||||
script:
|
||||
- VENDORTEST=1 make x64.interpreter.release -j$(nproc)
|
||||
artifacts:
|
||||
paths:
|
||||
- out/linux/x64/interpreter/release/escargot
|
||||
|
||||
test_x64_release_sunspider:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: ./escargot test/vendortest/SunSpider/tests/sunspider-1.0.2/*.js; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_octane:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/octane/index.lock
|
||||
- git submodule deinit -f test/octane
|
||||
- git submodule init
|
||||
- git submodule update test/octane
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-octane | tail -1 > out/octane_result; if ! cat out/octane_result | grep -c 'Score' > /dev/null; then exit 1; fi
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_test262:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/test262/index.lock
|
||||
- git submodule deinit -f test/test262
|
||||
- git submodule init
|
||||
- git submodule update test/test262
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-test262; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_jetstream_only_cdjs:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-jetstream-only-cdjs; if cat test/vendortest/driver/jetstream/jetstream-result-raw.res | grep -c 'NaN' > /dev/null; then exit 1; fi; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_jetstream_only_simple:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-jetstream-only-simple; if cat test/vendortest/driver/jetstream/jetstream-result-raw.res | grep -c 'NaN' > /dev/null; then exit 1; fi; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_spidermonkey:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-spidermonkey-full; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_internal:
|
||||
stage: test
|
||||
tags:
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-internal-test; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_v8:
|
||||
stage: test
|
||||
tags:
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-v8; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_chakracore:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-chakracore; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
test_x64_release_jsc:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/release/escargot ./escargot
|
||||
script: make run-jsc-stress; exit $?;
|
||||
dependencies:
|
||||
- build_x64_release
|
||||
|
||||
###############################################################################
|
||||
|
||||
build_x86_release:
|
||||
stage: build
|
||||
tags:
|
||||
- escargot_main_build
|
||||
before_script:
|
||||
- unset TIZEN_SDK_HOME
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/third_party/GCutil/index.lock
|
||||
- git submodule deinit -f third_party/GCutil
|
||||
- git submodule init
|
||||
- git submodule update third_party/GCutil
|
||||
- ARCH=x86 MODE=release ./build_third_party.sh
|
||||
- make clean
|
||||
script:
|
||||
- VENDORTEST=1 make x86.interpreter.release -j$(nproc)
|
||||
artifacts:
|
||||
paths:
|
||||
- out/linux/x86/interpreter/release/escargot
|
||||
|
||||
test_x86_release_sunspider:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: ./escargot test/vendortest/SunSpider/tests/sunspider-1.0.2/*.js; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_octane:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/octane/index.lock
|
||||
- git submodule deinit -f test/octane
|
||||
- git submodule init
|
||||
- git submodule update test/octane
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-octane | tail -1 > out/octane_result; if ! cat out/octane_result | grep -c 'Score' > /dev/null; then exit 1; fi
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_test262:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/test262/index.lock
|
||||
- git submodule deinit -f test/test262
|
||||
- git submodule init
|
||||
- git submodule update test/test262
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-test262; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_jetstream_only_cdjs:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-jetstream-only-cdjs; if cat test/vendortest/driver/jetstream/jetstream-result-raw.res | grep -c 'NaN' > /dev/null; then exit 1; fi; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_jetstream_only_simple:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-jetstream-only-simple; if cat test/vendortest/driver/jetstream/jetstream-result-raw.res | grep -c 'NaN' > /dev/null; then exit 1; fi; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_spidermonkey:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-spidermonkey-full; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_internal:
|
||||
stage: test
|
||||
tags:
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-internal-test; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_v8:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-v8; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_chakracore:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-chakracore; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
test_x86_release_jsc:
|
||||
stage: test
|
||||
tags:
|
||||
- escargot_allow_slow
|
||||
before_script:
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/release/escargot ./escargot
|
||||
script: make run-jsc-stress; exit $?;
|
||||
dependencies:
|
||||
- build_x86_release
|
||||
|
||||
###############################################################################
|
||||
|
||||
build_x64_debug:
|
||||
stage: build
|
||||
tags:
|
||||
- escargot_main_build
|
||||
before_script:
|
||||
- unset TIZEN_SDK_HOME
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/third_party/GCutil/index.lock
|
||||
- git submodule deinit -f third_party/GCutil
|
||||
- git submodule init
|
||||
- git submodule update third_party/GCutil
|
||||
- ARCH=x64 MODE=debug ./build_third_party.sh
|
||||
- make clean
|
||||
script:
|
||||
- VENDORTEST=1 make x64.interpreter.debug -j$(nproc)
|
||||
artifacts:
|
||||
paths:
|
||||
- out/linux/x64/interpreter/debug/escargot
|
||||
|
||||
test_x64_debug_sunspider:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x64/interpreter/debug/escargot ./escargot
|
||||
script: ./escargot test/vendortest/SunSpider/tests/sunspider-1.0.2/*.js; exit $?;
|
||||
dependencies:
|
||||
- build_x64_debug
|
||||
|
||||
#test_x64_debug_octane:
|
||||
# stage: test
|
||||
# before_script:
|
||||
# - git submodule deinit -f test/octane
|
||||
# - git submodule init
|
||||
# - git submodule update test/octane
|
||||
# - cp out/linux/x64/interpreter/debug/escargot ./escargot
|
||||
# script: make run-octane | tail -1 > out/octane_result; if ! cat out/octane_result | grep -c 'Score' > /dev/null; then exit 1; fi
|
||||
# dependencies:
|
||||
# - build_x64_debug
|
||||
#
|
||||
#test_x64_debug_test262:
|
||||
# stage: test
|
||||
# before_script:
|
||||
# - git submodule deinit -f test/test262
|
||||
# - git submodule init
|
||||
# - git submodule update test/test262
|
||||
# - cp out/linux/x64/interpreter/debug/escargot ./escargot
|
||||
# script: make run-test262; exit $?;
|
||||
# dependencies:
|
||||
# - build_x64_debug
|
||||
#
|
||||
################################################################################
|
||||
|
||||
build_x86_debug:
|
||||
stage: build
|
||||
tags:
|
||||
- escargot_main_build
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/third_party/GCutil/index.lock
|
||||
- unset TIZEN_SDK_HOME
|
||||
- git submodule deinit -f third_party/GCutil
|
||||
- git submodule init
|
||||
- git submodule update third_party/GCutil
|
||||
- ARCH=x86 MODE=debug ./build_third_party.sh
|
||||
- make clean
|
||||
script:
|
||||
- VENDORTEST=1 make x86.interpreter.debug -j$(nproc)
|
||||
artifacts:
|
||||
paths:
|
||||
- out/linux/x86/interpreter/debug/escargot
|
||||
|
||||
test_x86_debug_sunspider:
|
||||
stage: test
|
||||
before_script:
|
||||
- rm -f .git/index.lock
|
||||
- rm -f .git/modules/test/vendortest/index.lock
|
||||
- git submodule deinit -f test/vendortest
|
||||
- git submodule init
|
||||
- git submodule update test/vendortest
|
||||
- cp out/linux/x86/interpreter/debug/escargot ./escargot
|
||||
script: ./escargot test/vendortest/SunSpider/tests/sunspider-1.0.2/*.js; exit $?;
|
||||
dependencies:
|
||||
- build_x86_debug
|
||||
|
||||
#test_x86_debug_octane:
|
||||
# stage: test
|
||||
# before_script:
|
||||
# - git submodule deinit -f test/octane
|
||||
# - git submodule init
|
||||
# - git submodule update test/octane
|
||||
# - cp out/linux/x86/interpreter/debug/escargot ./escargot
|
||||
# script: make run-octane | tail -1 > out/octane_result; if ! cat out/octane_result | grep -c 'Score' > /dev/null; then exit 1; fi
|
||||
# dependencies:
|
||||
# - build_x86_debug
|
||||
#
|
||||
#test_x86_debug_test262:
|
||||
# stage: test
|
||||
# before_script:
|
||||
# - git submodule deinit -f test/test262
|
||||
# - git submodule init
|
||||
# - git submodule update test/test262
|
||||
# script: make run-test262; exit $?;
|
||||
# dependencies:
|
||||
# - build_x86_debug
|
||||
#
|
||||
22
.gitmodules
vendored
|
|
@ -2,6 +2,10 @@
|
|||
path = third_party/GCutil
|
||||
url = https://github.com/Samsung/gcutil.git
|
||||
ignore = untracked
|
||||
[submodule "third_party/windows/icu"]
|
||||
path = third_party/windows/icu
|
||||
url = https://github.com/Samsung/icu.git
|
||||
ignore = untracked
|
||||
[submodule "test/vendortest"]
|
||||
path = test/vendortest
|
||||
url = https://github.com/Samsung/js_vendor_tc.git
|
||||
|
|
@ -15,18 +19,14 @@
|
|||
url = https://github.com/chromium/octane.git
|
||||
ignore = untracked
|
||||
[submodule "test/kangax"]
|
||||
path = test/kangax
|
||||
url = https://github.com/kangax/compat-table.git
|
||||
path = test/kangax
|
||||
url = https://github.com/kangax/compat-table.git
|
||||
ignore = untracked
|
||||
[submodule "third_party/googletest"]
|
||||
path = third_party/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
path = third_party/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
ignore = untracked
|
||||
[submodule "third_party/walrus"]
|
||||
path = third_party/walrus
|
||||
url = https://github.com/Samsung/walrus.git
|
||||
ignore = untracked
|
||||
[submodule "test/web-tooling-benchmark"]
|
||||
path = test/web-tooling-benchmark
|
||||
url = https://github.com/v8/web-tooling-benchmark
|
||||
[submodule "third_party/wasm/wabt"]
|
||||
path = third_party/wasm/wabt
|
||||
url = https://github.com/WebAssembly/wabt
|
||||
ignore = untracked
|
||||
|
|
|
|||
|
|
@ -1,52 +1,15 @@
|
|||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12 FATAL_ERROR)
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
|
||||
|
||||
PROJECT (ESCARGOT)
|
||||
|
||||
# CONFIGURATION
|
||||
SET (CMAKE_VERBOSE_MAKEFILE true)
|
||||
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
MESSAGE(STATUS "CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME})
|
||||
MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
|
||||
|
||||
IF (NOT DEFINED ESCARGOT_ARCH)
|
||||
IF (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "X86" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86"
|
||||
OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
|
||||
SET(ESCARGOT_ARCH "x86")
|
||||
ELSEIF (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64"
|
||||
OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "EM64T")
|
||||
SET(ESCARGOT_ARCH "x64")
|
||||
ELSEIF (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm32"
|
||||
OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
|
||||
SET(ESCARGOT_ARCH "arm")
|
||||
ELSEIF (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
|
||||
SET(ESCARGOT_ARCH "aarch64")
|
||||
ELSEIF (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
|
||||
SET(ESCARGOT_ARCH "riscv64")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF (NOT DEFINED ESCARGOT_HOST)
|
||||
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" OR ${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
|
||||
SET(ESCARGOT_HOST "windows")
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
SET(ESCARGOT_HOST "android")
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
SET(ESCARGOT_HOST "darwin")
|
||||
ELSE()
|
||||
SET(ESCARGOT_HOST "linux")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF (NOT DEFINED ESCARGOT_MODE)
|
||||
SET (ESCARGOT_MODE "release")
|
||||
ENDIF()
|
||||
IF (NOT DEFINED ESCARGOT_OUTPUT)
|
||||
SET (ESCARGOT_OUTPUT "shell")
|
||||
ENDIF()
|
||||
IF (NOT DEFINED ESCARGOT_THREADING)
|
||||
SET (ESCARGOT_THREADING ON)
|
||||
ENDIF()
|
||||
#SET (ESCARGOT_HOST "linux" CACHE STRING "ESCARGOT_HOST")
|
||||
#SET (ESCARGOT_ARCH "x86" CACHE STRING "ESCARGOT_ARCH")
|
||||
#SET (ESCARGOT_MODE "release" CACHE STRING "ESCARGOT_MODE")
|
||||
#SET (ESCARGOT_OUTPUT "shell" CACHE STRING "ESCARGOT_OUTPUT")
|
||||
SET (ESCARGOT_ASAN "0" CACHE STRING "ESCARGOT_ASAN")
|
||||
|
||||
SET (ESCARGOT_TARGET escargot)
|
||||
SET (ESCARGOT_CCTEST_TARGET cctest)
|
||||
|
|
@ -57,34 +20,3 @@ PROCESSORCOUNT (NPROCS)
|
|||
# INCLUDE CMAKE FILES
|
||||
INCLUDE (${PROJECT_SOURCE_DIR}/build/config.cmake)
|
||||
INCLUDE (${PROJECT_SOURCE_DIR}/build/escargot.cmake)
|
||||
|
||||
# Pkgconfig
|
||||
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/packaging/escargot.pc.in ${CMAKE_BINARY_DIR}/escargot.pc @ONLY)
|
||||
|
||||
IF (ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY AND ESCARGOT_TLS_ACCESS_BY_ADDRESS)
|
||||
MESSAGE(FATAL_ERROR "You cannot enable ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY and ESCARGOT_TLS_ACCESS_BY_ADDRESS at same time")
|
||||
ENDIF()
|
||||
|
||||
MESSAGE(STATUS "Escargot Arch: " ${ESCARGOT_ARCH})
|
||||
MESSAGE(STATUS "Escargot Host: " ${ESCARGOT_HOST})
|
||||
MESSAGE(STATUS "Escargot Mode: " ${ESCARGOT_MODE})
|
||||
MESSAGE(STATUS "Escargot Output: " ${ESCARGOT_OUTPUT})
|
||||
MESSAGE(STATUS "--------------------------------------------------------------------------------")
|
||||
MESSAGE(STATUS "ESCARGOT_DEFINITIONS: " ${ESCARGOT_DEFINITIONS})
|
||||
MESSAGE(STATUS "ESCARGOT_CXXFLAGS: " ${ESCARGOT_CXXFLAGS})
|
||||
MESSAGE(STATUS "ESCARGOT_LDFLAGS: " ${ESCARGOT_LDFLAGS})
|
||||
MESSAGE(STATUS "ESCARGOT_INCDIRS: " ${ESCARGOT_INCDIRS})
|
||||
MESSAGE(STATUS "ESCARGOT_LIBRARIES: " ${ESCARGOT_LIBRARIES})
|
||||
MESSAGE(STATUS "ESCARGOT_LIBICU_SUPPORT: " ${ESCARGOT_LIBICU_SUPPORT})
|
||||
MESSAGE(STATUS "ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN: " ${ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN})
|
||||
MESSAGE(STATUS "ESCARGOT_SMALL_CONFIG: " ${ESCARGOT_SMALL_CONFIG})
|
||||
MESSAGE(STATUS "ESCARGOT_CODE_CACHE: " ${ESCARGOT_CODE_CACHE})
|
||||
MESSAGE(STATUS "ESCARGOT_WASM: " ${ESCARGOT_WASM})
|
||||
MESSAGE(STATUS "ESCARGOT_THREADING: " ${ESCARGOT_THREADING})
|
||||
MESSAGE(STATUS "ESCARGOT_TLS_ACCESS_BY_ADDRESS: " ${ESCARGOT_TLS_ACCESS_BY_ADDRESS})
|
||||
MESSAGE(STATUS "ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY: " ${ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY})
|
||||
MESSAGE(STATUS "ESCARGOT_EXPORT_ALL: " ${ESCARGOT_EXPORT_ALL})
|
||||
MESSAGE(STATUS "ESCARGOT_TCO: " ${ESCARGOT_TCO})
|
||||
MESSAGE(STATUS "ESCARGOT_TEMPORAL: " ${ESCARGOT_TEMPORAL})
|
||||
MESSAGE(STATUS "ESCARGOT_SHADOWREALM: " ${ESCARGOT_SHADOWREALM})
|
||||
MESSAGE(STATUS "ESCARGOT_TEST: " ${ESCARGOT_TEST})
|
||||
|
|
|
|||
87
Jenkinsfile
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
def isPr() {
|
||||
env.CHANGE_ID != null
|
||||
}
|
||||
node {
|
||||
try {
|
||||
stage("Get source") {
|
||||
def url = 'https://github.com/Samsung/escargot.git'
|
||||
|
||||
if (isPr()) {
|
||||
def refspec = "+refs/pull/${env.CHANGE_ID}/head:refs/remotes/origin/PR-${env.CHANGE_ID} +refs/heads/master:refs/remotes/origin/master"
|
||||
def extensions = [[$class: 'PreBuildMerge', options: [mergeRemote: "refs/remotes/origin", mergeTarget: "PR-${env.CHANGE_ID}"]]]
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: extensions,
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
refspec: refspec,
|
||||
url: url
|
||||
]]
|
||||
])
|
||||
} else {
|
||||
def refspec = "+refs/heads/master:refs/remotes/origin/master"
|
||||
def extensions = []
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [[$class: 'WipeWorkspace']],
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
refspec: refspec,
|
||||
url: url
|
||||
]]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
stage('Submodule update') {
|
||||
sh 'git submodule update --init test third_party/GCutil'
|
||||
}
|
||||
|
||||
stage('Prepare build(gcc)') {
|
||||
sh 'LDFLAGS=" -L/usr/icu32/lib/ -Wl,-rpath=/usr/icu32/lib/" PKG_CONFIG_PATH="/usr/icu32/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_OUTPUT=shell_test -GNinja'
|
||||
sh 'LDFLAGS=" -L/usr/icu32/lib/ -Wl,-rpath=/usr/icu32/lib/" PKG_CONFIG_PATH="/usr/icu32/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux_release -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_OUTPUT=shell_test -GNinja'
|
||||
sh 'gcc -shared -m32 -fPIC -o backtrace-hooking-32.so tools/test/test262/backtrace-hooking.c'
|
||||
sh 'LDFLAGS=" -L/usr/icu64/lib/ -Wl,-rpath=/usr/icu64/lib/" PKG_CONFIG_PATH="/usr/icu64/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux64 -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_OUTPUT=shell_test -GNinja'
|
||||
sh 'LDFLAGS=" -L/usr/icu64/lib/ -Wl,-rpath=/usr/icu64/lib/" PKG_CONFIG_PATH="/usr/icu64/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux64_release -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_OUTPUT=shell_test -GNinja'
|
||||
}
|
||||
|
||||
stage('Build(gcc)') {
|
||||
parallel (
|
||||
'release-build' : {
|
||||
sh 'cd build/out_linux/; ninja '
|
||||
sh 'cd build/out_linux64/; ninja'
|
||||
},
|
||||
'debug-build' : {
|
||||
sh 'cd build/out_linux_release/; ninja'
|
||||
sh 'cd build/out_linux64_release/; ninja'
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
stage('Running test') {
|
||||
timeout(30) {
|
||||
parallel (
|
||||
'release-32bit-test262' : {
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux_release/escargot" test262'
|
||||
},
|
||||
'debug-32bit-test262' : {
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 ESCARGOT_LD_PRELOAD=${WORKSPACE}/backtrace-hooking-32.so tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux/escargot" test262'
|
||||
},
|
||||
'release-64bit-test262' : {
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64_release/escargot" test262'
|
||||
},
|
||||
'kangax test-suites' : {
|
||||
sh 'python tools/kangax/run-kangax.py --engine="${WORKSPACE}/build/out_linux64/escargot"'
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
throw e
|
||||
} finally {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
MIT-style License
|
||||
|
||||
Copyright (c) 1988-1989 Hans-J. Boehm, Alan J. Demers
|
||||
Copyright (c) 1991-1996 by Xerox Corporation. All rights reserved.
|
||||
Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
|
||||
Copyright (c) 1998 by Fergus Henderson. All rights reserved.
|
||||
Copyright (c) 1999-2001 by Red Hat, Inc. All rights reserved.
|
||||
Copyright (c) 1999-2011 Hewlett-Packard Development Company, L.P.
|
||||
Copyright (c) 2004-2005 Andrei Polushin
|
||||
Copyright (c) 2007 Free Software Foundation, Inc.
|
||||
Copyright (c) 2008-2022 Ivan Maidanski
|
||||
Copyright (c) 2011 Ludovic Courtes
|
||||
Copyright (c) 2018 Petter A. Urkedal
|
||||
|
||||
|
||||
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
||||
OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
||||
|
||||
Permission is hereby granted to use or copy this program
|
||||
for any purpose, provided the above notices are retained on all copies.
|
||||
Permission to modify the code and to distribute modified code is granted,
|
||||
provided the above notices are retained, and a notice that the code was
|
||||
modified is included with the above copyright notice.
|
||||
|
||||
|
||||
Several files (gc/gc_allocator.h, extra/msvc_dbg.c) come with slightly
|
||||
different licenses, though they are all similar in spirit (the exact
|
||||
licensing terms are given at the beginning of the corresponding source file).
|
||||
|
||||
A few of the files needed to use the GNU-style build procedure come with
|
||||
a modified GPL license that appears not to significantly restrict use of
|
||||
the collector, though use of those files for a purpose other than building
|
||||
the collector may require the resulting code to be covered by the GPL.
|
||||
204
README.md
|
|
@ -2,71 +2,17 @@
|
|||
|
||||
[](LICENSE)
|
||||
[](https://github.com/Samsung/escargot/releases)
|
||||
[](https://github.com/Samsung/escargot/actions/workflows/es-actions.yml)
|
||||

|
||||
[](https://github.com/Samsung/escargot/actions)
|
||||
[](https://scan.coverity.com/projects/samsung-escargot)
|
||||
[](https://codecov.io/gh/Samsung/escargot)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Escargot is a lightweight JavaScript engine developed by [Samsung](https://github.com/Samsung), designed specifically for resource-constrained environments. It is optimized for performance and low memory usage, making it ideal for use in embedded systems, IoT devices, and other applications where resources are limited.
|
||||
|
||||
Key features of Escargot include:
|
||||
* **ECMAScript Compliance**: Escargot supports a significant portion of the latest ECMAScript version ([ECMAScript 2025](https://262.ecma-international.org/16.0/)), ensuring compatibility with modern JavaScript standards while maintaining a lightweight footprint.
|
||||
* **Memory Efficiency**: The engine is designed with memory constraints in mind, making it suitable for devices with limited RAM and storage.
|
||||
* **Performance Optimization**: Escargot implements various optimization techniques to ensure fast execution of JavaScript code, even on low-power devices.
|
||||
* **Extensibility**: The engine can be customized and extended to meet the specific needs of different applications, providing flexibility for developers.
|
||||
|
||||
Escargot is an open-source project that allows developers to contribute to its development or use it in their own projects, while also powering several services in Samsung products. The engine's design prioritizes simplicity and efficiency, making it an excellent choice for developers working in embedded or resource-limited environments.
|
||||
|
||||
|
||||
## Contents 📋
|
||||
* [Building](#Building-)
|
||||
* [Linux](#Linux)
|
||||
* [macOS](#macOS)
|
||||
* [Android](#Android)
|
||||
* [Windows](#Windows)
|
||||
* [Testing](#Testing-)
|
||||
* [Contributing](#Contributing-)
|
||||
* [Research Papers](#Research-Papers-)
|
||||
* [License](#License-)
|
||||
|
||||
## Building 🛠️
|
||||
|
||||
### Supported Platforms and Architectures
|
||||
| **OS** | **Architecture** |
|
||||
|-|-|
|
||||
| **Linux(Ubuntu)** | x86/x64/arm/aarch64 |
|
||||
| macOS | x64/aarch64 |
|
||||
| Windows | Win32/x64 |
|
||||
| Android | x86/x64/arm/aarch64 |
|
||||
|
||||
### Build Options
|
||||
|
||||
The following build options are supported when generating build rules using cmake.
|
||||
|
||||
| **Option** | **Description** | **Flag** | **Value** | **Default** |
|
||||
|-|-|-|-|-|
|
||||
| **HOST** | Choose target platform | -DESCARGOT_HOST | linux/darwin/android/windows | |
|
||||
| **ARCH** | Choose target architecture | -DESCARGOT_ARCH | x64/x86/arm/aarch64 | |
|
||||
| **MODE** | Choose release/debug mode | -DESCARGOT_MODE | release/debug | release |
|
||||
| **OUTPUT** | Choose build output type | -DESCARGOT_OUTPUT | shared_lib/static_lib/shell/cctest | shell |
|
||||
| **LIBICU** | Include libicu library | -DESCARGOT_LIBICU_SUPPORT | ON/OFF | ON |
|
||||
| **WASM** | Enable WebAssembly support | -DESCARGOT_WASM | ON/OFF | OFF |
|
||||
| **CODE_CACHE** | Enable code cache | -DESCARGOT_CODE_CACHE | ON/OFF | OFF |
|
||||
| **TCO** | Enable tail call optimization | -DESCARGOT_TCO | ON/OFF | OFF |
|
||||
| **THREADING** | Enable threading features (e.g. Atomics, SharedArrayBuffer) | -DESCARGOT_THREADING | ON/OFF | ON |
|
||||
| **TLS_ADDRESS_OFFSET** | Enable thread local storge access optimization(offset) | -DESCARGOT_TLS_ACCESS_BY_ADDRESS | ON/OFF | OFF |
|
||||
| **TLS_PTHREAD_KEY** | Enable thread local storge access optimization(pthread_key) | -DESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY | ON/OFF | OFF |
|
||||
| **TEMPORAL** | Enable Temporal support | -ESCARGOT_TEMPORAL | ON/OFF | OFF |
|
||||
| **SHADOWREALM** | Enable ShadowRealm support | -ESCARGOT_SHADOWREALM | ON/OFF | OFF |
|
||||
| **SMALL_CONFIG** | Enable aggressive memory optimizations for tiny devices | -DESCARGOT_SMALL_CONFIG | ON/OFF | OFF |
|
||||
| **TEST** | Enable additional features used only for testing | -DESCARGOT_TEST | ON/OFF | OFF |
|
||||
| **DEBUGGER** | Enable Debug server | -DESCARGOT_DEBUGGER | ON/OFF | OFF |
|
||||
|
||||
### Linux
|
||||
#### On Ubuntu Linux
|
||||
|
||||
General build prerequisites:
|
||||
```sh
|
||||
sudo apt-get install autoconf automake cmake libtool libicu-dev ninja-build pkg-config
|
||||
sudo apt-get install autoconf automake cmake libtool libicu-dev ninja-build
|
||||
```
|
||||
|
||||
Prerequisites for x86-64-to-x86 compilation:
|
||||
|
|
@ -75,120 +21,56 @@ sudo apt-get install gcc-multilib g++-multilib
|
|||
sudo apt-get install libicu-dev:i386
|
||||
```
|
||||
|
||||
Build Escargot:
|
||||
```sh
|
||||
git submodule update --init third_party # update submodules
|
||||
cmake -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell -GNinja
|
||||
ninja
|
||||
```
|
||||
#### On macOS
|
||||
|
||||
### macOS
|
||||
|
||||
General build prerequisites:
|
||||
```sh
|
||||
brew install autoconf automake cmake icu4c libtool ninja pkg-config
|
||||
|
||||
# add icu path to pkg_config_path (x64)
|
||||
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||||
# add icu path to pkg_config_path (arm64)
|
||||
export PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||||
```
|
||||
|
||||
Build Escargot:
|
||||
Note: For later build steps (cmake, pkg-config) to find ICU libraries, you may
|
||||
need to set the `PKG_CONFIG_PATH` environment variable, as instructed by brew.
|
||||
E.g.:
|
||||
|
||||
```sh
|
||||
git submodule update --init third_party # update submodules
|
||||
cmake -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell -GNinja
|
||||
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"
|
||||
```
|
||||
|
||||
## Build Escargot
|
||||
|
||||
```sh
|
||||
git clone https://github.com/Samsung/escargot.git
|
||||
cd escargot
|
||||
git submodule update --init third_party
|
||||
cmake -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell -GNinja
|
||||
ninja
|
||||
```
|
||||
|
||||
### Android
|
||||
#### Build options
|
||||
|
||||
Build prerequisites on Ubuntu:
|
||||
The following build options are supported when generating ninja rules using cmake.
|
||||
|
||||
* -DESCARGOT_HOST=[ linux | tizen_obs | darwin ]<br>
|
||||
Compile Escargot for Linux, Tizen, or macOS platform
|
||||
* -DESCARGOT_ARCH=[ x64 | x86 | arm | i686 | aarch64 ]<br>
|
||||
Compile Escargot for each architecture
|
||||
* -DESCARGOT_MODE=[ debug | release ]<br>
|
||||
Compile Escargot for either release or debug mode
|
||||
* -DESCARGOT_OUTPUT=[ shared_lib | static_lib | shell | shell_test | cctest ]<br>
|
||||
Define target output type
|
||||
* -DESCARGOT_LIBICU_SUPPORT=[ ON | OFF ]<br>
|
||||
Enable libicu library if set ON. (Optional, default = ON)
|
||||
|
||||
## Testing
|
||||
|
||||
First, get benchmarks and tests:
|
||||
```sh
|
||||
sudo apt install openjdk-17-jdk # require java 17
|
||||
git submodule update --init
|
||||
```
|
||||
|
||||
Build Escargot using gradle:
|
||||
### Benchmarks
|
||||
|
||||
Test run for each benchmark (Sunspider, Octane, V8, Chakracore, test262,
|
||||
SpiderMonkey, etc.):
|
||||
```sh
|
||||
git submodule update --init third_party # update submodules
|
||||
export ANDROID_SDK_ROOT=.... # set your android SDK root first
|
||||
cd build/android/
|
||||
./gradlew bundleReleaseAar # build escargot AAR
|
||||
./gradlew bundleHostJar # bundle jar for host
|
||||
./gradlew javadocJar # create java doc
|
||||
./gradlew sourcesJar # create sources jar
|
||||
|
||||
./gradlew assembleDebug # build debug test shell
|
||||
./gradlew :escargot:connectedDebugAndroidTest # run escargot-jni tests on android device
|
||||
./gradlew :escargot:testDebugUnitTest # run escargot-jni tests on host
|
||||
tools/run-tests.py --arch=x86_64 spidermonkey test262 v8
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
Install VS2022 with cmake and ninja.
|
||||
Open [ x86 Native Tools Command Prompt for VS 2022 | x64 Native Tools Command Prompt for VS 2022 ]
|
||||
|
||||
```sh
|
||||
git submodule update --init third_party # update submodules
|
||||
|
||||
CMake -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_NAME=[ Windows | WindowsStore ] -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=[ x86 | x64 ] -DCMAKE_GENERATOR_PLATFORM=[ Win32 | x64 ],version=10.0.18362.0 -DESCARGOT_ARCH=[ x86 | x64 ] -DESCARGOT_MODE=release -Bout -DESCARGOT_HOST=windows -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_THREADING=ON
|
||||
cd out
|
||||
msbuild ESCARGOT.sln /property:Configuration=Release /p:platform=[ Win32 | x64 ]
|
||||
```
|
||||
|
||||
## Debugger
|
||||
|
||||
Make sure Escargot is built with the `-DESCARGOT_DEBUGGER=1` flag (off by default) enabled;
|
||||
then start Escargot with the `--start-debug-server` option.
|
||||
|
||||
### Connect using a debugger client
|
||||
|
||||
- Escargot python debugger
|
||||
- run `./tools/debugger/debugger.py`; It will automatically connect to a debug server on the default port `6501`
|
||||
- run `./tools/debugger/debugger.py --help` for a list of options
|
||||
- [Visual Studio Code extension](https://github.com/Samsung/escargot-vscode-extension/?tab=readme-ov-file#how-to-use)
|
||||
- Chrome Devtools `⚠️ Early in development ⚠️`
|
||||
- Initial setup:
|
||||
- Navigate to [chrome://inspect](chrome://inspect)
|
||||
- Make sure *Discover network targets* is enabled; click configure
|
||||
- Add `localhost:6501` as a target; click Done
|
||||
- Usage:
|
||||
- The started debug server will be listed in the *Remote Target* list (If it is not, the page may need to be reloaded using the browser reload button)
|
||||
- Click `inspect`
|
||||
- A new window with the Chrome Devtools debugger UI will open
|
||||
|
||||
## Testing ✅
|
||||
|
||||
Escargot supports various benchmark sets, which can be run using the [tools/run-tests.py](https://github.com/Samsung/escargot/blob/master/tools/run-tests.py) script.
|
||||
|
||||
| Benchmark | flag |
|
||||
| --- | --- |
|
||||
| SunSpider 1.0.2 | `sunspider` |
|
||||
| [Octane 2.0](https://github.com/chromium/octane.git) | `octane` |
|
||||
| [test262](https://github.com/tc39/test262.git) | `test262` |
|
||||
| [Web Tooling Benchmark](https://github.com/v8/web-tooling-benchmark) | `web-tooling-benchmark` |
|
||||
| SpiderMonkey (vendor-made) | `spidermonkey` |
|
||||
| ChakraCore (vendor-made) | `chakracore` |
|
||||
| V8 (vendor-made) | `v8` |
|
||||
|
||||
Run each benchmark separately or all together as shown below:
|
||||
```sh
|
||||
tools/run-tests.py --engine=./out/linux/x64/release/escargot web-tooling-benchmark
|
||||
tools/run-tests.py --engine=./out/linux/x64/release/escargot spidermonkey test262 v8
|
||||
```
|
||||
|
||||
## Contributing 💡
|
||||
Escargot welcomes contributions from developers in any form, wheter it's code, documentation, bug reports, or suggestions. By contributing to the project, you agree to license your contributions under the [LGPL-2.1](https://github.com/Samsung/escargot/blob/master/LICENSE) license.
|
||||
|
||||
#### ❗ Vulnerability Reporting
|
||||
⚠️ If you identify any vulnerabilities, please report them through the [Issues page](https://github.com/Samsung/escargot/issues). *Reports sent via other channels may not be considered or may be processed with delays*. Please note that our project assumes the execution of valid JavaScript source code only. Handling of invalid source code is not within the main scope of this project and might not be addressed.
|
||||
|
||||
## Research Papers 📝
|
||||
* [Dynamic code compression for JavaScript engine](https://doi.org/10.1002/spe.3186)
|
||||
Software: Practice and Experience Vol. 53 (5), pp. 1196-1217, 2023
|
||||
|
||||
* [Tail Call Optimization Tailored for Native Stack Utilization in JavaScript Runtimes](https://doi.org/10.1109/ACCESS.2024.3441750)
|
||||
IEEE Access Vol. 12, pp. 111801-111817, 2024
|
||||
|
||||
## License 📜
|
||||
Escargot is open-source software primarily licensed under [LGPL-2.1](https://github.com/Samsung/escargot/blob/master/LICENSE), with some components covered by other licenses. Complete license and copyright information can be found in the source code.
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
v4.3.0
|
||||
v3.0.0
|
||||
|
|
|
|||
10
build/android/.gitignore
vendored
|
|
@ -1,10 +0,0 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/*
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
3
build/android/.idea/.gitignore
generated
vendored
|
|
@ -1,3 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
1
build/android/.idea/.name
generated
|
|
@ -1 +0,0 @@
|
|||
Escargot android
|
||||
6
build/android/.idea/compiler.xml
generated
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
||||
20
build/android/.idea/gradle.xml
generated
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/escargot" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
10
build/android/.idea/misc.xml
generated
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
18
build/android/.idea/vcs.xml
generated
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/kangax" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/octane" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/test262" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/vendortest" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/web-tooling-benchmark" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/GCutil" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/googletest" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus/third_party/sljit" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus/third_party/uvwasi" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus/third_party/wasm-c-api" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/wasm/wabt" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
1
build/android/app/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
/build
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.samsung.lwe.escargot.shell'
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.samsung.lwe.escargot.shell"
|
||||
minSdk 28
|
||||
targetSdk 34
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
signingConfig signingConfigs.debug
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation project(path: ':escargot')
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
}
|
||||
21
build/android/app/proguard-rules.pro
vendored
|
|
@ -1,21 +0,0 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.samsung.lwe.escargot.shell;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.samsung.lwe.escargot.shell", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.EscargotAndroidTestShell"
|
||||
tools:targetApi="31">
|
||||
<profileable android:shell="true" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -1,333 +0,0 @@
|
|||
package com.samsung.lwe.escargot.shell;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.samsung.lwe.escargot.Bridge;
|
||||
import com.samsung.lwe.escargot.Context;
|
||||
import com.samsung.lwe.escargot.Evaluator;
|
||||
import com.samsung.lwe.escargot.Globals;
|
||||
import com.samsung.lwe.escargot.JavaScriptArrayObject;
|
||||
import com.samsung.lwe.escargot.JavaScriptJavaCallbackFunctionObject;
|
||||
import com.samsung.lwe.escargot.JavaScriptString;
|
||||
import com.samsung.lwe.escargot.JavaScriptValue;
|
||||
import com.samsung.lwe.escargot.Memory;
|
||||
import com.samsung.lwe.escargot.VMInstance;
|
||||
import com.samsung.lwe.escargot.util.MultiThreadExecutor;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private void copyAssets() {
|
||||
AssetManager assetManager = getAssets();
|
||||
String[] files = null;
|
||||
try {
|
||||
files = assetManager.list("");
|
||||
} catch (IOException e) {
|
||||
Log.e("tag", "Failed to get asset file list.", e);
|
||||
}
|
||||
for(String filename : files) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = assetManager.open(filename);
|
||||
File outFile = new File(getApplicationContext().getFilesDir(), filename);
|
||||
out = new FileOutputStream(outFile);
|
||||
copyFile(in, out);
|
||||
in.close();
|
||||
in = null;
|
||||
out.flush();
|
||||
out.close();
|
||||
out = null;
|
||||
} catch(IOException e) {
|
||||
Log.e("tag", "Failed to copy asset file: " + filename, e);
|
||||
}
|
||||
}
|
||||
|
||||
Log.e("Escargot shell", getApplicationContext().getFilesDir().getAbsolutePath());
|
||||
}
|
||||
|
||||
private void copyFile(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while((read = in.read(buffer)) != -1){
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
String str = "";
|
||||
private void run()
|
||||
{
|
||||
final String base = getApplicationContext().getFilesDir().getAbsolutePath() + "/";
|
||||
new Thread(() -> {
|
||||
Globals.initializeGlobals();
|
||||
Memory.setGCFrequency(2);
|
||||
|
||||
VMInstance vm = VMInstance.create(Optional.empty(), Optional.empty());
|
||||
Context context = Context.create(vm);
|
||||
|
||||
{
|
||||
Context finalContext = context;
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("print"), JavaScriptJavaCallbackFunctionObject.create(context, "print", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(str);
|
||||
sb.append('\n');
|
||||
for (int i = 0; i < javaScriptValues.length; i ++) {
|
||||
if (i > 0) {
|
||||
System.out.print(" ");
|
||||
sb.append(' ');
|
||||
}
|
||||
|
||||
Optional<JavaScriptString> s = javaScriptValues[i].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
String j = s.get().toJavaString();
|
||||
System.out.print(j);
|
||||
sb.append(j);
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
str = sb.toString();
|
||||
final String ff = str;
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TextView tv = ((TextView)findViewById(R.id.output));
|
||||
tv.setText(ff);
|
||||
}
|
||||
});
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("load"), JavaScriptJavaCallbackFunctionObject.create(context, "run", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
Optional<JavaScriptString> s = javaScriptValues[0].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
try {
|
||||
byte[] chars = Files.readAllBytes(Paths.get(s.get().toJavaString()));
|
||||
String fileContent = new String(chars);
|
||||
return Evaluator.evalScript(finalContext, fileContent, s.get().toJavaString(), false);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("run"), JavaScriptJavaCallbackFunctionObject.create(context, "run", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
long sm = System.currentTimeMillis();
|
||||
Optional<JavaScriptString> s = javaScriptValues[0].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
Evaluator.evalScript(finalContext, "load('" + s.get().toJavaString() + "')", "<code>", false);
|
||||
}
|
||||
return Optional.of(JavaScriptValue.create(System.currentTimeMillis() - sm));
|
||||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("read"), JavaScriptJavaCallbackFunctionObject.create(context, "read", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
Optional<JavaScriptString> s = javaScriptValues[0].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
FileReader in = null;
|
||||
try {
|
||||
byte[] chars = Files.readAllBytes(Paths.get(s.get().toJavaString()));
|
||||
String fileContent = new String(chars);
|
||||
return Optional.of(JavaScriptString.create(fileContent));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
String source = "load('" + base + "test.js" + "');";
|
||||
String fileName = "<java code>";
|
||||
Evaluator.evalScript(context,
|
||||
source,
|
||||
fileName,
|
||||
true);
|
||||
context = null;
|
||||
vm = null;
|
||||
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
|
||||
Globals.finalizeGlobals();
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void runExample()
|
||||
{
|
||||
new Thread(() -> {
|
||||
Looper.prepare();
|
||||
Handler handler = new Handler(Looper.myLooper());
|
||||
|
||||
Globals.initializeGlobals();
|
||||
|
||||
VMInstance vmInstance = VMInstance.create(Optional.empty(), Optional.empty());
|
||||
Context context = Context.create(vmInstance);
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("print"), JavaScriptJavaCallbackFunctionObject.create(context, "", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue receiverValue, JavaScriptValue[] arguments) {
|
||||
System.out.println(arguments[0].toString(context).get().toJavaString());
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("end"), JavaScriptJavaCallbackFunctionObject.create(context, "", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue receiverValue, JavaScriptValue[] arguments) {
|
||||
Looper.myLooper().quitSafely();
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
|
||||
MultiThreadExecutor executor = new MultiThreadExecutor(vmInstance, new MultiThreadExecutor.WorkerThreadEndNotifier() {
|
||||
@Override
|
||||
public void notify(MultiThreadExecutor executor, MultiThreadExecutor.ExecutorInstance instance) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
executor.pumpEventsFromThreadIfNeeds();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Bridge.register(context, "HTTP", "get", new Bridge.Adapter() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, Optional<JavaScriptValue> data) {
|
||||
String url = "";
|
||||
if (data.isPresent()) {
|
||||
Optional<JavaScriptString> mayBeString = data.get().toString(context);
|
||||
if (mayBeString.isPresent()) {
|
||||
url = mayBeString.get().toJavaString();
|
||||
}
|
||||
}
|
||||
final String finalURL = url;
|
||||
MultiThreadExecutor.ExecutorInstance instance = executor.startWorker(context, new MultiThreadExecutor.Executor() {
|
||||
@Override
|
||||
public MultiThreadExecutor.ResultBuilderContext run() {
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL(finalURL).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
return new MultiThreadExecutor.ResultBuilderContext(true, response.toString());
|
||||
} else {
|
||||
return new MultiThreadExecutor.ResultBuilderContext(false, "error HTTP return code:" + responseCode);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return new MultiThreadExecutor.ResultBuilderContext(false, e.toString());
|
||||
}
|
||||
}
|
||||
}, new MultiThreadExecutor.ResultBuilder() {
|
||||
@Override
|
||||
public JavaScriptValue build(Context scriptContext, MultiThreadExecutor.ResultBuilderContext builderContext) {
|
||||
return JavaScriptString.create((String)builderContext.data());
|
||||
}
|
||||
});
|
||||
return Optional.of(instance.promise());
|
||||
}
|
||||
});
|
||||
|
||||
Evaluator.evalScript(context, "" +
|
||||
"let promise1 = HTTP.get('https://httpbin.org/get');" +
|
||||
"let promise2 = HTTP.get('http://google.com');" +
|
||||
"Promise.allSettled([promise1, promise2]).then(function(v) {" +
|
||||
"print(JSON.stringify(v));" +
|
||||
"print('http all end!');" +
|
||||
"end();" +
|
||||
"});", "", false);
|
||||
|
||||
|
||||
Looper.loop();
|
||||
Looper.myLooper().quit();
|
||||
|
||||
context = null;
|
||||
vmInstance = null;
|
||||
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
|
||||
Globals.finalizeGlobals();
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
// copy assets to internal storage (for copying js files which are used by test)
|
||||
copyAssets();
|
||||
|
||||
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
runExample();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="run"/>
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_toRightOf="@id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="mt example"/>
|
||||
<TextView
|
||||
android:layout_below="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:singleLine="false"
|
||||
android:text="result"
|
||||
android:id="@+id/output"
|
||||
android:textSize="8sp"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 982 B |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
|
@ -1,16 +0,0 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.EscargotAndroidTestShell" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/black</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<resources>
|
||||
<string name="app_name">Escargot android test shell</string>
|
||||
</resources>
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.EscargotAndroidTestShell" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample backup rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/guide/topics/data/autobackup
|
||||
for details.
|
||||
Note: This file is ignored for devices older that API 31
|
||||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
<!--
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
-->
|
||||
</full-backup-content>
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.samsung.lwe.escargot.shell;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.10.1' apply false
|
||||
id 'com.android.library' version '8.10.1' apply false
|
||||
}
|
||||
1
build/android/escargot/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
/build
|
||||
|
|
@ -1,247 +0,0 @@
|
|||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'jacoco'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
ext {
|
||||
force64Option = System.getProperty("ESCARGOT_BUILD_64BIT_FORCE_LARGE", "ON")
|
||||
pthreadKeyOption = System.getProperty("ESCARGOT_BUILD_TLS_ACCESS_BY_PTHREAD_KEY", "OFF")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.samsung.lwe.escargot'
|
||||
compileSdk 36
|
||||
ndkVersion '28.1.13356709'
|
||||
|
||||
defaultConfig {
|
||||
minSdk 28
|
||||
targetSdk 36
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DESCARGOT_HOST=android", "-DESCARGOT_OUTPUT=static_lib", "-DENABLE_SHELL=OFF",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option, "-DESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY="+project.ext.pthreadKeyOption
|
||||
}
|
||||
}
|
||||
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
debug {
|
||||
testCoverageEnabled true
|
||||
jniDebuggable = true
|
||||
ndk {
|
||||
debuggable = true
|
||||
}
|
||||
}
|
||||
|
||||
debugShell {
|
||||
initWith(buildTypes.debug)
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DESCARGOT_HOST=android", "-DESCARGOT_OUTPUT=static_lib", "-DENABLE_SHELL=ON"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
releaseShell {
|
||||
initWith(buildTypes.release)
|
||||
jniDebuggable = true
|
||||
ndk {
|
||||
debuggable = true
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DESCARGOT_HOST=android", "-DESCARGOT_OUTPUT=static_lib", "-DENABLE_SHELL=ON"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs('src/main/java')
|
||||
test {
|
||||
java.srcDir('src/androidTest/java')
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
|
||||
ndkVersion '27.0.12077973'
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
publishing {
|
||||
singleVariant("release") {
|
||||
// if you don't want sources/javadoc, remove these lines
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
afterEvaluate {
|
||||
from components.release
|
||||
}
|
||||
artifactId "escargot-android"
|
||||
groupId "com.samsung.lwe.escargot"
|
||||
version "X.X.X.20XXXXXX.X.XXXXXXXX"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "/XXXXXX/android/releases/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def dirForNativeNoNDK = project.layout.buildDirectory.get().dir("native_nondk")
|
||||
def srcForNativeNoNDK = project.layout.projectDirectory.dir("src/main/cpp").asFile
|
||||
|
||||
task createNativeNoNDK() {
|
||||
def dstdir = dirForNativeNoNDK.asFile
|
||||
if (!dstdir.exists()) dstdir.mkdirs()
|
||||
}
|
||||
task buildCMakeNativeNoNDK(type: Exec) {
|
||||
dependsOn createNativeNoNDK
|
||||
workingDir dirForNativeNoNDK
|
||||
if (org.gradle.internal.os.OperatingSystem.current().isLinux()) {
|
||||
commandLine "/usr/bin/env", "cmake", "-DESCARGOT_HOST=linux", "-DESCARGOT_ARCH=x64", "-DESCARGOT_OUTPUT=static_lib",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option,
|
||||
"-DUNDER_NDK=OFF", srcForNativeNoNDK.absolutePath
|
||||
} else if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
|
||||
var javaHome = new ByteArrayOutputStream().withStream { os ->
|
||||
exec {
|
||||
executable "/usr/libexec/java_home"
|
||||
args "-v", "1.8"
|
||||
standardOutput = os
|
||||
}
|
||||
os.toString().trim()
|
||||
}
|
||||
var icu4cPath = new ByteArrayOutputStream().withStream { os ->
|
||||
exec {
|
||||
commandLine "sh", "-c", "brew --prefix icu4c"
|
||||
standardOutput = os
|
||||
}
|
||||
os.toString().trim()
|
||||
}
|
||||
var pkgConfigPath = icu4cPath + "/lib/pkgconfig"
|
||||
environment("PKG_CONFIG_PATH", pkgConfigPath)
|
||||
commandLine "/usr/bin/env", "cmake", "-DESCARGOT_HOST=darwin", "-DESCARGOT_ARCH=x64", "-DESCARGOT_OUTPUT=static_lib", "-DUNDER_NDK=OFF",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option,
|
||||
"-DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF",
|
||||
"-DJAVA_HOME=" + javaHome, "-DJAVA_INCLUDE_PATH=" + javaHome + "/include",
|
||||
"-DJAVA_INCLUDE_PATH2=" + javaHome + "/include/darwin", "-DJAVA_AWT_INCLUDE_PATH=" + javaHome + "/include",
|
||||
srcForNativeNoNDK.absolutePath
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
task buildGMakeNativeNoNDK(type: Exec) {
|
||||
dependsOn buildCMakeNativeNoNDK
|
||||
workingDir dirForNativeNoNDK
|
||||
commandLine "/usr/bin/env", "make", "-j" + Runtime.getRuntime().availableProcessors().toString();
|
||||
}
|
||||
|
||||
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
|
||||
reports {
|
||||
xml.required = true
|
||||
html.required = true
|
||||
}
|
||||
def mainSrc = "${project.projectDir}/src/main/java"
|
||||
sourceDirectories.setFrom(files([mainSrc]))
|
||||
|
||||
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*',
|
||||
'android/**/*.*', '**/*Activity*.*']
|
||||
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
|
||||
classDirectories.setFrom(files([debugTree]))
|
||||
|
||||
executionData.setFrom(fileTree(dir: "${buildDir}/jacoco/testDebugUnitTest.exec"))
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
if (org.gradle.internal.os.OperatingSystem.current().isLinux() || org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
|
||||
testDebugUnitTest {
|
||||
dependsOn buildGMakeNativeNoNDK
|
||||
systemProperty "java.library.path", dirForNativeNoNDK.asFile.absolutePath + ":" + System.getProperty("java.library.path")
|
||||
}
|
||||
testReleaseUnitTest {
|
||||
dependsOn buildGMakeNativeNoNDK
|
||||
systemProperty "java.library.path", dirForNativeNoNDK.asFile.absolutePath + ":" + System.getProperty("java.library.path")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
task clearHostJar(type: Delete) {
|
||||
delete 'build/libs/escargot.jar'
|
||||
}
|
||||
|
||||
task bundleHostJar(type: Jar) {
|
||||
dependsOn buildGMakeNativeNoNDK
|
||||
dependsOn assemble
|
||||
from(zipTree('build/intermediates/aar_main_jar/release/syncReleaseLibJars/classes.jar'))
|
||||
from(dirForNativeNoNDK.asFile.toString() + "/libescargot-jni.so")
|
||||
from(dirForNativeNoNDK.asFile.toString() + "/libescargot-jni.dylib")
|
||||
rename("libescargot-jni.dylib", "libescargot-jni.so")
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
archiveClassifier.set('sources')
|
||||
archivesBaseName = "escargot"
|
||||
}
|
||||
|
||||
task javadoc(type: Javadoc) {
|
||||
source = android.sourceSets.main.java.sourceFiles
|
||||
android.libraryVariants.all { variant ->
|
||||
if (variant.name == 'release') {
|
||||
owner.classpath += variant.javaCompileProvider.get().classpath
|
||||
}
|
||||
}
|
||||
options.memberLevel = JavadocMemberLevel.PRIVATE
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
archiveClassifier.set('javadoc')
|
||||
archivesBaseName = "escargot"
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
sourcesJar
|
||||
javadocJar
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation project(path: ':escargot')
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
androidTestImplementation project(path: ':escargot')
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
-keep class com.samsung.lwe.escargot.* { *; }
|
||||
-keep enum com.samsung.lwe.escargot.* { *; }
|
||||
24
build/android/escargot/proguard-rules.pro
vendored
|
|
@ -1,24 +0,0 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keep class com.samsung.lwe.escargot.* { *; }
|
||||
-keep enum com.samsung.lwe.escargot.* { *; }
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.18.1)
|
||||
|
||||
project(escargot-jni)
|
||||
|
||||
option(UNDER_NDK "Build under the Android NDK" ON)
|
||||
option(ENABLE_SHELL "Enable shell" OFF)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions -Wno-conversion-null -fPIC -ftls-model=local-dynamic ")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ftls-model=local-dynamic ")
|
||||
|
||||
if (NOT UNDER_NDK)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -g3")
|
||||
endif ()
|
||||
|
||||
SET (ESCARGOT_ARCH ${ANDROID_SYSROOT_ABI})
|
||||
# STRING(TOLOWER ${CMAKE_BUILD_TYPE} ESCARGOT_MODE)
|
||||
SET (ESCARGOT_MODE "release")
|
||||
SET (ESCARGOT_THREADING ON)
|
||||
|
||||
if (ENABLE_SHELL)
|
||||
SET (ESCARGOT_TEST ON)
|
||||
SET (ESCARGOT_TEMPORAL ON)
|
||||
SET (ESCARGOT_EXPORT_ALL ON)
|
||||
endif ()
|
||||
ADD_SUBDIRECTORY (${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../ escargot)
|
||||
|
||||
FILE (GLOB_RECURSE JNI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
ADD_LIBRARY (escargot-jni SHARED ${JNI_SRC})
|
||||
|
||||
SET(LOG_LIBRARY "")
|
||||
if (NOT UNDER_NDK)
|
||||
ADD_DEFINITIONS(-DNDEBUG)
|
||||
endif ()
|
||||
|
||||
if (UNDER_NDK)
|
||||
FIND_LIBRARY(LOG_LIBRARY log)
|
||||
# enable 16KB page size (require version of Android NDK >= 27)
|
||||
TARGET_LINK_OPTIONS(escargot PRIVATE "-Wl,-z,max-page-size=16384")
|
||||
TARGET_LINK_OPTIONS(escargot-jni PRIVATE "-Wl,-z,max-page-size=16384")
|
||||
else ()
|
||||
FIND_PACKAGE(JNI REQUIRED)
|
||||
INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIRS})
|
||||
endif ()
|
||||
|
||||
TARGET_LINK_LIBRARIES (escargot-jni PRIVATE escargot ${LOG_LIBRARY})
|
||||
|
||||
if (ENABLE_SHELL)
|
||||
SET(CMAKE_EXE_LINKER_FLAGS -Wl,-export-dynamic) # export symbol of Shell.cpp
|
||||
ADD_COMPILE_OPTIONS(-DNDEBUG -g3 -DESCARGOT_ENABLE_TEST -fPIC)
|
||||
ADD_LINK_OPTIONS(-static-libstdc++)
|
||||
ADD_EXECUTABLE(escargot-shell ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/shell/Shell.cpp)
|
||||
TARGET_INCLUDE_DIRECTORIES(escargot-shell PRIVATE ADD_SUBDIRECTORY
|
||||
(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party/GCutil/include)
|
||||
(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src))
|
||||
TARGET_LINK_LIBRARIES (escargot-shell PRIVATE escargot ${LOG_LIBRARY})
|
||||
|
||||
ADD_EXECUTABLE(test-data-runner ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../tools/test/test-data-runner/test-data-runner.cpp)
|
||||
TARGET_COMPILE_OPTIONS(test-data-runner PRIVATE -std=c++11 -fPIC)
|
||||
endif ()
|
||||
|
|
@ -1,350 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
JavaVM* g_jvm;
|
||||
size_t g_nonPointerValueLast = reinterpret_cast<size_t>(ValueRef::createUndefined());
|
||||
thread_local std::vector<ExecutionStateRef*> ExecutionStateRefTracker::g_lastExecutionStateVector;
|
||||
|
||||
jobject createJavaValueObject(JNIEnv* env, jclass clazz, ValueRef* value)
|
||||
{
|
||||
jobject valueObject;
|
||||
if (!value->isStoredInHeap()) {
|
||||
valueObject = env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(JZ)V"), reinterpret_cast<jlong>(value), jboolean(false));
|
||||
} else {
|
||||
PersistentRefHolder<ValueRef>* pRef = new PersistentRefHolder<ValueRef>(value);
|
||||
jlong ptr = reinterpret_cast<size_t>(pRef);
|
||||
valueObject = env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(J)V"), ptr);
|
||||
}
|
||||
return valueObject;
|
||||
}
|
||||
|
||||
jobject createJavaValueObject(JNIEnv* env, const char* className, ValueRef* value)
|
||||
{
|
||||
return createJavaValueObject(env, env->FindClass(className), value);
|
||||
}
|
||||
|
||||
ValueRef* unwrapValueRefFromValue(JNIEnv* env, jclass clazz, jobject object)
|
||||
{
|
||||
auto ptr = env->GetLongField(object, env->GetFieldID(clazz, "m_nativePointer", "J"));
|
||||
if (static_cast<size_t>(ptr) <= g_nonPointerValueLast || (static_cast<size_t>(ptr) & 1)) {
|
||||
return reinterpret_cast<ValueRef*>(ptr);
|
||||
} else {
|
||||
PersistentRefHolder<ValueRef>* ref = reinterpret_cast<PersistentRefHolder<ValueRef>*>(ptr);
|
||||
return ref->get();
|
||||
}
|
||||
}
|
||||
|
||||
jobject createJavaObjectFromValue(JNIEnv* env, ValueRef* value)
|
||||
{
|
||||
if (!value->isStoredInHeap() || value->isNumber()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptValue", value);
|
||||
} else if (value->isString()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptString", value);
|
||||
} else if (value->isSymbol()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptSymbol", value);
|
||||
} else if (value->isBigInt()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptBigInt", value);
|
||||
} else if (value->isObject()) {
|
||||
if (value->isArrayObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptArrayObject", value);
|
||||
} else if (value->isGlobalObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptGlobalObject", value);
|
||||
} else if (value->isFunctionObject()) {
|
||||
if (value->asFunctionObject()->extraData()) {
|
||||
ScriptObjectExtraData* data = reinterpret_cast<ScriptObjectExtraData*>(value->asFunctionObject()->extraData());
|
||||
if (data->implementSideData) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptJavaCallbackFunctionObject", value);
|
||||
}
|
||||
}
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptFunctionObject", value);
|
||||
} else if (value->isPromiseObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptPromiseObject", value);
|
||||
} else if (value->isErrorObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptErrorObject", value);
|
||||
} else {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptObject", value);
|
||||
}
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
jobject createJavaObject(JNIEnv* env, VMInstanceRef* value)
|
||||
{
|
||||
PersistentRefHolder<VMInstanceRef>* pRef = new PersistentRefHolder<VMInstanceRef>(value);
|
||||
jlong ptr = reinterpret_cast<size_t>(pRef);
|
||||
jclass clazz = env->FindClass("com/samsung/lwe/escargot/VMInstance");
|
||||
return env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(J)V"), ptr);
|
||||
}
|
||||
|
||||
jobject createJavaObject(JNIEnv* env, ContextRef* value)
|
||||
{
|
||||
PersistentRefHolder<ContextRef>* pRef = new PersistentRefHolder<ContextRef>(value);
|
||||
jlong ptr = reinterpret_cast<size_t>(pRef);
|
||||
jclass clazz = env->FindClass("com/samsung/lwe/escargot/Context");
|
||||
return env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(J)V"), ptr);
|
||||
}
|
||||
|
||||
OptionalRef<JNIEnv> fetchJNIEnvFromCallback()
|
||||
{
|
||||
JNIEnv* env = nullptr;
|
||||
if (g_jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) == JNI_EDETACHED) {
|
||||
#if defined(_JAVASOFT_JNI_H_) // oraclejdk or openjdk
|
||||
if (g_jvm->AttachCurrentThread(reinterpret_cast<void **>(&env), NULL) != 0) {
|
||||
#else
|
||||
if (g_jvm->AttachCurrentThread(reinterpret_cast<JNIEnv **>(&env), NULL) != 0) {
|
||||
#endif
|
||||
// give up
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Escargot_init(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
thread_local static bool inited = false;
|
||||
if (!inited) {
|
||||
if (!g_jvm) {
|
||||
env->GetJavaVM(&g_jvm);
|
||||
}
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string fetchStringFromJavaOptionalString(JNIEnv *env, jobject optional)
|
||||
{
|
||||
auto classOptionalString = env->GetObjectClass(optional);
|
||||
auto methodIsPresent = env->GetMethodID(classOptionalString, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(optional, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptionalString, "get", "()Ljava/lang/Object;");
|
||||
jboolean isSucceed;
|
||||
jstring value = static_cast<jstring>(env->CallObjectMethod(optional, methodGet));
|
||||
const char* str = env->GetStringUTFChars(
|
||||
value, &isSucceed);
|
||||
auto length = env->GetStringUTFLength(value);
|
||||
auto ret = std::string(str, length);
|
||||
env->ReleaseStringUTFChars(value, str);
|
||||
return ret;
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
StringRef* createJSStringFromJava(JNIEnv* env, jstring str)
|
||||
{
|
||||
if (!str) {
|
||||
return StringRef::emptyString();
|
||||
}
|
||||
jboolean isSucceed;
|
||||
const char* cString = env->GetStringUTFChars(str, &isSucceed);
|
||||
StringRef* code = StringRef::createFromUTF8(cString, env->GetStringUTFLength(str));
|
||||
env->ReleaseStringUTFChars(str, cString);
|
||||
return code;
|
||||
}
|
||||
|
||||
std::string createStringFromJava(JNIEnv* env, jstring str)
|
||||
{
|
||||
if (!str) {
|
||||
return std::string();
|
||||
}
|
||||
jboolean isSucceed;
|
||||
const char* cString = env->GetStringUTFChars(str, &isSucceed);
|
||||
std::string ret = std::string(cString, env->GetStringUTFLength(str));
|
||||
env->ReleaseStringUTFChars(str, cString);
|
||||
return ret;
|
||||
}
|
||||
|
||||
jstring createJavaStringFromJS(JNIEnv* env, StringRef* string)
|
||||
{
|
||||
std::basic_string<uint16_t> buf;
|
||||
auto bad = string->stringBufferAccessData();
|
||||
buf.reserve(bad.length);
|
||||
|
||||
for (size_t i = 0; i < bad.length ; i ++) {
|
||||
buf.push_back(bad.charAt(i));
|
||||
}
|
||||
|
||||
return env->NewString(buf.data(), buf.length());
|
||||
}
|
||||
|
||||
void throwJavaRuntimeException(ExecutionStateRef* state)
|
||||
{
|
||||
state->throwException(ErrorObjectRef::create(state, ErrorObjectRef::None, StringRef::createFromASCII("Java runtime exception")));
|
||||
}
|
||||
|
||||
bool hasJavaScriptRuntimeExceptionOnEnv(JNIEnv* env)
|
||||
{
|
||||
if (env->ExceptionCheck()) {
|
||||
jthrowable exception = env->ExceptionOccurred();
|
||||
env->ExceptionClear();
|
||||
bool ret = env->IsInstanceOf(exception, env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException"));
|
||||
env->Throw(exception);
|
||||
return ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
OptionalRef<ValueRef> extractExceptionFromEnv(JNIEnv* env)
|
||||
{
|
||||
if (env->ExceptionCheck()) {
|
||||
jthrowable exception = env->ExceptionOccurred();
|
||||
env->ExceptionClear();
|
||||
bool ret = env->IsInstanceOf(exception, env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException"));
|
||||
if (ret) {
|
||||
jclass clz = env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException");
|
||||
jobject jv = env->CallObjectMethod(exception, env->GetMethodID(clz, "exception", "()Lcom/samsung/lwe/escargot/JavaScriptValue;"));
|
||||
ValueRef* v = unwrapValueRefFromValue(env, env->GetObjectClass(jv), jv);
|
||||
return v;
|
||||
} else {
|
||||
env->Throw(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasJavaExcpetion(JNIEnv* env)
|
||||
{
|
||||
if (env->ExceptionCheck() && !hasJavaScriptRuntimeExceptionOnEnv(env)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
jobject storeExceptionOnContextAndReturnsIt(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto exceptionOnEnv = extractExceptionFromEnv(env);
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
// store exception to context
|
||||
auto fieldId = env->GetFieldID(env->GetObjectClass(contextObject), "m_lastThrownException", "Ljava/util/Optional;");
|
||||
ValueRef* exception = exceptionOnEnv ? exceptionOnEnv.get() : evaluatorResult.error.value();
|
||||
auto fieldValue = env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
createJavaObjectFromValue(env, exception));
|
||||
env->SetObjectField(contextObject, fieldId, fieldValue);
|
||||
|
||||
return env->CallStaticObjectMethod(optionalClazz, env->GetStaticMethodID(optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorJavaScriptValueResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
createJavaObjectFromValue(env, evaluatorResult.result));
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorBooleanResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
auto booleanClazz = env->FindClass("java/lang/Boolean");
|
||||
auto valueOfMethodId = env->GetStaticMethodID(booleanClazz, "valueOf", "(Z)Ljava/lang/Boolean;");
|
||||
auto javaBoolean = env->CallStaticObjectMethod(booleanClazz, valueOfMethodId, (jboolean)evaluatorResult.result->asBoolean());
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
javaBoolean);
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorIntegerResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
auto containerClass = env->FindClass("java/lang/Integer");
|
||||
auto valueOfMethodId = env->GetStaticMethodID(containerClass, "valueOf", "(I)Ljava/lang/Integer;");
|
||||
auto javaValue = env->CallStaticObjectMethod(containerClass, valueOfMethodId, (jint)evaluatorResult.result->asInt32());
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
javaValue);
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorDoubleResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
auto containerClass = env->FindClass("java/lang/Double");
|
||||
auto valueOfMethodId = env->GetStaticMethodID(containerClass, "valueOf", "(D)Ljava/lang/Double;");
|
||||
auto javaValue = env->CallStaticObjectMethod(containerClass, valueOfMethodId, (jdouble)evaluatorResult.result->asNumber());
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
javaValue);
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
ScriptObjectExtraData* ensureScriptObjectExtraData(ObjectRef* ref)
|
||||
{
|
||||
ScriptObjectExtraData* data = reinterpret_cast<ScriptObjectExtraData*>(ref->extraData());
|
||||
if (!data) {
|
||||
data = new ScriptObjectExtraData;
|
||||
ref->setExtraData(data);
|
||||
|
||||
Memory::gcRegisterFinalizer(ref, [](void* self, void* data) {
|
||||
ScriptObjectExtraData* extraData = reinterpret_cast<ScriptObjectExtraData*>(reinterpret_cast<ObjectRef*>(self)->extraData());
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (env) {
|
||||
if (extraData->implementSideData) {
|
||||
env->DeleteGlobalRef(extraData->implementSideData);
|
||||
extraData->implementSideData = nullptr;
|
||||
}
|
||||
if (extraData->userData) {
|
||||
env->DeleteGlobalRef(extraData->userData);
|
||||
extraData->userData = nullptr;
|
||||
}
|
||||
}
|
||||
}, nullptr);
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
#ifndef ESCARGOT_ANDROID_ESCARGOTJNI_H
|
||||
#define ESCARGOT_ANDROID_ESCARGOTJNI_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <EscargotPublic.h>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <cassert>
|
||||
|
||||
using namespace Escargot;
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "Escargot"
|
||||
#define LOGUNK(...) __android_log_print(ANDROID_LOG_UNKNOWN,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGDEF(...) __android_log_print(ANDROID_LOG_DEFAULT,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGF(...) __android_log_print(ANDROID_FATAL_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGS(...) __android_log_print(ANDROID_SILENT_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGUNK(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGDEF(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGV(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGD(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGI(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGW(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGE(...) fprintf(stderr,__VA_ARGS__)
|
||||
#define LOGF(...) fprintf(stderr,__VA_ARGS__)
|
||||
#define LOGS(...) fprintf(stderr,__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define THROW_NPE_RETURN_NULL(param, paramType) \
|
||||
if (env->ExceptionCheck()) { \
|
||||
return 0; \
|
||||
} \
|
||||
if (!param) { \
|
||||
env->ThrowNew(env->FindClass("java/lang/NullPointerException"), paramType" cannot be null"); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define THROW_NPE_RETURN_VOID(param, paramType) \
|
||||
if (env->ExceptionCheck()) { \
|
||||
return; \
|
||||
} \
|
||||
if (!param) { \
|
||||
env->ThrowNew(env->FindClass("java/lang/NullPointerException"), paramType" cannot be null"); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define THROW_CAST_EXCEPTION_IF_NEEDS(param, value, typeName) \
|
||||
if (env->ExceptionCheck()) { \
|
||||
return NULL; \
|
||||
} \
|
||||
if (!value->is##typeName()) { \
|
||||
env->ThrowNew(env->FindClass("java/lang/ClassCastException"), "Can not cast to " #typeName); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
extern JavaVM* g_jvm;
|
||||
extern size_t g_nonPointerValueLast;
|
||||
|
||||
jobject createJavaValueObject(JNIEnv* env, jclass clazz, ValueRef* value);
|
||||
jobject createJavaValueObject(JNIEnv* env, const char* className, ValueRef* value);
|
||||
jobject createJavaObject(JNIEnv* env, VMInstanceRef* value);
|
||||
jobject createJavaObject(JNIEnv* env, ContextRef* value);
|
||||
|
||||
ValueRef* unwrapValueRefFromValue(JNIEnv* env, jclass clazz, jobject object);
|
||||
jobject createJavaObjectFromValue(JNIEnv* env, ValueRef* value);
|
||||
ValueRef* unwrapValueRefFromValue(JNIEnv* env, jclass clazz, jobject object);
|
||||
OptionalRef<JNIEnv> fetchJNIEnvFromCallback();
|
||||
|
||||
std::string fetchStringFromJavaOptionalString(JNIEnv *env, jobject optional);
|
||||
StringRef* createJSStringFromJava(JNIEnv* env, jstring str);
|
||||
std::string createStringFromJava(JNIEnv* env, jstring str);
|
||||
jstring createJavaStringFromJS(JNIEnv* env, StringRef* string);
|
||||
void throwJavaRuntimeException(ExecutionStateRef* state);
|
||||
OptionalRef<ValueRef> extractExceptionFromEnv(JNIEnv* env);
|
||||
jobject storeExceptionOnContextAndReturnsIt(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorJavaScriptValueResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorBooleanResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorIntegerResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorDoubleResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
|
||||
struct ScriptObjectExtraData {
|
||||
jobject userData;
|
||||
jobject implementSideData;
|
||||
|
||||
ScriptObjectExtraData()
|
||||
: userData(nullptr)
|
||||
, implementSideData(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void* operator new(size_t t)
|
||||
{
|
||||
return Memory::gcMallocAtomic(sizeof(ScriptObjectExtraData));
|
||||
}
|
||||
};
|
||||
|
||||
ScriptObjectExtraData* ensureScriptObjectExtraData(ObjectRef* ref);
|
||||
|
||||
template<typename T>
|
||||
jobject nativeOptionalValueIntoJavaOptionalValue(JNIEnv* env, OptionalRef<T> ref)
|
||||
{
|
||||
if (env->ExceptionCheck()) {
|
||||
return nullptr;
|
||||
}
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
if (ref) {
|
||||
jmethodID ctorMethod = env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;");
|
||||
return env->CallStaticObjectMethod(optionalClazz, ctorMethod, createJavaObjectFromValue(env, ref.value()));
|
||||
}
|
||||
|
||||
return env->CallStaticObjectMethod(optionalClazz, env->GetStaticMethodID(optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
|
||||
template<typename NativeType>
|
||||
PersistentRefHolder<NativeType>* getPersistentPointerFromJava(JNIEnv *env, jclass clazz, jobject object)
|
||||
{
|
||||
auto ptr = env->GetLongField(object, env->GetFieldID(clazz, "m_nativePointer", "J"));
|
||||
PersistentRefHolder<NativeType>* pVMRef = reinterpret_cast<PersistentRefHolder<NativeType>*>(ptr);
|
||||
return pVMRef;
|
||||
}
|
||||
|
||||
class ExecutionStateRefTracker {
|
||||
public:
|
||||
ExecutionStateRefTracker(ExecutionStateRef* newValue)
|
||||
{
|
||||
g_lastExecutionStateVector.push_back(newValue);
|
||||
}
|
||||
|
||||
~ExecutionStateRefTracker()
|
||||
{
|
||||
g_lastExecutionStateVector.pop_back();
|
||||
}
|
||||
private:
|
||||
friend class ScriptEvaluator;
|
||||
static thread_local std::vector<ExecutionStateRef*> g_lastExecutionStateVector;
|
||||
};
|
||||
|
||||
class ScriptEvaluator {
|
||||
public:
|
||||
template <typename... Args, typename F>
|
||||
static Evaluator::EvaluatorResult execute(ContextRef* ctx, F&& closure, Args... args)
|
||||
{
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef * state, Args...);
|
||||
if (ExecutionStateRefTracker::g_lastExecutionStateVector.size()) {
|
||||
return Evaluator::execute(ExecutionStateRefTracker::g_lastExecutionStateVector.back(), [](ExecutionStateRef * state, Closure closure, Args... args) -> ValueRef* {
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
return closure(state, args...);
|
||||
}, Closure(closure), args...);
|
||||
} else {
|
||||
return Evaluator::execute(ctx, [](ExecutionStateRef * state, Closure closure, Args... args) -> ValueRef* {
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
return closure(state, args...);
|
||||
}, Closure(closure), args...);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif //ESCARGOT_ANDROID_ESCARGOTJNI_H
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptArrayObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state) -> ValueRef* {
|
||||
return ArrayObjectRef::create(state);
|
||||
});
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asArrayObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptArrayObject_length(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ArrayObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asArrayObject();
|
||||
|
||||
int64_t length = 0;
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ArrayObjectRef* thisValueRef, int64_t* pLength) -> ValueRef* {
|
||||
*pLength = static_cast<int64_t>(thisValueRef->length(state));
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, &length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptArrayObject_setLength(JNIEnv* env, jobject thiz,
|
||||
jobject context, jlong newLength)
|
||||
{
|
||||
THROW_NPE_RETURN_VOID(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ArrayObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asArrayObject();
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ArrayObjectRef* thisValueRef, jlong pLength) -> ValueRef* {
|
||||
if (pLength >= 0) {
|
||||
thisValueRef->setLength(state, static_cast<uint64_t>(pLength));
|
||||
} else {
|
||||
thisValueRef->set(state, AtomicStringRef::create(state->context(), "length")->string(), ValueRef::create(pLength));
|
||||
}
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, newLength);
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__I(JNIEnv* env, jclass clazz, jint num)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, BigIntRef::create(static_cast<int64_t>(num)));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__J(JNIEnv* env, jclass clazz, jlong num)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, BigIntRef::create(static_cast<int64_t>(num)));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__Ljava_lang_String_2I(JNIEnv* env,
|
||||
jclass clazz,
|
||||
jstring numString,
|
||||
jint radix)
|
||||
{
|
||||
return createJavaValueObject(env, clazz,
|
||||
BigIntRef::create(createJSStringFromJava(env, numString), radix));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__Lcom_samsung_lwe_escargot_JavaScriptString_2I(
|
||||
JNIEnv* env, jclass clazz, jobject numString, jint radix)
|
||||
{
|
||||
if (numString) {
|
||||
return createJavaValueObject(env, clazz,
|
||||
BigIntRef::create(unwrapValueRefFromValue(env, env->GetObjectClass(
|
||||
numString), numString)->asString(), radix));
|
||||
} else {
|
||||
return createJavaValueObject(env, clazz, BigIntRef::create(static_cast<int64_t>(0)));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_toString(JNIEnv* env, jobject thiz, jint radix)
|
||||
{
|
||||
return createJavaObjectFromValue(env, unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asBigInt()->toString(radix));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_toNumber(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asBigInt()->toNumber();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_toInt64(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asBigInt()->toInt64();
|
||||
}
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_Bridge_register(JNIEnv* env, jclass clazz, jobject context,
|
||||
jstring objectName, jstring propertyName,
|
||||
jobject adapter)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(adapter, "Adapter");
|
||||
|
||||
auto contextPtr = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context),
|
||||
context);
|
||||
auto jsObjectName = createJSStringFromJava(env, objectName);
|
||||
auto jsPropertyName = createJSStringFromJava(env, propertyName);
|
||||
|
||||
if (!jsObjectName->length() || !jsPropertyName->length()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
adapter = env->NewGlobalRef(adapter);
|
||||
|
||||
auto evalResult = ScriptEvaluator::execute(contextPtr->get(),
|
||||
[](ExecutionStateRef* state, JNIEnv* env, jobject adapter,
|
||||
StringRef* jsObjectName,
|
||||
StringRef* jsPropertyName) -> ValueRef* {
|
||||
auto globalObject = state->context()->globalObject();
|
||||
ObjectRef* targetObject;
|
||||
|
||||
ValueRef* willBeTargetObject = globalObject->getOwnProperty(
|
||||
state, jsObjectName);
|
||||
if (willBeTargetObject->isObject()) {
|
||||
targetObject = willBeTargetObject->asObject();
|
||||
} else {
|
||||
targetObject = ObjectRef::create(state);
|
||||
globalObject->defineDataProperty(state,
|
||||
jsObjectName,
|
||||
targetObject,
|
||||
true, true, true);
|
||||
}
|
||||
|
||||
FunctionObjectRef::NativeFunctionInfo info(
|
||||
AtomicStringRef::create(state->context(), jsPropertyName),
|
||||
[](ExecutionStateRef* state,
|
||||
ValueRef* thisValue, size_t argc,
|
||||
ValueRef** argv,
|
||||
bool isConstructorCall) -> ValueRef* {
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
FunctionObjectRef* callee = state->resolveCallee().get();
|
||||
|
||||
jobject jo = ensureScriptObjectExtraData(
|
||||
reinterpret_cast<FunctionObjectRef*>(callee))->implementSideData;
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (!env) {
|
||||
// give up
|
||||
LOGE("could not fetch env from callback");
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
env->PushLocalFrame(32);
|
||||
|
||||
jobject callbackArg;
|
||||
jclass optionalClazz = env->FindClass(
|
||||
"java/util/Optional");
|
||||
if (argc) {
|
||||
callbackArg = env->CallStaticObjectMethod(
|
||||
optionalClazz,
|
||||
env->GetStaticMethodID(
|
||||
optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
createJavaObjectFromValue(env.get(), argv[0]));
|
||||
} else {
|
||||
callbackArg = env->CallStaticObjectMethod(
|
||||
optionalClazz,
|
||||
env->GetStaticMethodID(
|
||||
optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
auto javaReturnValue = env->CallObjectMethod(
|
||||
jo,
|
||||
env->GetMethodID(
|
||||
env->GetObjectClass(jo),
|
||||
"callback",
|
||||
"(Lcom/samsung/lwe/escargot/Context;Ljava/util/Optional;)Ljava/util/Optional;"),
|
||||
createJavaObject(env.get(), callee->context()),
|
||||
callbackArg);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
env->PopLocalFrame(NULL);
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
auto methodIsPresent = env->GetMethodID(
|
||||
optionalClazz, "isPresent", "()Z");
|
||||
ValueRef* nativeReturnValue = ValueRef::createUndefined();
|
||||
if (javaReturnValue && env->CallBooleanMethod(javaReturnValue,
|
||||
methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(
|
||||
optionalClazz, "get",
|
||||
"()Ljava/lang/Object;");
|
||||
jobject value = env->CallObjectMethod(
|
||||
javaReturnValue, methodGet);
|
||||
nativeReturnValue = unwrapValueRefFromValue(
|
||||
env.get(),
|
||||
env->GetObjectClass(value),
|
||||
value);
|
||||
}
|
||||
|
||||
env->PopLocalFrame(NULL);
|
||||
return nativeReturnValue;
|
||||
}, 1, true, false);
|
||||
FunctionObjectRef* callback = FunctionObjectRef::create(
|
||||
state, info);
|
||||
targetObject->defineDataProperty(state, jsPropertyName,
|
||||
callback, true, true,
|
||||
true);
|
||||
return callback;
|
||||
}, env, adapter, jsObjectName, jsPropertyName);
|
||||
|
||||
if (evalResult.isSuccessful()) {
|
||||
FunctionObjectRef* callback = evalResult.result->asFunctionObject();
|
||||
ensureScriptObjectExtraData(callback)->implementSideData = adapter;
|
||||
} else {
|
||||
env->DeleteGlobalRef(adapter);
|
||||
}
|
||||
|
||||
return evalResult.isSuccessful();
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_Context_create(JNIEnv* env, jclass clazz, jobject vmInstance)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(vmInstance, "VMInstance");
|
||||
|
||||
auto vmPtr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(vmInstance),
|
||||
vmInstance);
|
||||
auto contextRef = ContextRef::create(vmPtr->get());
|
||||
return createJavaObject(env, contextRef.get());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_Context_getGlobalObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(thiz), thiz);
|
||||
return createJavaObjectFromValue(env, contextRef->get()->globalObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_Context_throwException(JNIEnv* env, jobject thiz, jobject exception)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(exception, "JavaScriptValue");
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(thiz), thiz);
|
||||
if (contextRef->get()->canThrowException()) {
|
||||
ValueRef* exceptionRef = unwrapValueRefFromValue(env, env->GetObjectClass(exception), exception);
|
||||
if (exceptionRef->isErrorObject()) {
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* exceptionRef) -> ValueRef* {
|
||||
exceptionRef->asErrorObject()->updateStackTraceData(state);
|
||||
return ValueRef::createUndefined();
|
||||
}, exceptionRef);
|
||||
}
|
||||
jclass clz = env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException");
|
||||
jobject obj = env->NewObject(clz, env->GetMethodID(clz, "<init>", "(Lcom/samsung/lwe/escargot/JavaScriptValue;)V"), exception);
|
||||
env->Throw(static_cast<jthrowable>(obj));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptErrorObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context, jobject kind,
|
||||
jstring message)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(kind, "ErrorKind");
|
||||
THROW_NPE_RETURN_NULL(message, "String");
|
||||
|
||||
auto nameMethod = env->GetMethodID(env->GetObjectClass(kind), "name", "()Ljava/lang/String;");
|
||||
auto kindName = (jstring)env->CallObjectMethod(kind, nameMethod);
|
||||
auto string = createStringFromJava(env, kindName);
|
||||
|
||||
ErrorObjectRef::Code code = Escargot::ErrorObjectRef::None;
|
||||
if (string == "ReferenceError") {
|
||||
code = Escargot::ErrorObjectRef::ReferenceError;
|
||||
} else if (string == "TypeError") {
|
||||
code = Escargot::ErrorObjectRef::TypeError;
|
||||
} else if (string == "SyntaxError") {
|
||||
code = Escargot::ErrorObjectRef::SyntaxError;
|
||||
} else if (string == "RangeError") {
|
||||
code = Escargot::ErrorObjectRef::RangeError;
|
||||
} else if (string == "URIError") {
|
||||
code = Escargot::ErrorObjectRef::URIError;
|
||||
} else if (string == "EvalError") {
|
||||
code = Escargot::ErrorObjectRef::EvalError;
|
||||
} else if (string == "AggregateError") {
|
||||
code = Escargot::ErrorObjectRef::AggregateError;
|
||||
}
|
||||
|
||||
StringRef* jsMessage = createJSStringFromJava(env, message);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state,
|
||||
ErrorObjectRef::Code code, StringRef* jsMessage) -> ValueRef* {
|
||||
return ErrorObjectRef::create(state, code, jsMessage);
|
||||
}, code, jsMessage);
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asErrorObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptErrorObject_stack(JNIEnv* env, jobject thiz,
|
||||
jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ErrorObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asErrorObject();
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ErrorObjectRef* thisValueRef) -> ValueRef* {
|
||||
return thisValueRef->getOwnProperty(state, StringRef::createFromASCII("stack"))->toString(state);
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(), evaluatorResult);
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
static bool stringEndsWith(const std::string& str, const std::string& suffix)
|
||||
{
|
||||
return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
|
||||
}
|
||||
|
||||
static Evaluator::EvaluatorResult evalScript(ContextRef* context, StringRef* source, StringRef* srcName, bool shouldPrintScriptResult, bool shouldExecutePendingJobsAtEnd, bool isModule)
|
||||
{
|
||||
if (stringEndsWith(srcName->toStdUTF8String(), "mjs")) {
|
||||
isModule = isModule || true;
|
||||
}
|
||||
|
||||
auto scriptInitializeResult = context->scriptParser()->initializeScript(source, srcName, isModule);
|
||||
if (!scriptInitializeResult.script) {
|
||||
LOGD("Script parsing error: ");
|
||||
switch (scriptInitializeResult.parseErrorCode) {
|
||||
case Escargot::ErrorObjectRef::Code::SyntaxError:
|
||||
LOGD("SyntaxError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::EvalError:
|
||||
LOGD("EvalError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::RangeError:
|
||||
LOGD("RangeError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::ReferenceError:
|
||||
LOGD("ReferenceError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::TypeError:
|
||||
LOGD("TypeError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::URIError:
|
||||
LOGD("URIError");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LOGD(": %s\n", scriptInitializeResult.parseErrorMessage->toStdUTF8String().data());
|
||||
Evaluator::EvaluatorResult evalResult;
|
||||
evalResult.error = StringRef::createFromASCII("script parsing error");
|
||||
return evalResult;
|
||||
}
|
||||
|
||||
auto evalResult = ScriptEvaluator::execute(context, [](ExecutionStateRef* state, ScriptRef* script) -> ValueRef* {
|
||||
return script->execute(state);
|
||||
},
|
||||
scriptInitializeResult.script.get());
|
||||
|
||||
if (!evalResult.isSuccessful()) {
|
||||
if (shouldPrintScriptResult) {
|
||||
LOGD("Uncaught %s:\n", evalResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
for (size_t i = 0; i < evalResult.stackTrace.size(); i++) {
|
||||
LOGD("%s (%d:%d)\n", evalResult.stackTrace[i].srcName->toStdUTF8String().data(), (int)evalResult.stackTrace[i].loc.line, (int)evalResult.stackTrace[i].loc.column);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (shouldPrintScriptResult) {
|
||||
LOGD("%s", evalResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldExecutePendingJobsAtEnd) {
|
||||
while (context->vmInstance()->hasPendingJob() || context->vmInstance()->hasPendingJobFromAnotherThread()) {
|
||||
if (context->vmInstance()->waitEventFromAnotherThread(10)) {
|
||||
context->vmInstance()->executePendingJobFromAnotherThread();
|
||||
}
|
||||
if (context->vmInstance()->hasPendingJob()) {
|
||||
auto jobResult = context->vmInstance()->executePendingJob();
|
||||
if (shouldPrintScriptResult) {
|
||||
if (jobResult.error) {
|
||||
LOGD("Uncaught %s:(in promise job)\n", jobResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
} else {
|
||||
LOGD("%s(in promise job)\n", jobResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return evalResult;
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_Evaluator_evalScript(JNIEnv* env, jclass clazz, jobject context,
|
||||
jstring source, jstring sourceFileName,
|
||||
jboolean shouldPrintScriptResult,
|
||||
jboolean shouldExecutePendingJobsAtEnd)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto ptr = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
Evaluator::EvaluatorResult result = evalScript(ptr->get(), createJSStringFromJava(env, source),
|
||||
createJSStringFromJava(env, sourceFileName), shouldPrintScriptResult,
|
||||
shouldExecutePendingJobsAtEnd, false);
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, ptr->get(), result);
|
||||
}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptFunctionObject_context(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
FunctionObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asFunctionObject();
|
||||
return createJavaObject(env, thisValueRef->context());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptJavaCallbackFunctionObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context,
|
||||
jstring functionName,
|
||||
jint argumentCount,
|
||||
jboolean isConstructor,
|
||||
jobject callback)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(callback, "Callback");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context),
|
||||
context);
|
||||
|
||||
FunctionObjectRef::NativeFunctionInfo info(
|
||||
AtomicStringRef::create(contextRef->get(), createJSStringFromJava(env, functionName)),
|
||||
[](ExecutionStateRef* state, ValueRef* thisValue, size_t argc, ValueRef** argv, bool isConstructorCall) -> ValueRef* {
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (!env) {
|
||||
LOGE("failed to fetch env from function callback");
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
env->PushLocalFrame(32);
|
||||
jobject callback = ensureScriptObjectExtraData(state->resolveCallee().get())->implementSideData;
|
||||
auto callbackMethodId = env->GetMethodID(env->GetObjectClass(callback), "callback",
|
||||
"(Lcom/samsung/lwe/escargot/Context;Lcom/samsung/lwe/escargot/JavaScriptValue;[Lcom/samsung/lwe/escargot/JavaScriptValue;)Ljava/util/Optional;");
|
||||
|
||||
jobjectArray javaArgv = env->NewObjectArray(argc, env->FindClass("com/samsung/lwe/escargot/JavaScriptValue"), nullptr);
|
||||
|
||||
for (size_t i = 0; i < argc; i ++) {
|
||||
auto ref = createJavaObjectFromValue(env.get(), argv[i]);
|
||||
env->SetObjectArrayElement(javaArgv, i, ref);
|
||||
env->DeleteLocalRef(ref);
|
||||
}
|
||||
jobject returnValue = env->CallObjectMethod(
|
||||
callback,
|
||||
callbackMethodId,
|
||||
createJavaObject(env.get(), state->resolveCallee()->context()),
|
||||
createJavaObjectFromValue(env.get(), thisValue),
|
||||
javaArgv
|
||||
);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
env->PopLocalFrame(NULL);
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
ValueRef* nativeReturnValue = ValueRef::createUndefined();
|
||||
if (returnValue) {
|
||||
auto classOptional = env->GetObjectClass(returnValue);
|
||||
auto methodIsPresent = env->GetMethodID(classOptional, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(returnValue, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptional, "get", "()Ljava/lang/Object;");
|
||||
jobject callbackReturnValue = env->CallObjectMethod(returnValue, methodGet);
|
||||
nativeReturnValue = unwrapValueRefFromValue(env.get(), env->GetObjectClass(callbackReturnValue), callbackReturnValue);
|
||||
}
|
||||
}
|
||||
env->PopLocalFrame(NULL);
|
||||
return nativeReturnValue;
|
||||
},
|
||||
argumentCount,
|
||||
isConstructor);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(),
|
||||
[](ExecutionStateRef* state, FunctionObjectRef::NativeFunctionInfo info) -> ValueRef* {
|
||||
return FunctionObjectRef::create(state, info);
|
||||
}, info);
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
|
||||
callback = env->NewGlobalRef(callback);
|
||||
FunctionObjectRef* fn = evaluatorResult.result->asFunctionObject();
|
||||
ensureScriptObjectExtraData(fn)->implementSideData = callback;
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptJavaCallbackFunctionObject", fn);
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_jsonStringify(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject input)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(input, "JavaScriptValue");
|
||||
|
||||
auto globalObjectRef = getPersistentPointerFromJava<GlobalObjectRef>(env, env->GetObjectClass(context), thiz);
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* inputValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(input), input);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* inputValueRef) -> ValueRef* {
|
||||
return globalObject->jsonStringify()->call(state, globalObject->json(), 1, &inputValueRef);
|
||||
}, globalObjectRef->get(), inputValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_jsonParse(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject input)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(input, "JavaScriptValue");
|
||||
|
||||
auto globalObjectRef = getPersistentPointerFromJava<GlobalObjectRef>(env, env->GetObjectClass(context), thiz);
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* inputValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(input), input);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* inputValueRef) -> ValueRef* {
|
||||
return globalObject->jsonParse()->call(state, globalObject->json(), 1, &inputValueRef);
|
||||
}, globalObjectRef->get(), inputValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
static jobject callPromiseBuiltinFunction(JNIEnv* env, jobject thiz, jobject context, jobject iterable,
|
||||
ValueRef* (*closure)(ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef))
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(iterable, "JavaScriptValue");
|
||||
|
||||
auto globalObjectRef = getPersistentPointerFromJava<GlobalObjectRef>(env, env->GetObjectClass(context), thiz);
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* iterableValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(iterable), iterable);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), closure, globalObjectRef->get(), iterableValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseAll(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseAll()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseAllSettled(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseAllSettled()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseAny(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseAny()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseRace(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseRace()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseReject(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseReject()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseResolve(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseResolve()->call(state, globalObject->promise(), 1,
|
||||
&iterableValueRef);
|
||||
});
|
||||
}
|
||||
|
|
@ -1,319 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
static void gcCallback(void* data)
|
||||
{
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (!env) {
|
||||
LOGE("failed to fetch env from gc event callback");
|
||||
return;
|
||||
}
|
||||
if (!env->ExceptionCheck()) {
|
||||
env->PushLocalFrame(32);
|
||||
jclass clazz = env->FindClass("com/samsung/lwe/escargot/NativePointerHolder");
|
||||
jmethodID mId = env->GetStaticMethodID(clazz, "cleanUp", "()V");
|
||||
env->CallStaticVoidMethod(clazz, mId);
|
||||
env->PopLocalFrame(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static OptionalRef<StringRef> builtinHelperFileRead(OptionalRef<ExecutionStateRef> state, const char* fileName, const char* builtinName)
|
||||
{
|
||||
FILE* fp = fopen(fileName, "r");
|
||||
if (fp) {
|
||||
StringRef* src = StringRef::emptyString();
|
||||
std::string utf8Str;
|
||||
std::basic_string<unsigned char, std::char_traits<unsigned char>> str;
|
||||
char buf[512];
|
||||
bool hasNonLatin1Content = false;
|
||||
size_t readLen;
|
||||
while ((readLen = fread(buf, 1, sizeof buf, fp))) {
|
||||
if (!hasNonLatin1Content) {
|
||||
for (size_t i = 0; i < readLen; i++) {
|
||||
unsigned char ch = buf[i];
|
||||
if (ch & 0x80) {
|
||||
// check non-latin1 character
|
||||
hasNonLatin1Content = true;
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
break;
|
||||
}
|
||||
str += ch;
|
||||
}
|
||||
} else {
|
||||
utf8Str.append(buf, readLen);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (StringRef::isCompressibleStringEnabled()) {
|
||||
if (state) {
|
||||
if (hasNonLatin1Content) {
|
||||
src = StringRef::createFromUTF8ToCompressibleString(state->context()->vmInstance(), utf8Str.data(), utf8Str.length(), false);
|
||||
} else {
|
||||
src = StringRef::createFromLatin1ToCompressibleString(state->context()->vmInstance(), str.data(), str.length());
|
||||
}
|
||||
} else {
|
||||
if (hasNonLatin1Content) {
|
||||
src = StringRef::createFromUTF8(utf8Str.data(), utf8Str.length(), false);
|
||||
} else {
|
||||
src = StringRef::createFromLatin1(str.data(), str.length());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hasNonLatin1Content) {
|
||||
src = StringRef::createFromUTF8(utf8Str.data(), utf8Str.length(), false);
|
||||
} else {
|
||||
src = StringRef::createFromLatin1(str.data(), str.length());
|
||||
}
|
||||
}
|
||||
return src;
|
||||
} else {
|
||||
if (state) {
|
||||
const size_t maxNameLength = 980;
|
||||
if ((strnlen(builtinName, maxNameLength) + strnlen(fileName, maxNameLength)) < maxNameLength) {
|
||||
char msg[1024];
|
||||
snprintf(msg, sizeof(msg), "GlobalObject.%s: cannot open file %s", builtinName, fileName);
|
||||
state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromUTF8(msg, strnlen(msg, sizeof msg))));
|
||||
} else {
|
||||
state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromASCII("invalid file name")));
|
||||
}
|
||||
} else {
|
||||
LOGE("%s", fileName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
class ShellPlatform : public PlatformRef {
|
||||
public:
|
||||
bool m_canBlock;
|
||||
|
||||
ShellPlatform()
|
||||
: m_canBlock(true)
|
||||
{
|
||||
}
|
||||
|
||||
void setCanBlock(bool b)
|
||||
{
|
||||
m_canBlock = b;
|
||||
}
|
||||
|
||||
virtual void markJSJobEnqueued(ContextRef* relatedContext) override
|
||||
{
|
||||
// ignore. we always check pending job after eval script
|
||||
}
|
||||
|
||||
virtual void markJSJobFromAnotherThreadExists(ContextRef* relatedContext) override
|
||||
{
|
||||
// ignore. we always check pending job after eval script
|
||||
}
|
||||
|
||||
virtual LoadModuleResult onLoadModule(ContextRef* relatedContext, ScriptRef* whereRequestFrom, StringRef* moduleSrc, ModuleType type) override
|
||||
{
|
||||
std::string referrerPath = whereRequestFrom->src()->toStdUTF8String();
|
||||
auto& loadedModules = *reinterpret_cast<std::vector<std::tuple<std::string, ContextRef*, PersistentRefHolder<ScriptRef>>>*>(threadLocalCustomData());
|
||||
|
||||
for (size_t i = 0; i < loadedModules.size(); i++) {
|
||||
if (std::get<2>(loadedModules[i]) == whereRequestFrom) {
|
||||
referrerPath = std::get<0>(loadedModules[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string absPath = absolutePath(referrerPath, moduleSrc->toStdUTF8String());
|
||||
if (absPath.length() == 0) {
|
||||
std::string s = "Error reading : " + moduleSrc->toStdUTF8String();
|
||||
return LoadModuleResult(ErrorObjectRef::Code::None, StringRef::createFromUTF8(s.data(), s.length()));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < loadedModules.size(); i++) {
|
||||
if (std::get<0>(loadedModules[i]) == absPath && std::get<1>(loadedModules[i]) == relatedContext) {
|
||||
return LoadModuleResult(std::get<2>(loadedModules[i]));
|
||||
}
|
||||
}
|
||||
|
||||
OptionalRef<StringRef> source = builtinHelperFileRead(nullptr, absPath.data(), "");
|
||||
if (!source) {
|
||||
std::string s = "Error reading : " + absPath;
|
||||
return LoadModuleResult(ErrorObjectRef::Code::None, StringRef::createFromUTF8(s.data(), s.length()));
|
||||
}
|
||||
|
||||
ScriptParserRef::InitializeScriptResult parseResult;
|
||||
StringRef* srcName = StringRef::createFromUTF8(absPath.data(), absPath.size());
|
||||
|
||||
if (type == ModuleJSON) {
|
||||
parseResult = relatedContext->scriptParser()->initializeJSONModule(source.value(), srcName);
|
||||
} else {
|
||||
parseResult = relatedContext->scriptParser()->initializeScript(source.value(), srcName, true);
|
||||
}
|
||||
|
||||
if (!parseResult.isSuccessful()) {
|
||||
return LoadModuleResult(parseResult.parseErrorCode, parseResult.parseErrorMessage);
|
||||
}
|
||||
|
||||
return LoadModuleResult(parseResult.script.get());
|
||||
}
|
||||
|
||||
virtual void didLoadModule(ContextRef* relatedContext, OptionalRef<ScriptRef> referrer, ScriptRef* loadedModule) override
|
||||
{
|
||||
std::string path;
|
||||
if (referrer && loadedModule->src()->length() && loadedModule->src()->charAt(0) != '/') {
|
||||
path = absolutePath(referrer->src()->toStdUTF8String(), loadedModule->src()->toStdUTF8String());
|
||||
} else {
|
||||
path = absolutePath(loadedModule->src()->toStdUTF8String());
|
||||
}
|
||||
auto& loadedModules = *reinterpret_cast<std::vector<std::tuple<std::string, ContextRef*, PersistentRefHolder<ScriptRef>>>*>(threadLocalCustomData());
|
||||
loadedModules.push_back(std::make_tuple(path, relatedContext, PersistentRefHolder<ScriptRef>(loadedModule)));
|
||||
}
|
||||
|
||||
virtual void hostImportModuleDynamically(ContextRef* relatedContext, ScriptRef* referrer, StringRef* src, ModuleType type, PromiseObjectRef* promise) override
|
||||
{
|
||||
LoadModuleResult loadedModuleResult = onLoadModule(relatedContext, referrer, src, type);
|
||||
notifyHostImportModuleDynamicallyResult(relatedContext, referrer, src, promise, loadedModuleResult);
|
||||
}
|
||||
|
||||
virtual bool canBlockExecution(ContextRef* relatedContext) override
|
||||
{
|
||||
return m_canBlock;
|
||||
}
|
||||
|
||||
virtual void* allocateThreadLocalCustomData() override
|
||||
{
|
||||
return new std::vector<std::tuple<std::string /* abs path */, ContextRef*, PersistentRefHolder<ScriptRef>>>();
|
||||
}
|
||||
|
||||
virtual void deallocateThreadLocalCustomData() override
|
||||
{
|
||||
delete reinterpret_cast<std::vector<std::tuple<std::string, ContextRef*, PersistentRefHolder<ScriptRef>>>*>(threadLocalCustomData());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string dirnameOf(const std::string& fname)
|
||||
{
|
||||
size_t pos = fname.find_last_of("/");
|
||||
if (std::string::npos == pos) {
|
||||
pos = fname.find_last_of("\\/");
|
||||
}
|
||||
return (std::string::npos == pos)
|
||||
? ""
|
||||
: fname.substr(0, pos);
|
||||
}
|
||||
|
||||
std::string absolutePath(const std::string& referrerPath, const std::string& src)
|
||||
{
|
||||
std::string utf8MayRelativePath = dirnameOf(referrerPath) + "/" + src;
|
||||
auto absPath = realpath(utf8MayRelativePath.data(), nullptr);
|
||||
if (!absPath) {
|
||||
return std::string();
|
||||
}
|
||||
std::string utf8AbsolutePath = absPath;
|
||||
free(absPath);
|
||||
|
||||
return utf8AbsolutePath;
|
||||
}
|
||||
|
||||
std::string absolutePath(const std::string& src)
|
||||
{
|
||||
auto absPath = realpath(src.data(), nullptr);
|
||||
if (!absPath) {
|
||||
return std::string();
|
||||
}
|
||||
std::string utf8AbsolutePath = absPath;
|
||||
free(absPath);
|
||||
|
||||
return utf8AbsolutePath;
|
||||
}
|
||||
};
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_initializeGlobals(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (!Globals::isInitialized()) {
|
||||
Globals::initialize(new ShellPlatform());
|
||||
Memory::addGCEventListener(Memory::MARK_START, gcCallback, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_finalizeGlobals(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (Globals::isInitialized()) {
|
||||
// java object cleanup
|
||||
gcCallback(nullptr);
|
||||
|
||||
Memory::removeGCEventListener(Memory::MARK_START, gcCallback, nullptr);
|
||||
Globals::finalize();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_initializeThread(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (!Globals::isInitialized()) {
|
||||
Globals::initializeThread();
|
||||
}
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_finalizeThread(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (Globals::isInitialized()) {
|
||||
Globals::finalizeThread();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_isInitialized(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return Globals::isInitialized();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_version(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
std::string version = Globals::version();
|
||||
std::basic_string<uint16_t> u16Version;
|
||||
|
||||
for (auto c: version) {
|
||||
u16Version.push_back(c);
|
||||
}
|
||||
|
||||
return env->NewString(u16Version.data(), u16Version.length());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_buildDate(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
std::string version = Globals::buildDate();
|
||||
std::basic_string<uint16_t> u16Version;
|
||||
|
||||
for (auto c: version) {
|
||||
u16Version.push_back(c);
|
||||
}
|
||||
|
||||
return env->NewString(u16Version.data(), u16Version.length());
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_gc(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
Memory::gc();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_heapSize(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return Memory::heapSize();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_totalSize(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return Memory::totalSize();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_setGCFrequency(JNIEnv* env, jclass clazz, jint value)
|
||||
{
|
||||
Memory::setGCFrequency(value);
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_NativePointerHolder_releaseNativePointerMemory(JNIEnv* env,
|
||||
jclass clazz, jlong pointer)
|
||||
{
|
||||
uint64_t ptrInNumber = (uint64_t)(pointer);
|
||||
if (ptrInNumber > g_nonPointerValueLast && !(pointer & 1)) {
|
||||
PersistentRefHolder<void>* pRef = reinterpret_cast<PersistentRefHolder<void>*>(pointer);
|
||||
delete pRef;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_create(JNIEnv* env, jclass clazz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state) -> ValueRef* {
|
||||
return ObjectRef::create(state);
|
||||
});
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_get(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject propertyName)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef) -> ValueRef* {
|
||||
return thisValueRef->get(state, propertyNameValueRef);
|
||||
}, thisValueRef, propertyNameValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_set(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject propertyName, jobject value)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(value, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
ValueRef* valueRef = unwrapValueRefFromValue(env, env->GetObjectClass(value), value);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef, ValueRef* valueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->set(state, propertyNameValueRef, valueRef));
|
||||
}, thisValueRef, propertyNameValueRef, valueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_defineDataProperty(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject propertyName,
|
||||
jobject value,
|
||||
jboolean isWritable,
|
||||
jboolean isEnumerable,
|
||||
jboolean isConfigurable)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(value, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
ValueRef* valueRef = unwrapValueRefFromValue(env, env->GetObjectClass(value), value);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef, ValueRef* valueRef,
|
||||
jboolean isWritable,
|
||||
jboolean isEnumerable,
|
||||
jboolean isConfigurable) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->defineDataProperty(state, propertyNameValueRef, valueRef, isWritable, isEnumerable, isConfigurable));
|
||||
}, thisValueRef, propertyNameValueRef, valueRef, isWritable, isEnumerable, isConfigurable);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_getOwnProperty(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject propertyName)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef) -> ValueRef* {
|
||||
return thisValueRef->getOwnProperty(state, propertyNameValueRef);
|
||||
}, thisValueRef, propertyNameValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_setExtraData(JNIEnv* env, jobject thiz,
|
||||
jobject object)
|
||||
{
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
jobject extraData = nullptr;
|
||||
|
||||
if (object) {
|
||||
auto classOptional = env->GetObjectClass(object);
|
||||
auto methodIsPresent = env->GetMethodID(classOptional, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(object, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptional, "get", "()Ljava/lang/Object;");
|
||||
jboolean isSucceed;
|
||||
extraData = env->CallObjectMethod(object, methodGet);
|
||||
extraData = env->NewGlobalRef(extraData);
|
||||
}
|
||||
}
|
||||
|
||||
ensureScriptObjectExtraData(thisValueRef)->userData = extraData;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_extraData(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
jobject extraData = nullptr;
|
||||
if (thisValueRef->extraData()) {
|
||||
extraData = ensureScriptObjectExtraData(thisValueRef)->userData;
|
||||
}
|
||||
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
if (extraData) {
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
extraData);
|
||||
} else {
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state) -> ValueRef* {
|
||||
return PromiseObjectRef::create(state);
|
||||
});
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asPromiseObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_state(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
|
||||
jclass enumClass = env->FindClass(
|
||||
"com/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState");
|
||||
jfieldID enumFieldID;
|
||||
PromiseObjectRef::PromiseState state = thisValueRef->state();
|
||||
if (state == PromiseObjectRef::Pending) {
|
||||
enumFieldID = env->GetStaticFieldID(enumClass, "Pending",
|
||||
"Lcom/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState;");
|
||||
} else if (state == PromiseObjectRef::FulFilled) {
|
||||
enumFieldID = env->GetStaticFieldID(enumClass, "FulFilled",
|
||||
"Lcom/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState;");
|
||||
} else {
|
||||
enumFieldID = env->GetStaticFieldID(enumClass, "Rejected",
|
||||
"Lcom/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState;");
|
||||
}
|
||||
return env->GetStaticObjectField(enumClass, enumFieldID);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_promiseResult(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
return createJavaObjectFromValue(env, thisValueRef->promiseResult());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_then__Lcom_samsung_lwe_escargot_Context_2Lcom_samsung_lwe_escargot_JavaScriptValue_2(
|
||||
JNIEnv* env, jobject thiz, jobject context, jobject handler)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(handler, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* handlerRef = unwrapValueRefFromValue(env, env->GetObjectClass(handler), handler);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* handlerRef) -> ValueRef* {
|
||||
return promiseObject->then(state, handlerRef);
|
||||
}, thisValueRef, handlerRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_then__Lcom_samsung_lwe_escargot_Context_2Lcom_samsung_lwe_escargot_JavaScriptValue_2Lcom_samsung_lwe_escargot_JavaScriptValue_2(
|
||||
JNIEnv* env, jobject thiz, jobject context, jobject onFulfilled, jobject onRejected)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(onFulfilled, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(onRejected, "JavaScriptValue");
|
||||
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* onFulfilledRef = unwrapValueRefFromValue(env, env->GetObjectClass(onFulfilled), onFulfilled);
|
||||
ValueRef* onRejectedRef = unwrapValueRefFromValue(env, env->GetObjectClass(onRejected), onRejected);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* onFulfilledRef, ValueRef* onRejectedRef) -> ValueRef* {
|
||||
return promiseObject->then(state, onFulfilledRef, onRejectedRef);
|
||||
}, thisValueRef, onFulfilledRef, onRejectedRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_catchOperation(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject handler)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(handler, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* handlerRef = unwrapValueRefFromValue(env, env->GetObjectClass(handler), handler);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* handlerRef) -> ValueRef* {
|
||||
return promiseObject->catchOperation(state, handlerRef);
|
||||
}, thisValueRef, handlerRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_fulfill(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject value)
|
||||
{
|
||||
THROW_NPE_RETURN_VOID(context, "Context");
|
||||
THROW_NPE_RETURN_VOID(value, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* valueRef = unwrapValueRefFromValue(env, env->GetObjectClass(value), value);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* valueRef) -> ValueRef* {
|
||||
promiseObject->fulfill(state, valueRef);
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, valueRef);
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_reject(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject reason)
|
||||
{
|
||||
THROW_NPE_RETURN_VOID(context, "Context");
|
||||
THROW_NPE_RETURN_VOID(reason, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* reasonRef = unwrapValueRefFromValue(env, env->GetObjectClass(reason), reason);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* reasonRef) -> ValueRef* {
|
||||
promiseObject->reject(state, reasonRef);
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, reasonRef);
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_hasHandler(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
return thisValueRef->hasResolveHandlers() || thisValueRef->hasRejectHandlers();
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptString_create(JNIEnv* env, jclass clazz, jstring value)
|
||||
{
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptString", createJSStringFromJava(env, value));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptString_toJavaString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
StringRef* string = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asString();
|
||||
return createJavaStringFromJS(env, string);
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_create(JNIEnv* env, jclass clazz, jobject value)
|
||||
{
|
||||
OptionalRef<StringRef> descString;
|
||||
if (value) {
|
||||
auto classOptionalJavaScriptString = env->GetObjectClass(value);
|
||||
auto methodIsPresent = env->GetMethodID(classOptionalJavaScriptString, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(value, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptionalJavaScriptString, "get", "()Ljava/lang/Object;");
|
||||
jboolean isSucceed;
|
||||
jobject javaObjectValue = env->CallObjectMethod(value, methodGet);
|
||||
descString = unwrapValueRefFromValue(env, env->GetObjectClass(javaObjectValue), javaObjectValue)->asString();
|
||||
}
|
||||
}
|
||||
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptSymbol", SymbolRef::create(descString));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_fromGlobalSymbolRegistry(JNIEnv* env, jclass clazz,
|
||||
jobject vm,
|
||||
jobject stringKey)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(vm, "VMInstance");
|
||||
THROW_NPE_RETURN_NULL(stringKey, "JavaScriptString");
|
||||
|
||||
auto ptr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(vm), vm);
|
||||
auto key = unwrapValueRefFromValue(env, env->GetObjectClass(stringKey), stringKey);
|
||||
|
||||
auto symbol = SymbolRef::fromGlobalSymbolRegistry(ptr->get(), key->asString());
|
||||
return createJavaObjectFromValue(env, symbol);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_descriptionString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto desc = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asSymbol()->descriptionString();
|
||||
return createJavaObjectFromValue(env, desc);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_descriptionValue(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto desc = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asSymbol()->descriptionValue();
|
||||
return createJavaObjectFromValue(env, desc);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_symbolDescriptiveString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto desc = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asSymbol()->symbolDescriptiveString();
|
||||
return createJavaObjectFromValue(env, desc);
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_VMInstance_create(JNIEnv *env, jclass clazz, jobject locale,
|
||||
jobject timezone)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(locale, "Optional<String>");
|
||||
THROW_NPE_RETURN_NULL(timezone, "Optional<String>");
|
||||
|
||||
std::string localeString = fetchStringFromJavaOptionalString(env, locale);
|
||||
std::string timezoneString = fetchStringFromJavaOptionalString(env, timezone);
|
||||
|
||||
auto vmRef = VMInstanceRef::create(localeString.length() ? localeString.data() : nullptr,
|
||||
timezoneString.length() ? timezoneString.data() : nullptr);
|
||||
return createJavaObject(env, vmRef.get());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_VMInstance_hasPendingJob(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto vmPtr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(thiz),
|
||||
thiz);
|
||||
return vmPtr->get()->hasPendingJob();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_VMInstance_executePendingJob(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto vmPtr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(thiz),
|
||||
thiz);
|
||||
if (vmPtr->get()->hasPendingJob()) {
|
||||
vmPtr->get()->executePendingJob();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,500 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_createUndefined(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::createUndefined());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_createNull(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::createNull());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_create__I(JNIEnv* env, jclass clazz, jint value)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::create(value));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_create__D(JNIEnv* env, jclass clazz, jdouble value)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::create(value));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_create__Z(JNIEnv* env, jclass clazz, jboolean value)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::create(static_cast<bool>(value)));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isUndefined(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isUndefined();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isNull(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isNull();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isUndefinedOrNull(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isUndefinedOrNull();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isNumber(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isNumber();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isInt32(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isInt32();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isBoolean(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isBoolean();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isTrue(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isTrue();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isFalse(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isFalse();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isString();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isSymbol(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isSymbol();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isBigInt(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isBigInt();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isCallable(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isCallable();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isArrayObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isArrayObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isFunctionObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isFunctionObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isPromiseObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isPromiseObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isErrorObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isErrorObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asBoolean(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Boolean);
|
||||
return ref->asBoolean();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asInt32(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Int32);
|
||||
return ref->asInt32();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asNumber(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Number);
|
||||
return ref->asNumber();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, String);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptSymbol(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Symbol);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptBigInt(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, BigInt);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Object);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptArrayObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, ArrayObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptFunctionObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, FunctionObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptPromiseObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, PromiseObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptErrorObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, ErrorObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toString(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return thisValueRef->toString(state);
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toNumber(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toNumber(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorDoubleResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toInteger(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toInteger(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorDoubleResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toInt32(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toInt32(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorIntegerResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toBoolean(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toBoolean(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toObject(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return thisValueRef->toObject(state);
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_abstractEqualsTo(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject other)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(other, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* otherValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(other), other);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* otherValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->abstractEqualsTo(state, otherValueRef));
|
||||
}, thisValueRef, otherValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_equalsTo(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject other)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(other, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* otherValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(other), other);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* otherValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->equalsTo(state, otherValueRef));
|
||||
}, thisValueRef, otherValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_instanceOf(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject other)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(other, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* otherValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(other), other);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* otherValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->instanceOf(state, otherValueRef));
|
||||
}, thisValueRef, otherValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_call(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject receiver, jobjectArray argv)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(receiver, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(argv, "JavaScriptValue[]");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* receiverValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(receiver), receiver);
|
||||
|
||||
auto argvLength = env->GetArrayLength(argv);
|
||||
ValueRef** argVector = reinterpret_cast<ValueRef**>(Memory::gcMalloc(argvLength * sizeof(ValueRef*)));
|
||||
|
||||
for (jsize i = 0; i < argvLength; i++) {
|
||||
jobject e = env->GetObjectArrayElement(argv, i);
|
||||
argVector[i] = unwrapValueRefFromValue(env, env->GetObjectClass(e), e);
|
||||
env->DeleteLocalRef(e);
|
||||
}
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(),
|
||||
[](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* receiverValueRef, ValueRef** argVector, int argvLength) -> ValueRef* {
|
||||
return thisValueRef->call(state, receiverValueRef, argvLength, argVector);
|
||||
}, thisValueRef, receiverValueRef, argVector, argvLength);
|
||||
|
||||
Memory::gcFree(argVector);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_construct(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobjectArray argv)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(argv, "JavaScriptValue[]");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto argvLength = env->GetArrayLength(argv);
|
||||
ValueRef** argVector = reinterpret_cast<ValueRef**>(Memory::gcMalloc(argvLength * sizeof(ValueRef*)));
|
||||
|
||||
for (jsize i = 0; i < argvLength; i++) {
|
||||
jobject e = env->GetObjectArrayElement(argv, i);
|
||||
argVector[i] = unwrapValueRefFromValue(env, env->GetObjectClass(e), e);
|
||||
env->DeleteLocalRef(e);
|
||||
}
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(),
|
||||
[](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef** argVector, int argvLength) -> ValueRef* {
|
||||
return thisValueRef->construct(state, argvLength, argVector);
|
||||
}, thisValueRef, argVector, argvLength);
|
||||
|
||||
Memory::gcFree(argVector);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
final public class Bridge {
|
||||
static { Escargot.init(); }
|
||||
private Bridge() {
|
||||
}
|
||||
|
||||
public abstract static class Adapter {
|
||||
/**
|
||||
* @param context Context from callee
|
||||
* @param data the data parameter contains value when call this function from JavaScript
|
||||
* @return if want to return data to JavaScript callback, you can return value from this callback.
|
||||
*/
|
||||
public abstract Optional<JavaScriptValue> callback(Context context, Optional<JavaScriptValue> data);
|
||||
}
|
||||
|
||||
/**
|
||||
* if success, you can access `GlobalObject`.`objectName`.`propertyName`(...) in JavaScript
|
||||
*
|
||||
* @param context
|
||||
* @param objectName
|
||||
* @param propertyName
|
||||
* @param adapter
|
||||
* @return returns true if success
|
||||
*/
|
||||
static public native boolean register(Context context, String objectName, String propertyName, Adapter adapter);
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Context extends NativePointerHolder {
|
||||
protected Context(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
public native static Context create(VMInstance vmInstance);
|
||||
public boolean exceptionWasThrown()
|
||||
{
|
||||
return m_lastThrownException.isPresent();
|
||||
}
|
||||
public Optional<JavaScriptValue> lastThrownException()
|
||||
{
|
||||
Optional<JavaScriptValue> lastThrownException = m_lastThrownException;
|
||||
m_lastThrownException = Optional.empty();
|
||||
return lastThrownException;
|
||||
}
|
||||
public native JavaScriptGlobalObject getGlobalObject();
|
||||
public native boolean throwException(JavaScriptValue exception);
|
||||
|
||||
protected Optional<JavaScriptValue> m_lastThrownException = Optional.empty();
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Escargot {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("escargot-jni");
|
||||
} catch(UnsatisfiedLinkError e) {
|
||||
// try to load library from jar resource
|
||||
Optional<String> r = copyStreamAsTempFile(Escargot.class.getResourceAsStream("/libescargot-jni.so"),
|
||||
"libescargot-jni-", ".so", true);
|
||||
if (r.isPresent()) {
|
||||
System.load(r.get());
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
static public Optional<String> copyStreamAsTempFile(InputStream is, String prefix, String suffix, boolean isExecutable)
|
||||
{
|
||||
try {
|
||||
File f = File.createTempFile(prefix, suffix);
|
||||
f.deleteOnExit();
|
||||
f.setExecutable(isExecutable);
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
int read;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((read = is.read(bytes)) != -1) {
|
||||
fos.write(bytes, 0, read);
|
||||
}
|
||||
fos.flush();
|
||||
is.close();
|
||||
fos.close();
|
||||
return Optional.of(f.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
static native public void init();
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
final public class Evaluator {
|
||||
static { Escargot.init(); }
|
||||
private Evaluator() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param source
|
||||
* @param sourceFileName
|
||||
* @return return result if eval was successful
|
||||
*/
|
||||
static public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName)
|
||||
{
|
||||
return evalScript(context, source, sourceFileName, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param source
|
||||
* @param sourceFileName
|
||||
* @param shouldPrintScriptResult
|
||||
* @return return result if eval was successful
|
||||
*/
|
||||
static public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName,
|
||||
boolean shouldPrintScriptResult)
|
||||
{
|
||||
return evalScript(context, source, sourceFileName, shouldPrintScriptResult, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param source
|
||||
* @param sourceFileName
|
||||
* @param shouldPrintScriptResult
|
||||
* @param shouldExecutePendingJobsAtEnd
|
||||
* @return return result if eval was successful
|
||||
*/
|
||||
static native public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName,
|
||||
boolean shouldPrintScriptResult, boolean shouldExecutePendingJobsAtEnd);
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
final public class Globals {
|
||||
private Globals() {
|
||||
|
||||
}
|
||||
static { Escargot.init(); }
|
||||
|
||||
static public native void initializeGlobals();
|
||||
static public native void finalizeGlobals();
|
||||
static public native void initializeThread();
|
||||
static public native void finalizeThread();
|
||||
|
||||
static public native boolean isInitialized();
|
||||
|
||||
static public native String version();
|
||||
static public native String buildDate();
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptArrayObject extends JavaScriptObject {
|
||||
protected JavaScriptArrayObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
static public native JavaScriptArrayObject create(Context context);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param from
|
||||
* @return
|
||||
*/
|
||||
static public Optional<JavaScriptArrayObject> create(Context context, JavaScriptValue[] from)
|
||||
{
|
||||
JavaScriptArrayObject ret = JavaScriptArrayObject.create(context);
|
||||
ret.setLength(context, from.length);
|
||||
for (int i = 0; i < from.length; i ++) {
|
||||
Optional<Boolean> b = ret.set(context, JavaScriptValue.create(i), from[i]);
|
||||
if (!b.isPresent() || !b.get())
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(ret);
|
||||
}
|
||||
public native long length(Context context);
|
||||
public native void setLength(Context context, long newLength);
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptBigInt extends JavaScriptValue {
|
||||
protected JavaScriptBigInt(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
|
||||
static public native JavaScriptBigInt create(int num);
|
||||
static public native JavaScriptBigInt create(long num);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param numString
|
||||
* @param radix
|
||||
* @return
|
||||
*/
|
||||
static public native JavaScriptBigInt create(String numString, int radix);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param numString
|
||||
* @param radix
|
||||
* @return
|
||||
*/
|
||||
static public native JavaScriptBigInt create(JavaScriptString numString, int radix);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param radix
|
||||
* @return
|
||||
*/
|
||||
public native JavaScriptString toString(int radix);
|
||||
|
||||
public native double toNumber();
|
||||
public native long toInt64();
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptErrorObject extends JavaScriptObject {
|
||||
protected JavaScriptErrorObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
|
||||
public enum ErrorKind {
|
||||
None,
|
||||
ReferenceError,
|
||||
TypeError,
|
||||
SyntaxError,
|
||||
RangeError,
|
||||
URIError,
|
||||
EvalError,
|
||||
AggregateError
|
||||
}
|
||||
static public native JavaScriptErrorObject create(Context context, ErrorKind kind, String message);
|
||||
public native Optional<JavaScriptString> stack(Context context);
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
public class JavaScriptFunctionObject extends JavaScriptObject {
|
||||
protected JavaScriptFunctionObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
public native Context context();
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptGlobalObject extends JavaScriptObject {
|
||||
protected JavaScriptGlobalObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptString> jsonStringify(Context context, JavaScriptValue input);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> jsonParse(Context context, JavaScriptValue input);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseAll(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseAllSettled(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseAny(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseRace(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseReject(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseResolve(Context context, JavaScriptValue iterable);
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptJavaCallbackFunctionObject extends JavaScriptFunctionObject {
|
||||
protected JavaScriptJavaCallbackFunctionObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
|
||||
public abstract static class Callback {
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param receiverValue
|
||||
* @param arguments
|
||||
* @return
|
||||
*/
|
||||
public abstract Optional<JavaScriptValue> callback(Context context, JavaScriptValue receiverValue, JavaScriptValue arguments[]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param functionName
|
||||
* @param argumentCount
|
||||
* @param isConstructor
|
||||
* @param callback
|
||||
* @return
|
||||
*/
|
||||
static public native JavaScriptJavaCallbackFunctionObject create(Context context, String functionName, int argumentCount, boolean isConstructor, Callback callback);
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptObject extends JavaScriptValue {
|
||||
protected JavaScriptObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
static public native JavaScriptObject create(Context context);
|
||||
/**
|
||||
* return thisObject[propertyName];
|
||||
* @param context
|
||||
* @param propertyName
|
||||
* @return JavaScriptValue or Optional.empty if there was a exception while executing get function
|
||||
*/
|
||||
public native Optional<JavaScriptValue> get(Context context, JavaScriptValue propertyName);
|
||||
|
||||
/**
|
||||
* thisObject[propertyName] = value;
|
||||
* @param context
|
||||
* @param propertyName
|
||||
* @param value
|
||||
* @return Boolean or Optional.empty if there was a exception while executing set function
|
||||
*/
|
||||
public native Optional<Boolean> set(Context context, JavaScriptValue propertyName, JavaScriptValue value);
|
||||
|
||||
/**
|
||||
* Object.definePropety(
|
||||
* thisObject,
|
||||
* propertyName,
|
||||
* {
|
||||
* value: value
|
||||
* writable: isWritable
|
||||
* enumerable: isEnumerable
|
||||
* configurable: isConfigurable
|
||||
* })
|
||||
* @param context
|
||||
* @param propertyName
|
||||
* @param value
|
||||
* @param isWritable
|
||||
* @param isEnumerable
|
||||
* @param isConfigurable
|
||||
* @return Boolean or Optional.empty if there was a exception while executing set function
|
||||
*/
|
||||
public native Optional<Boolean> defineDataProperty(Context context, JavaScriptValue propertyName, JavaScriptValue value,
|
||||
boolean isWritable, boolean isEnumerable, boolean isConfigurable);
|
||||
|
||||
/**
|
||||
* return thisObject[propertyName]; // but only search thisObject. this function does not get value on prototype chain
|
||||
* there is no simple equivalent js function or source
|
||||
* @param context
|
||||
* @param propertyName
|
||||
* @return JavaScriptValue or Optional.empty if there was a exception while executing getOwnProperty function
|
||||
*/
|
||||
public native Optional<JavaScriptValue> getOwnProperty(Context context, JavaScriptValue propertyName);
|
||||
|
||||
/**
|
||||
* store Java Object in JavaScriptObject
|
||||
* @param object
|
||||
*/
|
||||
public native void setExtraData(Optional<Object> object);
|
||||
|
||||
/**
|
||||
* returns stored Java object in JavaScriptObject
|
||||
* this function returns `Optional with Object` or `empty Optional`
|
||||
* @return
|
||||
*/
|
||||
public native Optional<Object> extraData();
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptPromiseObject extends JavaScriptObject {
|
||||
protected JavaScriptPromiseObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
static public native JavaScriptPromiseObject create(Context context);
|
||||
|
||||
enum PromiseState {
|
||||
Pending,
|
||||
FulFilled,
|
||||
Rejected
|
||||
};
|
||||
public native PromiseState state();
|
||||
public native JavaScriptValue promiseResult();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptObject> then(Context context, JavaScriptValue handler);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param onFulfilled
|
||||
* @param onRejected
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptObject> then(Context context, JavaScriptValue onFulfilled, JavaScriptValue onRejected);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptObject> catchOperation(Context context, JavaScriptValue handler);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param value
|
||||
*/
|
||||
public native void fulfill(Context context, JavaScriptValue value);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param reason
|
||||
*/
|
||||
public native void reject(Context context, JavaScriptValue reason);
|
||||
|
||||
public native boolean hasHandler();
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
public class JavaScriptString extends JavaScriptValue {
|
||||
protected JavaScriptString(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
native static public JavaScriptString create(String value);
|
||||
native public String toJavaString();
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptSymbol extends JavaScriptValue {
|
||||
protected JavaScriptSymbol(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
|
||||
native static public JavaScriptSymbol create(Optional<JavaScriptString> value);
|
||||
native public JavaScriptString descriptionString();
|
||||
native public JavaScriptValue descriptionValue();
|
||||
native public JavaScriptString symbolDescriptiveString();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vm
|
||||
* @param stringKey
|
||||
* @return
|
||||
*/
|
||||
native public static JavaScriptSymbol fromGlobalSymbolRegistry(VMInstance vm, JavaScriptString stringKey);
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptValue extends NativePointerHolder {
|
||||
protected JavaScriptValue(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
|
||||
protected JavaScriptValue(long nativePointer, boolean isHeapValue)
|
||||
{
|
||||
super(nativePointer, isHeapValue);
|
||||
}
|
||||
|
||||
native static public JavaScriptValue createUndefined();
|
||||
native static public JavaScriptValue createNull();
|
||||
native static public JavaScriptValue create(boolean value);
|
||||
native static public JavaScriptValue create(int value);
|
||||
native static public JavaScriptValue create(double value);
|
||||
|
||||
native public boolean isUndefined();
|
||||
native public boolean isNull();
|
||||
native public boolean isUndefinedOrNull();
|
||||
native public boolean isBoolean();
|
||||
native public boolean isTrue();
|
||||
native public boolean isFalse();
|
||||
native public boolean isNumber();
|
||||
native public boolean isInt32();
|
||||
native public boolean isString();
|
||||
native public boolean isSymbol();
|
||||
native public boolean isBigInt();
|
||||
native public boolean isCallable();
|
||||
native public boolean isObject();
|
||||
native public boolean isArrayObject();
|
||||
native public boolean isFunctionObject();
|
||||
native public boolean isPromiseObject();
|
||||
native public boolean isErrorObject();
|
||||
|
||||
native public boolean asBoolean();
|
||||
native public int asInt32();
|
||||
native public double asNumber();
|
||||
native public JavaScriptString asScriptString();
|
||||
native public JavaScriptSymbol asScriptSymbol();
|
||||
native public JavaScriptBigInt asScriptBigInt();
|
||||
native public JavaScriptObject asScriptObject();
|
||||
native public JavaScriptArrayObject asScriptArrayObject();
|
||||
native public JavaScriptFunctionObject asScriptFunctionObject();
|
||||
native public JavaScriptPromiseObject asScriptPromiseObject();
|
||||
native public JavaScriptErrorObject asScriptErrorObject();
|
||||
|
||||
native public Optional<JavaScriptString> toString(Context context);
|
||||
native public Optional<Boolean> toBoolean(Context context);
|
||||
native public Optional<Double> toNumber(Context context);
|
||||
native public Optional<Double> toInteger(Context context);
|
||||
native public Optional<Integer> toInt32(Context context);
|
||||
native public Optional<JavaScriptObject> toObject(Context context);
|
||||
|
||||
/**
|
||||
* this == other
|
||||
* @param context
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
native public Optional<Boolean> abstractEqualsTo(Context context, JavaScriptValue other);
|
||||
/**
|
||||
* this === other
|
||||
* @param context
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
native public Optional<Boolean> equalsTo(Context context, JavaScriptValue other);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
native public Optional<Boolean> instanceOf(Context context, JavaScriptValue other);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param receiver
|
||||
* @param argv
|
||||
* @return
|
||||
*/
|
||||
native public Optional<JavaScriptValue> call(Context context, JavaScriptValue receiver, JavaScriptValue[] argv);
|
||||
|
||||
/**
|
||||
* same with new expression in js
|
||||
* @param context
|
||||
* @param argv
|
||||
* @return
|
||||
*/
|
||||
native public Optional<JavaScriptValue> construct(Context context, JavaScriptValue[] argv);
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
final public class Memory {
|
||||
static { Escargot.init(); }
|
||||
private Memory() {
|
||||
}
|
||||
|
||||
static public native void gc();
|
||||
|
||||
/**
|
||||
* Return the number of bytes in the heap. Excludes bdwgc private data structures. Excludes the unmapped memory
|
||||
* @return
|
||||
*/
|
||||
static public native long heapSize();
|
||||
|
||||
/**
|
||||
* Return the total number of bytes allocated in this process
|
||||
* @return
|
||||
*/
|
||||
static public native long totalSize();
|
||||
|
||||
/**
|
||||
* NOTE bdwgc(c/c++ gc library escargot use) allocate at least N/GC_free_space_divisor bytes between collections
|
||||
* (Allocated memory by GC x 2) / (Frequency parameter value)
|
||||
* Increasing this value may use less space but there is more collection event
|
||||
* @param value
|
||||
*/
|
||||
static public native void setGCFrequency(int value);
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class NativePointerHolder {
|
||||
static ThreadLocal<ReferenceQueue<Object>> s_referenceQueue = ThreadLocal.withInitial(() -> new ReferenceQueue<>());
|
||||
static ThreadLocal<Set<NativePointerHolderPhantomReference>> s_referenceSet = ThreadLocal.withInitial(() -> new HashSet<>());
|
||||
static { Escargot.init(); }
|
||||
|
||||
public static class NativePointerHolderPhantomReference extends PhantomReference<Object> {
|
||||
public NativePointerHolderPhantomReference(NativePointerHolder nativePointerHolder, ReferenceQueue<Object> queue)
|
||||
{
|
||||
super(nativePointerHolder, queue);
|
||||
m_nativePointer = nativePointerHolder.m_nativePointer;
|
||||
}
|
||||
public void release()
|
||||
{
|
||||
releaseNativePointerMemory(m_nativePointer);
|
||||
}
|
||||
long m_nativePointer;
|
||||
}
|
||||
|
||||
NativePointerHolder(long nativePointer, boolean isHeapValue)
|
||||
{
|
||||
m_nativePointer = nativePointer;
|
||||
if (isHeapValue) {
|
||||
s_referenceSet.get().add(new NativePointerHolderPhantomReference(this, s_referenceQueue.get()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanUp()
|
||||
{
|
||||
Method refersToMethod = null;
|
||||
Method[] methods = NativePointerHolderPhantomReference.class
|
||||
.getSuperclass().getSuperclass() // <- points Reference<T>
|
||||
.getDeclaredMethods();
|
||||
for (int i = 0; i < methods.length; i ++) {
|
||||
if (methods[i].getName().equals("refersTo")) {
|
||||
refersToMethod = methods[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (NativePointerHolderPhantomReference reference : s_referenceSet.get()) {
|
||||
if (refersToMethod != null) {
|
||||
try {
|
||||
refersToMethod.invoke(reference, (java.lang.Object)null);
|
||||
continue;
|
||||
} catch (Exception e) {
|
||||
refersToMethod = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
reference.isEnqueued();
|
||||
}
|
||||
|
||||
Reference<?> ref;
|
||||
while ((ref = s_referenceQueue.get().poll()) != null) {
|
||||
s_referenceSet.get().remove(((NativePointerHolderPhantomReference)ref));
|
||||
((NativePointerHolderPhantomReference)ref).release();
|
||||
ref.clear();
|
||||
}
|
||||
}
|
||||
|
||||
static private native void releaseNativePointerMemory(long pointer);
|
||||
protected long m_nativePointer;
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class VMInstance extends NativePointerHolder {
|
||||
protected VMInstance(long nativePointer)
|
||||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
// you can to provide timezone as TZ database name like "US/Pacific".
|
||||
// if you don't provide, we try to detect system timezone.
|
||||
public native static VMInstance create(Optional<String> locale, Optional<String> timezone);
|
||||
|
||||
public native boolean hasPendingJob();
|
||||
public native void executePendingJob();
|
||||
public void executeEveryPendingJobIfExists()
|
||||
{
|
||||
while (hasPendingJob()) {
|
||||
executePendingJob();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package com.samsung.lwe.escargot.internal;
|
||||
|
||||
import com.samsung.lwe.escargot.JavaScriptValue;
|
||||
|
||||
public class JavaScriptRuntimeException extends RuntimeException {
|
||||
public JavaScriptRuntimeException(JavaScriptValue exception)
|
||||
{
|
||||
this.m_exception = exception;
|
||||
}
|
||||
|
||||
public JavaScriptValue exception() {
|
||||
return m_exception;
|
||||
}
|
||||
|
||||
private JavaScriptValue m_exception;
|
||||
}
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
package com.samsung.lwe.escargot.util;
|
||||
|
||||
|
||||
import com.samsung.lwe.escargot.Context;
|
||||
import com.samsung.lwe.escargot.JavaScriptPromiseObject;
|
||||
import com.samsung.lwe.escargot.JavaScriptValue;
|
||||
import com.samsung.lwe.escargot.VMInstance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MultiThreadExecutor {
|
||||
public static interface WorkerThreadEndNotifier {
|
||||
/**
|
||||
* called by worker thread before thread exiting
|
||||
* @param instance
|
||||
*/
|
||||
public abstract void notify(MultiThreadExecutor executor, ExecutorInstance instance);
|
||||
}
|
||||
|
||||
VMInstance m_vmInstance;
|
||||
Thread m_javaScriptThread;
|
||||
ArrayList<ExecutorInstance> m_activeInstances = new ArrayList<>();
|
||||
ArrayList<ExecutorInstance> m_endedInstances = new ArrayList<>();
|
||||
WorkerThreadEndNotifier m_workerThreadEndNotifier;
|
||||
|
||||
/**
|
||||
* init with current thread as JavaScript Thread
|
||||
* and manual threadEndNotifier
|
||||
* @param vmInstance
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance)
|
||||
{
|
||||
this(vmInstance, (executor, instance) -> {
|
||||
}, Thread.currentThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* init with manual threadEndNotifier
|
||||
* @param vmInstance
|
||||
* @param javaScriptThread
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance, Thread javaScriptThread)
|
||||
{
|
||||
this(vmInstance, (executor, instance) -> {
|
||||
}, javaScriptThread);
|
||||
}
|
||||
|
||||
/**
|
||||
* init with current thread as JavaScript Thread
|
||||
* and manual threadEndNotifier
|
||||
* @param vmInstance
|
||||
* @param threadEndNotifier
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance, WorkerThreadEndNotifier threadEndNotifier)
|
||||
{
|
||||
this(vmInstance, threadEndNotifier, Thread.currentThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param vmInstance
|
||||
* @param threadEndNotifier
|
||||
* @param javaScriptThread
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance, WorkerThreadEndNotifier threadEndNotifier, Thread javaScriptThread)
|
||||
{
|
||||
if (vmInstance == null || threadEndNotifier == null || javaScriptThread == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
m_javaScriptThread = javaScriptThread;
|
||||
m_vmInstance = vmInstance;
|
||||
m_workerThreadEndNotifier = threadEndNotifier;
|
||||
}
|
||||
|
||||
public static abstract class ResultBuilder {
|
||||
public abstract JavaScriptValue build(Context scriptContext, ResultBuilderContext builderContext);
|
||||
}
|
||||
|
||||
public static class ResultBuilderContext {
|
||||
private boolean m_wasSuccessful;
|
||||
private Object m_data;
|
||||
|
||||
public ResultBuilderContext(boolean wasSuccessful, Object data) {
|
||||
m_wasSuccessful = wasSuccessful;
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
public Object data() {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
public boolean wasSuccessful() {
|
||||
return m_wasSuccessful;
|
||||
}
|
||||
}
|
||||
public static abstract class Executor {
|
||||
public abstract ResultBuilderContext run();
|
||||
}
|
||||
|
||||
public static class ExecutorInstance {
|
||||
private Context m_context;
|
||||
private JavaScriptPromiseObject m_promise;
|
||||
private Thread m_thread;
|
||||
private ResultBuilderContext m_builderContext;
|
||||
private ResultBuilder m_resultBuilder;
|
||||
|
||||
private ExecutorInstance(Context context, JavaScriptPromiseObject promise,
|
||||
ResultBuilder resultBuilder)
|
||||
{
|
||||
this.m_context = context;
|
||||
this.m_promise = promise;
|
||||
this.m_resultBuilder = resultBuilder;
|
||||
}
|
||||
|
||||
public Context context() {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
public JavaScriptPromiseObject promise() {
|
||||
return m_promise;
|
||||
}
|
||||
|
||||
public Thread thread() {
|
||||
return m_thread;
|
||||
}
|
||||
|
||||
public ResultBuilderContext builderContext() {
|
||||
return m_builderContext;
|
||||
}
|
||||
|
||||
public ResultBuilder resultBuilder() {
|
||||
return m_resultBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param executor
|
||||
* @param resultBuilder
|
||||
* @return
|
||||
*/
|
||||
public ExecutorInstance startWorker(Context context, Executor executor, ResultBuilder resultBuilder)
|
||||
{
|
||||
if (Thread.currentThread() != m_javaScriptThread) {
|
||||
throw new RuntimeException("You should call this function on JavaScriptThread");
|
||||
}
|
||||
if (context == null || executor == null || resultBuilder == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
JavaScriptPromiseObject promise = JavaScriptPromiseObject.create(context);
|
||||
|
||||
ExecutorInstance instance = new ExecutorInstance(context, promise, resultBuilder);
|
||||
class ExecutorRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.m_builderContext = executor.run();
|
||||
if (instance.m_builderContext == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
synchronized (m_endedInstances) {
|
||||
m_endedInstances.add(instance);
|
||||
}
|
||||
synchronized (m_activeInstances) {
|
||||
m_activeInstances.remove(instance);
|
||||
}
|
||||
m_workerThreadEndNotifier.notify(MultiThreadExecutor.this, instance);
|
||||
}
|
||||
}
|
||||
|
||||
Thread thread = new Thread(new ExecutorRunnable());
|
||||
instance.m_thread = thread;
|
||||
|
||||
synchronized (m_activeInstances) {
|
||||
m_activeInstances.add(instance);
|
||||
}
|
||||
|
||||
thread.start();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean hasPendingEvent()
|
||||
{
|
||||
synchronized (m_endedInstances) {
|
||||
return !m_endedInstances.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPendingWorker()
|
||||
{
|
||||
synchronized (m_activeInstances) {
|
||||
return !m_activeInstances.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPendingEventOrWorker()
|
||||
{
|
||||
return hasPendingWorker() || hasPendingEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* must call this function from main thread(JS thread)
|
||||
*/
|
||||
public void pumpEventsFromThreadIfNeeds(boolean executePendingJavaScriptJobs)
|
||||
{
|
||||
if (Thread.currentThread() != m_javaScriptThread) {
|
||||
throw new RuntimeException("You should call this function on JavaScriptThread");
|
||||
}
|
||||
|
||||
Object[] instances;
|
||||
synchronized (m_endedInstances) {
|
||||
instances = m_endedInstances.toArray();
|
||||
m_endedInstances.clear();
|
||||
}
|
||||
|
||||
for (int i = 0; i < instances.length; i ++) {
|
||||
ExecutorInstance e = (ExecutorInstance)instances[i];
|
||||
JavaScriptValue value = e.resultBuilder().build(e.context(), e.builderContext());
|
||||
if (e.builderContext().wasSuccessful()) {
|
||||
e.promise().fulfill(e.context(), value);
|
||||
} else {
|
||||
e.promise().reject(e.context(), value);
|
||||
}
|
||||
}
|
||||
|
||||
if (executePendingJavaScriptJobs) {
|
||||
m_vmInstance.executeEveryPendingJobIfExists();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* must call this function from main thread(JS thread)
|
||||
*/
|
||||
public void pumpEventsFromThreadIfNeeds()
|
||||
{
|
||||
pumpEventsFromThreadIfNeeds(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package androidx.test.ext.junit.runners;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class AndroidJUnit4 extends Runner {
|
||||
private Class testClass;
|
||||
public AndroidJUnit4(Class testClass) {
|
||||
super();
|
||||
this.testClass = testClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
return Description
|
||||
.createTestDescription(testClass, "AndroidJUnit4(mock) description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(RunNotifier notifier) {
|
||||
System.out.println("running the tests from AndroidJUnit4(mock): " + testClass);
|
||||
try {
|
||||
Object testObject = testClass.newInstance();
|
||||
for (Method method : testClass.getMethods()) {
|
||||
if (method.isAnnotationPresent(Test.class)) {
|
||||
notifier.fireTestStarted(Description
|
||||
.createTestDescription(testClass, method.getName()));
|
||||
method.invoke(testObject);
|
||||
notifier.fireTestFinished(Description
|
||||
.createTestDescription(testClass, method.getName()));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Enables namespacing of each library's R class so that its R class includes only the
|
||||
# resources declared in the library itself and none from the library's dependencies,
|
||||
# thereby reducing the size of the R class for that library
|
||||
android.nonTransitiveRClass=true
|
||||