update: added support for IMU and Lottie JSON
This commit is contained in:
8
components/thorvg-main/.gitattributes
vendored
Normal file
8
components/thorvg-main/.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Normalize EOL for all files that Git considers text files
|
||||
* text=auto eol=lf
|
||||
|
||||
# Except for bat files, which are Windows only files
|
||||
*.bat eol=crlf
|
||||
|
||||
# And some test files where the EOL matters
|
||||
*.json -text
|
||||
2
components/thorvg-main/.github/FUNDING.yml
vendored
Normal file
2
components/thorvg-main/.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
github: thorvg
|
||||
open_collective: thorvg
|
||||
55
components/thorvg-main/.github/labeler.yml
vendored
Normal file
55
components/thorvg-main/.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"APIs":
|
||||
- inc/**/*
|
||||
|
||||
"binding":
|
||||
- src/bindings/**/*
|
||||
|
||||
"documentation":
|
||||
- README.md
|
||||
|
||||
"font":
|
||||
- src/loaders/ttf/**/*
|
||||
|
||||
"image":
|
||||
- src/loaders/jpg/**/*
|
||||
- src/loaders/external_jpg/**/*
|
||||
- src/loaders/png/**/*
|
||||
- src/loaders/external_png/**/*
|
||||
- src/loaders/webp/**/*
|
||||
- src/loaders/external_webp/**/*
|
||||
- src/loaders/raw/**/*
|
||||
- src/savers/gif/**/*
|
||||
|
||||
"svg":
|
||||
- src/loaders/svg/**/*
|
||||
|
||||
"tvg":
|
||||
- src/loaders/tvg/**/*
|
||||
|
||||
"test":
|
||||
- test/**/*
|
||||
|
||||
"tools":
|
||||
- tools/**/*
|
||||
|
||||
"infrastructure":
|
||||
- .github/**/*
|
||||
- meson.build
|
||||
- meson_option.txt
|
||||
|
||||
"lottie":
|
||||
- src/loaders/lottie/**/*
|
||||
|
||||
"cpu":
|
||||
- src/renderer/sw_engine/**/*
|
||||
|
||||
"webgpu":
|
||||
- src/renderer/wg_engine/**/*
|
||||
|
||||
"gl":
|
||||
- src/renderer/gl_engine/**/*
|
||||
|
||||
"renderer":
|
||||
- src/renderer/*
|
||||
- src/common/**/*
|
||||
|
||||
73
components/thorvg-main/.github/workflows/build_android.yml
vendored
Normal file
73
components/thorvg-main/.github/workflows/build_android.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
name: Android
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build_x86_64:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: nttld/setup-ndk@v1.3.1
|
||||
id: setup-ndk
|
||||
with:
|
||||
submodules: true
|
||||
ndk-version: r21e
|
||||
local-cache: true
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install meson ninja-build libgles-dev
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
API: 21
|
||||
run: |
|
||||
sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_x86_64.txt > /tmp/android_cross.txt
|
||||
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false -Dextra="lottie_exp" --cross-file /tmp/android_cross.txt
|
||||
sudo ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_x86_64
|
||||
path: build/src/libthorvg*
|
||||
|
||||
build_aarch64:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: nttld/setup-ndk@v1.3.1
|
||||
id: setup-ndk
|
||||
with:
|
||||
submodules: true
|
||||
ndk-version: r21e
|
||||
local-cache: true
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install meson ninja-build libgles-dev
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
API: 21
|
||||
run: |
|
||||
sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_aarch64.txt > /tmp/android_cross.txt
|
||||
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false -Dextra="lottie_exp" --cross-file /tmp/android_cross.txt
|
||||
sudo ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_aarch64
|
||||
path: build/src/libthorvg*
|
||||
100
components/thorvg-main/.github/workflows/build_ios.yml
vendored
Normal file
100
components/thorvg-main/.github/workflows/build_ios.yml
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
name: iOS
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build_simulator_x86_64:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Unbreak Python in GitHub Actions
|
||||
run: |
|
||||
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
||||
sudo rm -rf /Library/Frameworks/Python.framework/
|
||||
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
export HOMEBREW_NO_INSTALL_FROM_API=1
|
||||
brew update
|
||||
brew install meson
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_simulator_x86_64.txt
|
||||
ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_simulator_x86_64
|
||||
path: build/src/libthorvg*
|
||||
|
||||
build_simulator_arm64:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Unbreak Python in GitHub Actions
|
||||
run: |
|
||||
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
||||
sudo rm -rf /Library/Frameworks/Python.framework/
|
||||
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
export HOMEBREW_NO_INSTALL_FROM_API=1
|
||||
brew update
|
||||
brew install meson
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_simulator_arm64.txt
|
||||
ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_simulator_arm64
|
||||
path: build/src/libthorvg*
|
||||
|
||||
build_arm64:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Unbreak Python in GitHub Actions
|
||||
run: |
|
||||
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
||||
sudo rm -rf /Library/Frameworks/Python.framework/
|
||||
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
export HOMEBREW_NO_INSTALL_FROM_API=1
|
||||
brew update
|
||||
brew install meson
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_arm64.txt
|
||||
ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_arm64
|
||||
path: build/src/libthorvg*
|
||||
88
components/thorvg-main/.github/workflows/build_macos.yml
vendored
Normal file
88
components/thorvg-main/.github/workflows/build_macos.yml
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
name: macOS
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Unbreak Python in GitHub Actions
|
||||
run: |
|
||||
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
||||
sudo rm -rf /Library/Frameworks/Python.framework/
|
||||
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
export HOMEBREW_NO_INSTALL_FROM_API=1
|
||||
brew update
|
||||
brew install meson sdl2
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all -Dextra="lottie_exp"
|
||||
ninja -C build install
|
||||
|
||||
compact_test:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Unbreak Python in GitHub Actions
|
||||
run: |
|
||||
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
||||
sudo rm -rf /Library/Frameworks/Python.framework/
|
||||
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install meson
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false -Dextra="lottie_exp"
|
||||
ninja -C build install
|
||||
|
||||
unit_test:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Unbreak Python in GitHub Actions
|
||||
run: |
|
||||
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
||||
sudo rm -rf /Library/Frameworks/Python.framework/
|
||||
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install meson
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true -Dextra="lottie_exp" --errorlogs
|
||||
ninja -C build install test
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: UnitTestReport
|
||||
path: build/meson-logs/testlog.txt
|
||||
92
components/thorvg-main/.github/workflows/build_ubuntu.yml
vendored
Normal file
92
components/thorvg-main/.github/workflows/build_ubuntu.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
name: Ubuntu
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install meson ninja-build libturbojpeg0-dev libpng-dev libwebp-dev libgles-dev libsdl2-dev
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all
|
||||
sudo ninja -C build install
|
||||
|
||||
compact_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install meson ninja-build libgles-dev
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false
|
||||
sudo ninja -C build install
|
||||
|
||||
unit_test:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install meson ninja-build libgtest-dev libasan5 valgrind curl jq software-properties-common libturbojpeg0-dev libpng-dev libwebp-dev libgles-dev
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dloaders="all" -Dengines="sw, gl" -Dsavers="all" -Dbindings="capi" -Dtests=true --errorlogs
|
||||
sudo ninja -C build install test
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: UnitTestReport
|
||||
path: build/meson-logs/testlog.txt
|
||||
|
||||
- name: Run memcheck Script(valgrind)
|
||||
run: |
|
||||
export PATH=$PATH:~/.local/bin/
|
||||
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh"
|
||||
"${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build & Run memcheck Script(ASAN)
|
||||
run: |
|
||||
sudo rm -rf ./build
|
||||
meson setup build -Db_sanitize="address,undefined" -Dloaders="all" -Dsavers="all" -Dtests="true" -Dbindings="capi"
|
||||
sudo ninja -C build install
|
||||
export PATH=$PATH:~/.local/bin/
|
||||
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_asan.sh"
|
||||
"${GITHUB_WORKSPACE}/.github/workflows/memcheck_asan.sh"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
77
components/thorvg-main/.github/workflows/build_windows.yml
vendored
Normal file
77
components/thorvg-main/.github/workflows/build_windows.yml
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
name: Windows
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/msvc-dev-cmd@v1
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
pip install meson ninja
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all
|
||||
where link
|
||||
ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_windows
|
||||
path: build/src/thorvg*
|
||||
|
||||
compact_test:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/msvc-dev-cmd@v1
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
pip install meson ninja
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false
|
||||
where link
|
||||
ninja -C build install
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: result_windows_static
|
||||
path: build/src/thorvg*
|
||||
|
||||
unit_test:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/msvc-dev-cmd@v1
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
pip install meson ninja
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true --errorlogs
|
||||
where link
|
||||
ninja -C build install test
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: UnitTestReport
|
||||
path: build/meson-logs/testlog.txt
|
||||
|
||||
44
components/thorvg-main/.github/workflows/memcheck_asan.sh
vendored
Normal file
44
components/thorvg-main/.github/workflows/memcheck_asan.sh
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z "$GITHUB_TOKEN" ]]; then
|
||||
echo "The GITHUB_TOKEN is required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
|
||||
echo "Run Address Sanitizer"
|
||||
echo "meson -Db_sanitize=\"address,undefined\" -Dloaders=\"all\" -Dsavers=\"all\" -Dtests=\"true\" -Dbindings=\"capi\" . build"
|
||||
pwd
|
||||
cd ${GITHUB_WORKSPACE}/build/test
|
||||
./tvgUnitTests > memcheck_asan.txt 2>&1
|
||||
|
||||
|
||||
PAYLOAD_MEMCHECK=`cat memcheck_asan.txt`
|
||||
COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
|
||||
|
||||
echo $COMMENTS_URL
|
||||
echo "MEMCHECK errors:"
|
||||
echo $PAYLOAD_MEMCHECK
|
||||
|
||||
if [[ $PAYLOAD_MEMCHECK == *"runtime error:"* || $PAYLOAD_MEMCHECK == *"ERROR: AddressSanitizer:"* ]]; then
|
||||
OUTPUT+=$'\n**MEMCHECK(ASAN) RESULT**:\n'
|
||||
|
||||
OUTPUT+=$'\n`meson -Db_sanitize="address,undefined" -Dloaders="all" -Dsavers="all" -Dtests="true" -Dbindings="capi" . build`\n'
|
||||
OUTPUT+=$'\n```\n'
|
||||
OUTPUT+="$PAYLOAD_MEMCHECK"
|
||||
OUTPUT+=$'\n```\n'
|
||||
|
||||
(
|
||||
echo '<details><summary>ASAN output</sumary>'
|
||||
echo
|
||||
echo "$OUTPUT"
|
||||
echo
|
||||
echo '</details>'
|
||||
) >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body')
|
||||
|
||||
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL"
|
||||
fi
|
||||
fi
|
||||
|
||||
45
components/thorvg-main/.github/workflows/memcheck_valgrind.sh
vendored
Normal file
45
components/thorvg-main/.github/workflows/memcheck_valgrind.sh
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z "$GITHUB_TOKEN" ]]; then
|
||||
echo "The GITHUB_TOKEN is required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
|
||||
echo "Run Valgrind"
|
||||
echo "valgrind --leak-check=yes ./tvgUnitTests"
|
||||
cd ./build/test
|
||||
|
||||
valgrind --leak-check=yes ./tvgUnitTests > memcheck_valgrind.txt 2>&1
|
||||
|
||||
|
||||
PAYLOAD_MEMCHECK=`cat memcheck_valgrind.txt`
|
||||
COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
|
||||
|
||||
echo $COMMENTS_URL
|
||||
echo "MEMCHECK errors:"
|
||||
echo $PAYLOAD_MEMCHECK
|
||||
|
||||
DEFINITELY_LOST_NUMBER=$(echo "$PAYLOAD_MEMCHECK" | grep -oP 'definitely lost:\s*\K[0-9]+(?=\s*bytes in)')
|
||||
ERROR_NUMBER=$(echo "$PAYLOAD_MEMCHECK" | grep -oP 'ERROR SUMMARY:\s*\K[0-9]+(?=\s*errors)')
|
||||
if [[ $ERROR_NUMBER != 0 || $DEFINITELY_LOST_NUMBER != 0 || $PAYLOAD_MEMCHECK == *"Invalid read "* || $PAYLOAD_MEMCHECK == *"Invalid write "* ]]; then
|
||||
OUTPUT+=$'\n**MEMCHECK(VALGRIND) RESULT**:\n'
|
||||
OUTPUT+=$'\n`valgrind --leak-check=yes ./tvgUnitTests`\n'
|
||||
OUTPUT+=$'\n```\n'
|
||||
OUTPUT+="$PAYLOAD_MEMCHECK"
|
||||
OUTPUT+=$'\n```\n'
|
||||
|
||||
(
|
||||
echo '<details><summary>Valgrind output</sumary>'
|
||||
echo
|
||||
echo "$OUTPUT"
|
||||
echo
|
||||
echo '</details>'
|
||||
) >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body')
|
||||
|
||||
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL"
|
||||
fi
|
||||
fi
|
||||
|
||||
13
components/thorvg-main/.github/workflows/pull_request_label.yml
vendored
Normal file
13
components/thorvg-main/.github/workflows/pull_request_label.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Pull Request Labeler
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
jobs:
|
||||
triage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/labeler@v4
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
sync-labels: true
|
||||
|
||||
192
components/thorvg-main/.github/workflows/regression.yml
vendored
Normal file
192
components/thorvg-main/.github/workflows/regression.yml
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
name: Regression
|
||||
|
||||
# on: [push, pull_request] - enable when testing
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install things
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y meson wget2 librsvg2-dev librsvg2-bin ninja-build git gcc-multilib g++-multilib earlyoom
|
||||
|
||||
- name: Compile Thorvg PR
|
||||
run: |
|
||||
meson . build -Dtools=svg2png,lottie2gif -Dsavers=gif -Db_sanitize=address,undefined
|
||||
sudo ninja -C build install
|
||||
|
||||
- name: Compile Thorvg Develop
|
||||
run: |
|
||||
git clone https://github.com/thorvg/thorvg.git thorvg_develop
|
||||
cd thorvg_develop
|
||||
meson . build -Dtools=svg2png
|
||||
sudo ninja -C build install
|
||||
cd ..
|
||||
|
||||
- name: Download SVG Regression finder and setup settings
|
||||
run: |
|
||||
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.4.0/svg_tester
|
||||
chmod +x ./svg_tester
|
||||
|
||||
- name: Prepare valid files to test
|
||||
run: |
|
||||
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgValidFiles.zip -O files.zip
|
||||
unzip -q files.zip
|
||||
rm files.zip
|
||||
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgNotValidFiles.zip -O files.zip
|
||||
unzip -q files.zip
|
||||
rm files.zip
|
||||
mv ThorvgValidFiles FilesToTest
|
||||
find ThorvgNotValidFiles -type f -exec mv {} FilesToTest \;
|
||||
rmdir ThorvgNotValidFiles
|
||||
|
||||
- name: Setup settings for crash/leak/timeout tests
|
||||
run: |
|
||||
mv test/regression/settings_crash_leak.toml settings.toml
|
||||
|
||||
- name: Run regression finder tests
|
||||
run: |
|
||||
./svg_tester 2>&1 | tee result_crashes.txt
|
||||
|
||||
- name: Setup settings for comparison tests
|
||||
run: |
|
||||
mv test/regression/settings_comparison.toml settings.toml
|
||||
|
||||
- name: Store Crashing/Leaking/Timing out Images
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: crashing-leaking-timeouting-images
|
||||
path: BrokenFILES
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Clean Data
|
||||
run: |
|
||||
rm -rf BrokenSVG || true
|
||||
rm -rf FilesToTest || true
|
||||
rm -rf ProblematicSVG || true
|
||||
rm -rf IgnoredSVG || true
|
||||
rm -rf BrokenFILES || true
|
||||
|
||||
# Test valid files
|
||||
- name: Prepare valid files to test
|
||||
run: |
|
||||
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgValidFiles.zip -O files.zip
|
||||
unzip -q files.zip
|
||||
rm files.zip
|
||||
mv ThorvgValidFiles FilesToTest
|
||||
|
||||
- name: Run regression finder tests
|
||||
run: |
|
||||
./svg_tester 2>&1 | tee result_valid_files.txt
|
||||
|
||||
- name: Store Broken Images for valid inputs
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: differences-in-valid-files
|
||||
path: BrokenSVG
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Store Problematic Images for valid inputs
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: problematic-images-in-valid-files
|
||||
path: ProblematicSVG
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Clean Data
|
||||
run: |
|
||||
rm -rf BrokenSVG || true
|
||||
rm -rf FilesToTest || true
|
||||
rm -rf ProblematicSVG || true
|
||||
rm -rf IgnoredSVG || true
|
||||
rm -rf BrokenFILES || true
|
||||
|
||||
# Test files that may not work currently good with Thorvg, errors from this are not critical
|
||||
# it is possible that this will find also some improvements
|
||||
- name: Prepare not valid to test
|
||||
run: |
|
||||
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgNotValidFiles.zip -O files.zip
|
||||
unzip -q files.zip
|
||||
rm files.zip
|
||||
mv ThorvgNotValidFiles FilesToTest
|
||||
|
||||
- name: Run invalid files tests
|
||||
run: |
|
||||
./svg_tester 2>&1 | tee result_not_valid_files.txt
|
||||
|
||||
- name: Store Broken Images for not valid inputs
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: differences-in-not-valid-files
|
||||
path: BrokenSVG
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Store Problematic Images for not valid inputs
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: problematic-images-in-not-valid-files
|
||||
path: ProblematicSVG
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Clean Data
|
||||
run: |
|
||||
rm -rf BrokenSVG || true
|
||||
rm -rf FilesToTest || true
|
||||
rm -rf ProblematicSVG || true
|
||||
rm -rf IgnoredSVG || true
|
||||
rm -rf BrokenFILES || true
|
||||
|
||||
- name: Test png reproducibility
|
||||
run: |
|
||||
wget -q https://github.com/thorvg/thorvg/files/11356766/AA_5.svg.zip -O files.zip
|
||||
unzip -q files.zip
|
||||
rm files.zip
|
||||
cp test/regression/check_same_image_size.py check_same_image_size.py
|
||||
# Forces to run tasks on different threads if possible, which should help find problem with data races
|
||||
taskset -c 0-15 python3 check_same_image_size.py AA_5.svg ./build/src/tools/svg2png/tvg-svg2png 100 500 2>&1 | tee result_image_size.txt
|
||||
|
||||
- name: Check results
|
||||
run: |
|
||||
export PATH=$PATH:~/.local/bin/
|
||||
python3 "${GITHUB_WORKSPACE}/.github/workflows/regression_check.py"
|
||||
|
||||
if [[ -f "fail_ci.txt" ]]; then
|
||||
(
|
||||
echo '```'
|
||||
cat "fail_ci.txt"
|
||||
echo '```'
|
||||
) >> "$GITHUB_STEP_SUMMARY"
|
||||
fi
|
||||
|
||||
- name: Find Comment
|
||||
uses: peter-evans/find-comment@v3
|
||||
id: fc
|
||||
with:
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
comment-author: 'github-actions[bot]'
|
||||
body-includes: Regression report
|
||||
|
||||
# TODO - not works
|
||||
# - name: Create or update comment
|
||||
# uses: peter-evans/create-or-update-comment@v4
|
||||
# with:
|
||||
# comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
# issue-number: ${{ github.event.pull_request.number }}
|
||||
# body-path: 'comment.txt'
|
||||
# edit-mode: replace
|
||||
|
||||
- name: Fail CI if regression found
|
||||
run: |
|
||||
if [[ -f "fail_ci.txt" ]]; then
|
||||
echo "Check Check results section for more details which tests failed"
|
||||
exit 1
|
||||
fi
|
||||
67
components/thorvg-main/.github/workflows/regression_check.py
vendored
Normal file
67
components/thorvg-main/.github/workflows/regression_check.py
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
from typing import Optional
|
||||
|
||||
POSSIBLE_PROBLEM = "POSSIBLE_PROBLEM - "
|
||||
|
||||
|
||||
def check_file(file_name: str) -> Optional[str]:
|
||||
with open(file_name, "r") as file:
|
||||
print(f"Checking file {file_name}")
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if line.startswith(POSSIBLE_PROBLEM):
|
||||
return line[len(POSSIBLE_PROBLEM) :]
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
data_to_check = [
|
||||
(
|
||||
"result_valid_files.txt",
|
||||
True,
|
||||
"Found difference in converting images that properly converted in develop branch.",
|
||||
),
|
||||
(
|
||||
"result_not_valid_files.txt",
|
||||
False,
|
||||
"Found differences in converting images that were not properly converted in develop branch(this may be improvement).",
|
||||
),
|
||||
(
|
||||
"result_image_size.txt",
|
||||
True,
|
||||
"Generated png have different size in each run.",
|
||||
),
|
||||
(
|
||||
"result_crashes.txt",
|
||||
True,
|
||||
"Found crashes in crashes during when converting svg to png.",
|
||||
),
|
||||
]
|
||||
|
||||
fail_ci = False
|
||||
comment = ""
|
||||
for file_name, fail_ci_when_triggered, new_comment in data_to_check:
|
||||
possible_problem = check_file(file_name)
|
||||
if possible_problem is not None:
|
||||
print(f">>>>> Found changes in {file_name} (look at CI steps from above)")
|
||||
print(f"Comment: {new_comment}")
|
||||
|
||||
if fail_ci_when_triggered:
|
||||
fail_ci = True
|
||||
comment += new_comment + "\n"
|
||||
|
||||
to_write = "Regression report:\n"
|
||||
|
||||
if len(comment) > 0:
|
||||
to_write += comment
|
||||
to_write += "\nCheck CI for artifacts/logs for more details."
|
||||
else:
|
||||
to_write += "Not found any changes(both improvements and regressions) in this PR with test data."
|
||||
|
||||
print("\n\n" + to_write + "\n\n")
|
||||
|
||||
with open("comment.txt", "w") as file:
|
||||
file.write(to_write)
|
||||
|
||||
if fail_ci:
|
||||
with open("fail_ci.txt", "w") as file:
|
||||
file.write("Fail")
|
||||
20
components/thorvg-main/.github/workflows/release.yml
vendored
Normal file
20
components/thorvg-main/.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Release
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: "thorvg"
|
||||
- name: Create source archive
|
||||
run: |
|
||||
rm -rf ./thorvg/.git*
|
||||
tar -I "gzip -9" -cf thorvg.tar.gz thorvg
|
||||
- name: Upload to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: thorvg.tar.gz
|
||||
10
components/thorvg-main/.gitignore
vendored
Normal file
10
components/thorvg-main/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
build
|
||||
builddir
|
||||
doc
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.tvg
|
||||
*.tmp
|
||||
*.code-workspace
|
||||
.DS_Store
|
||||
7
components/thorvg-main/CODEOWNERS
Normal file
7
components/thorvg-main/CODEOWNERS
Normal file
@@ -0,0 +1,7 @@
|
||||
# ThorVG uses the CODEOWNERS file to automatically assign designated reviewers within the GitHub system.
|
||||
# Being listed as a code owner does not necessarily indicate copyright ownership of the code.
|
||||
|
||||
* @hermet
|
||||
/src/renderer/gl_engine @wenjieshen @SergeyLebedkin
|
||||
/src/renderer/wg_engine @SergeyLebedkin
|
||||
/src/loaders/svg @JSUYA
|
||||
89
components/thorvg-main/CODE_OF_CONDUCT.md
Normal file
89
components/thorvg-main/CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We pledge to make our community welcoming, safe, and equitable for all.
|
||||
|
||||
We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant.
|
||||
|
||||
|
||||
## Encouraged Behaviors
|
||||
|
||||
While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language.
|
||||
|
||||
With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including:
|
||||
|
||||
1. Respecting the **purpose of our community**, our activities, and our ways of gathering.
|
||||
2. Engaging **kindly and honestly** with others.
|
||||
3. Respecting **different viewpoints** and experiences.
|
||||
4. **Taking responsibility** for our actions and contributions.
|
||||
5. Gracefully giving and accepting **constructive feedback**.
|
||||
6. Committing to **repairing harm** when it occurs.
|
||||
7. Behaving in other ways that promote and sustain the **well-being of our community**.
|
||||
|
||||
|
||||
## Restricted Behaviors
|
||||
|
||||
We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct.
|
||||
|
||||
1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop.
|
||||
2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people.
|
||||
3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits.
|
||||
4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community.
|
||||
5. **Violating confidentiality.** Sharing or acting on someone's personal or private information without their permission.
|
||||
6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group.
|
||||
7. Behaving in other ways that **threaten the well-being** of our community.
|
||||
|
||||
### Other Restrictions
|
||||
|
||||
1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions.
|
||||
2. **Failing to credit sources.** Not properly crediting the sources of content you contribute.
|
||||
3. **Promotional materials.** Sharing unsolicited commercial or marketing content unrelated to ThorVG or the topic of discussion.
|
||||
4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors.
|
||||
|
||||
|
||||
## Reporting an Issue
|
||||
|
||||
Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm.
|
||||
|
||||
When an incident does occur, it is important to report it promptly. To report a violation, please contact **thorvg@thorvg.org**.
|
||||
|
||||
ThorVG Maintainers take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. ThorVG Maintainers will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution.
|
||||
|
||||
|
||||
## Addressing and Repairing Harm
|
||||
|
||||
The following enforcement guidelines outline how ThorVG Maintainers may respond to reported violations of this Code of Conduct. The response may vary depending on the severity and impact of the situation.
|
||||
|
||||
If an investigation by the ThorVG Maintainers finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped.
|
||||
|
||||
1) Warning
|
||||
1) Event: A violation involving a single incident or series of incidents.
|
||||
2) Consequence: A private, written warning from the ThorVG Maintainers.
|
||||
3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations.
|
||||
2) Temporarily Limited Activities
|
||||
1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation.
|
||||
2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members.
|
||||
3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over.
|
||||
3) Temporary Suspension
|
||||
1) Event: A pattern of repeated violation which the ThorVG Maintainers have tried to address with warnings, or a single serious violation.
|
||||
2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions.
|
||||
3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted.
|
||||
4) Permanent Ban
|
||||
1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the ThorVG Maintainers determine there is no way to keep the community safe with this person as a member.
|
||||
2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior.
|
||||
3) Repair: There is no possible repair in cases of this severity.
|
||||
|
||||
This enforcement ladder is intended as a guideline. It does not limit the ability of ThorVG Maintainers to use their discretion and judgment, in keeping with the best interests of our community.
|
||||
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
||||
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
|
||||
|
||||
This Code of Conduct is distributed under the Creative Commons Attribution 4.0 International (CC-BY-4.0) license.
|
||||
97
components/thorvg-main/CONTRIBUTING.md
Normal file
97
components/thorvg-main/CONTRIBUTING.md
Normal file
@@ -0,0 +1,97 @@
|
||||
We always appreciate your contribution. ThorVG doesn't expect patches to be perfect; instead, we value contributions that make ThorVG better than before. This page outlines the ThorVG contribution format.<br />
|
||||
<br />
|
||||
|
||||
## Coding Convention
|
||||
Please read the [ThorVG Coding Convention Guidance](https://github.com/thorvg/thorvg/wiki/Coding-Convention) before writing your code.
|
||||
|
||||
## Reviewers
|
||||
ThorVG uses GitHub infrastructure to automatically assign code reviewers for your changes. To see the full list of reviewers, please refer to the [CODEOWNERS](https://github.com/thorvg/thorvg/blob/main/CODEOWNERS) file.
|
||||
<br />
|
||||
|
||||
## Self Test & Verification
|
||||
After updating the ThorVG code, please ensure your changes don't break the library. We recommend conducting unit tests. You can easily run them using the following build commands:
|
||||
<br/>
|
||||
`
|
||||
$meson setup build -Dtests=true -Dloaders="all" -Dsavers="all" -Dbindings="capi" -Dtools="all" -Dlog=true
|
||||
`
|
||||
<br />
|
||||
`
|
||||
$ninja -C build test
|
||||
`
|
||||
<br/>
|
||||
<br/>
|
||||
Please make it sure running all tests and no any fail case.<br/>
|
||||
<br/>
|
||||
Expected Fail: 0<br/>
|
||||
Fail: 0<br/>
|
||||
Unexpected Pass: 0<br/>
|
||||
Skipped: 0<br/>
|
||||
Timeout: 0<br/>
|
||||
|
||||
## Commit Message
|
||||
[Module][Feature]: [Title]
|
||||
|
||||
[Description]
|
||||
|
||||
- [Module] refers to the sub-module primarily affected by your change. Most of the time, this indicates the name of a sub-folder.
|
||||
This also suggests who might need to review your patch.
|
||||
If your change doesn't belong to any sub-modules, you can either replace this with a suitable name or skip it.
|
||||
The name should be written entirely in lowercase letters.
|
||||
- e.g., build, doc, infra, common, sw_engine, gl_engine, svg_loader, wasm, svg2png...
|
||||
|
||||
- [Feature] indicates the primary function or feature you modified. Typically, this represents a class or file name.
|
||||
This is an optional.
|
||||
- e.g., canvas, shape, paint, scene, picture, task-scheduler, loader, builder, ...
|
||||
|
||||
- [Title] provides a brief description of your change and should be encapsulated in a single sentence.
|
||||
- e.g., "Fixed a typo."
|
||||
- e.g., "Addressed compile warnings."
|
||||
- e.g., "Refactored code."
|
||||
- e.g., "Resolved a rendering bug causing overlapped shapes to display improperly."
|
||||
|
||||
- [Description] doesn't have a strict format. However, it should detail what you accomplished in this patch as comprehensively as possible.
|
||||
|
||||
If you've resolved bugs, include the following details:
|
||||
- The type of bug.
|
||||
- Steps to reproduce it.
|
||||
- The root cause.
|
||||
- The solution applied.
|
||||
|
||||
For new features or functions, cover:
|
||||
- The nature of the feature.
|
||||
- Full API specifications (if there are any API additions).
|
||||
- Its necessity or rationale.
|
||||
- Any conditions or restrictions.
|
||||
- Relevant examples or references.
|
||||
|
||||
Finally, include any related issue ticket numbers in this section, if applicable.
|
||||
|
||||
|
||||
Here's a sample commit message for clarity:
|
||||
|
||||
- renderer/paint: Introduced path clipping feature
|
||||
|
||||
We've added a new method, Paint::composite(), to support various composite behaviors. This allows paints to interact with other paint instances based on the chosen composite method. Initially, we're introducing the "ClipPath" method for path-based clipping.
|
||||
|
||||
targetPaint->composite(srcPaint, CompositeMethod::ClipPath);
|
||||
|
||||
Note: If the source paint lacks path information, clipping may not produce the desired effect.
|
||||
|
||||
API Additions:
|
||||
enum CompositeMethod {None = 0, ClipPath};
|
||||
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) const noexcept;
|
||||
|
||||
Examples: Introduced ClipPath
|
||||
|
||||
References: [Provide any relevant links, such as screenshots.]
|
||||
|
||||
Issues: [Link to the issue]
|
||||
|
||||
## Pull Request
|
||||
|
||||
Once you've submitted a pull request (PR), please ensure the following checklist is completed:
|
||||
- Reviewers: Check the Reviewers List.
|
||||
- Assignees: You should be assigned.
|
||||
- Labels: Mark the appropriate Patch Purpose.
|
||||
- Automated Integration Test: All must pass.
|
||||
<p align="center"><img width="1000" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/contribution.png"></p>
|
||||
59
components/thorvg-main/CONTRIBUTORS.md
Normal file
59
components/thorvg-main/CONTRIBUTORS.md
Normal file
@@ -0,0 +1,59 @@
|
||||
## Project Lead
|
||||
- Hermet Park <hermetpark@gmail.com>
|
||||
|
||||
## Core Contributors
|
||||
- Pranay Samanta <pranay.ks@samsung.com>
|
||||
- Junsu Choi <jsuya.choi@samsung.com>
|
||||
- Mira Grudzinska <veleveta@gmail.com>
|
||||
- Ruiwen Tang <tangruiwen1989@gmail.com>
|
||||
- Sergii Liebodkin <sergii@lottiefiles.com>
|
||||
- Jinny You <jinny@lottiefiles.com>
|
||||
- Jay WenJie <jay@lottiefiles.com>
|
||||
|
||||
## Contributors
|
||||
- Prudhvi Raj Vasireddi <prudhvi.raj@samsung.com>
|
||||
- Mateusz Palkowski <m.palkowski@samsung.com>
|
||||
- Subhransu Mohanty <sub.mohanty@samsung.com>
|
||||
- Michal Szczecinski <m.szczecinsk@partner.samsung.com>
|
||||
- Shinwoo Kim <cinoo.kim@samsung.com>
|
||||
- Piotr Kalota <p.kalota@samsung.com>
|
||||
- Vincent Torri <vincent.torri@gmail.com>
|
||||
- Pankaj Kumar <pankaj.m1@samsung.com>
|
||||
- Patryk Kaczmarek <patryk.k@partner.samsung.com>
|
||||
- Michal Maciola <m.maciola@samsung.com>
|
||||
- Peter Vullings <peter@projectitis.com>
|
||||
- K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>
|
||||
- Rémi Verschelde <rverschelde@gmail.com>
|
||||
- Martin Liska <mliksa@suse.cz>
|
||||
- Vincenzo Pupillo <vincenzo.pupillo@unimi.it>
|
||||
- EunSik Jeong <rinechran@outlook.jp>
|
||||
- Rafał Mikrut <mikrutrafal@protonmail.com>
|
||||
- Martin Capitanio <capnm@capitanio.org>
|
||||
- YouJin Lee <ol-of@naver.com>
|
||||
- Nattu Adnan <nattu@reallynattu.com>
|
||||
- Gabor Kiss-Vamosi <kisvegabor@gmail.com>
|
||||
- Lorcán Mc Donagh <lorcan@lmdsp.com>
|
||||
- Lucas Niu <hoiyu3twon9@gmail.com>
|
||||
- Francisco Ramírez <franchuti688@gmail.com>
|
||||
- Abdelrahman Ashraf <a.theashraf@gmail.com>
|
||||
- Neo Xu <neo.xu1990@gmail.com>
|
||||
- Thaddeus Crews <repiteo@outlook.com>
|
||||
- Josh Soref <jsoref@gmail.com>
|
||||
- Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
- Łukasz Pomietło <oficjalnyadreslukasza@gmail.com>
|
||||
- Kelly Loh <kelly@lottiefiles.com>
|
||||
- Dragoș Tiselice <dragos@lottiefiles.com>
|
||||
- Marcin Baszczewski <marcin@baszczewski.pl>
|
||||
- Fabian Blatz <fabianblatz@gmail.com>
|
||||
- Jakub Marcowski <chubercikbattle@gmail.com>
|
||||
- Benjamin Halko <benjaminhalko@hotmail.com>
|
||||
- Benson Muite <benson_muite@emailplus.com>
|
||||
- kkocdko <kkocdko@gmail.com>
|
||||
- SoonGeon Noh <nors.nsg@gmail.com>
|
||||
- Giseong Ji <jiggyjiggy0323@gmail.com>
|
||||
- KunYoung Park <rjsdud3263@gmail.com>
|
||||
- Wang SiMiao 王思淼 <wangsimiao1@xiaomi.com>
|
||||
- Jackson Hu <huming2207@gmail.com>
|
||||
- Andy French <andyf@canva.com>
|
||||
- Andreas Deininger <andreas@deininger.net>
|
||||
- Jonathan Liu <net147@gmail.com>
|
||||
21
components/thorvg-main/LICENSE
Normal file
21
components/thorvg-main/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 - 2026 ThorVG Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
675
components/thorvg-main/README.md
Normal file
675
components/thorvg-main/README.md
Normal file
@@ -0,0 +1,675 @@
|
||||
[](https://insights.linuxfoundation.org/project/thorvg)
|
||||
[](https://www.codefactor.io/repository/github/hermet/thorvg)
|
||||

|
||||
[](LICENSE)
|
||||
[](https://en.wikipedia.org/wiki/Thor_Vector_Graphics)
|
||||
[](https://deepwiki.com/thorvg/thorvg)
|
||||
[](https://discord.gg/n25xj6J6HM)
|
||||
[](https://opencollective.com/thorvg)
|
||||
<br>
|
||||
[](https://github.com/thorvg/thorvg/actions/workflows/build_ubuntu.yml)
|
||||
[](https://github.com/thorvg/thorvg/actions/workflows/build_windows.yml)
|
||||
[](https://github.com/thorvg/thorvg/actions/workflows/build_macos.yml)
|
||||
[](https://github.com/thorvg/thorvg/actions/workflows/build_ios.yml)
|
||||
[](https://github.com/thorvg/thorvg/actions/workflows/build_android.yml)
|
||||
<br>
|
||||
[](https://github.com/thorvg/thorvg/releases/latest)
|
||||
[](https://vcpkg.link/ports/thorvg)
|
||||
[](https://aur.archlinux.org/packages/thorvg)
|
||||
[](https://conan.io/center/recipes/thorvg)
|
||||
[](https://src.fedoraproject.org/rpms/thorvg)
|
||||
[](https://packages.msys2.org/packages/mingw-w64-x86_64-thorvg?repo=mingw64)
|
||||
[](https://www.npmjs.com/package/@thorvg/lottie-player)
|
||||
[](https://pub.dev/packages/thorvg)
|
||||
[](https://nimble.directory/pkg/thorvg)
|
||||
[](https://code.dlang.org/packages/bindbc-thorvg)
|
||||
[](https://formulae.brew.sh/formula/thorvg)
|
||||
<br>
|
||||
|
||||
# ThorVG
|
||||
<p align="center">
|
||||
<img width="800" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/logo/512/thorvg-banner.png">
|
||||
</p>
|
||||
|
||||
**Thor Vector Graphics** is an **open-source** graphics library designed for creating **vector-based scenes and animations**. It combines **high performance** with **lightweight efficiency**, as Thor embodies a dual meaning—_symbolizing both immense strength and lightning-fast agility_. Embracing the philosophy of _simplicity leads to reliability_, the ThorVG project provides **intuitive, user-friendly interfaces** while maintaining a **compact footprint** and **minimal overhead**. <br />
|
||||
<br />
|
||||
The following primitives are supported by ThorVG: <br />
|
||||
|
||||
- **Lines & Shapes**: rectangles, circles, and paths with coordinate control
|
||||
- **Filling**: solid colors, linear & radial gradients, and path clipping
|
||||
- **Stroking**: stroke width, joins, caps, dash patterns, and trimming
|
||||
- **Scene Management**: retainable scene graph and object transformations
|
||||
- **Composition**: various blending and masking
|
||||
- **Text**: unicode characters with horizontal multi-line text layout using scalable fonts (TTF)
|
||||
- **Images**: SVG, JPG, PNG, WebP, and raw bitmaps
|
||||
- **Effects**: blur, drop shadow, fill, tint, tritone and color replacement
|
||||
- **Animations**: Lottie
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_primitives.png">
|
||||
</p>
|
||||
|
||||
### Lightweight Design
|
||||
ThorVG is designed for a wide range of programs, offering adaptability for integration and use in various applications and systems. It achieves this through a single binary with selectively buildable, modular components in a building block style. This ensures both optimal size and easy maintenance. <br />
|
||||
|
||||
<p align="center">
|
||||
<img width="750" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_structure.png">
|
||||
</p>
|
||||
|
||||
The core library of ThorVG maintains a binary size of approximately **150KB**. This is significantly smaller compared to graphics engines designed primarily for desktop environments and offers the following advantages.<br />
|
||||
|
||||
- **Memory Efficiency**: Thanks to its low runtime memory usage, ThorVG operates stably even on low-spec systems.
|
||||
- **Fast Boot**: The library loads and initializes quickly, improving the overall startup speed of applications.
|
||||
- **Low Size Deployment:** With its small code and resource footprint, ThorVG is well-suited for embedded systems, IoT devices, and network-constrained environments.
|
||||
|
||||
### Broad Portability
|
||||
ThorVG is based on the **C++** standard and provides consistent functionality across various platforms through an abstraction layer that minimizes dependence on specific operating systems or hardware. <br />
|
||||
|
||||
- **Extensive Platform Support**: ThorVG supports web platforms, desktop operating systems such as Windows, macOS, and Linux, mobile platforms including Android and iOS, as well as embedded systems like Tizen and RTOS-based environments.
|
||||
- **Microcontroller Support**: ThorVG has been shown to run on microcontrollers like the ESP32, demonstrating its efficiency even within environments with highly limited memory and storage.
|
||||
- **Headless Rendering Support**: ThorVG can perform rendering without a display server, enabling use cases such as server-side graphics processing or offline rendering tools.
|
||||
|
||||
If your program includes the main renderer, you can seamlessly utilize ThorVG APIs by transitioning drawing contexts between the main renderer and ThorVG. Throughout these API calls, ThorVG effectively serializes drawing commands among volatile paint nodes. Subsequently, it undertakes synchronous or asynchronous rendering via its render-backend engines. Additionally, ThorVG is adept at handling vector images, including formats like SVG and Lottie, and it remains adaptable for accommodating additional popular formats as needed. In the rendering process, the library may generate intermediate frame buffers for scene compositing, though only when essential. The accompanying diagram provides a concise overview of how to effectively incorporate ThorVG within your system.<br />
|
||||
|
||||
<p align="center">
|
||||
<img width="900" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_flow.png">
|
||||
</p>
|
||||
|
||||
### CPU Rasterization
|
||||
ThorVG is optimized for CPU-based rasterization, with a strong focus on vector rendering in environments where GPU resources are limited, unavailable, or intentionally avoided. In representative CPU benchmarks, ThorVG demonstrates **an average of ~1.8× faster performance** to a widely-used vector graphics engine across common vector rendering workloads. The advantage is particularly clear in geometry-heavy scenarios such as rectangles, strokes, rotations, and circle rendering.
|
||||
|
||||
#### Performance Overview
|
||||
<p align="center">
|
||||
<img width="1900" height="auto" alt="image" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_performance.png">
|
||||
</p>
|
||||
|
||||
#### Test Conditions
|
||||
- Tested with 5k semi-transparent primitives, including shapes, strokes, and images, using alpha blending.
|
||||
- Image filtering was performed using bilinear interpolation.
|
||||
- Test Platform: Apple M1 (macOS 15)
|
||||
- Render size: 2560 × 1440 (2K) for each test case
|
||||
- Versions: ThorVG v1.0.0, Skia v144
|
||||
|
||||
<p align="center">
|
||||
<img width="800" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_stress.png">
|
||||
</p>
|
||||
|
||||
### Threading
|
||||
ThorVG incorporates a threading mechanism designed to seamlessly retrieve upcoming scenes without unnecessary delays. It utilizes a finely-tuned task scheduler based on thread pools to handle a variety of tasks, including encoding, decoding, updating, and rendering. This architecture ensures efficient use of multi-core processing.<br />
|
||||
<br />
|
||||
The task scheduler is carefully designed to abstract complexity, simplify integration, and enhance user convenience. Its use is optional, allowing users to adopt it based on their specific needs.<br />
|
||||
|
||||
<p align="center">
|
||||
<img width="900" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_thread.png">
|
||||
</p>
|
||||
|
||||
### Smart Rendering
|
||||
ThorVG supports smart partial rendering, which enables more efficient rendering workflows by updating only the portions of a vector scene that have changed. By internally tracking modified regions, it minimizes unnecessary redraws and optimizes overall performance. This feature provides significant benefits in scenarios such as UI rendering, design tools, or applications where large parts of the scene remain static and only small elements update between frames. In such cases, avoiding full-scene rendering can greatly reduce computational workload and improve energy efficiency—making it particularly valuable on mobile and embedded systems.<br/>
|
||||
<br/>
|
||||
The following figure illustrates the geometry changes and highlights the minimal redraw region (outlined in red) that needs to be updated. Only the modified area between the previous and current frames is selectively redrawn, significantly improving performance.</br>
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_partial.png">
|
||||
</p>
|
||||
|
||||
Please note that in highly dynamic content—such as fast-paced games or full-screen animations where nearly all objects change every frame—partial rendering provides little to no benefit and may even introduce minor overhead. In these scenarios, full-scene rendering is typically the better choice. For a practical showcase, visit [this page](https://hermet.github.io/partial-test/) demonstrating a performance comparison of partial rendering using ThorVG's software renderer.<br />
|
||||
|
||||
### Render Backends
|
||||
Today, ThorVG provides its own implementation of multiple render-backend engines, allowing you to choose the one that best suits your app and system preferences.
|
||||
<br/>
|
||||
|
||||
- CPU/SIMD (Software)
|
||||
- OpenGL/ES
|
||||
- WebGL
|
||||
- WebGPU
|
||||
|
||||
ThorVG is particularly ahead of the curve in the web ecosystem. WebGPU introduces next-generation graphics APIs comparable to Vulkan, offering access to compute shaders and low-overhead GPU control. This enables more aggressive optimization strategies and broader application potential. On top of this, ThorVG fully supports all of its vector rendering features within the WebGPU backend, ensuring a complete and consistent experience across platforms.
|
||||
|
||||
Furthermore, by abstracting underlying hardware graphics APIs such as Metal, Vulkan, and DirectX, ThorVG guarantees seamless integration across a wide range of systems, regardless of the specific hardware accelerations available.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_webgpu.png">
|
||||
|
||||
### Supported Platforms
|
||||
ThorVG is designed to be portable across a wide range of devices, including small IoT devices, embedded systems, mobile platforms, game consoles, desktop environments, and the web. It is actively under development, with continuous efforts to expand support for essential platforms as needed. Currently, the major supported platforms include:<br />
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_platforms.png">
|
||||
</p>
|
||||
|
||||
## Contents
|
||||
- [ThorVG](#thorvg)
|
||||
- [Installation](#installation)
|
||||
- [Build and Install](#build-and-install)
|
||||
- [Build with Visual Studio](#build-with-visual-studio)
|
||||
- [Build with Xcode](#build-with-xcode)
|
||||
- [Quick Start](#quick-start)
|
||||
- [SVG](#svg)
|
||||
- [Lottie](#lottie)
|
||||
- [In Practice](#in-practice)
|
||||
- [Canva iOS](#canva-ios)
|
||||
- [dotLottie](#dotlottie)
|
||||
- [Espressif](#espressif)
|
||||
- [Flux Audio](#flux-audio)
|
||||
- [Godot](#godot)
|
||||
- [Lottie Creator](#lottie-creator)
|
||||
- [LVGL](#lvgl)
|
||||
- [Segger](#segger)
|
||||
- [TinyPiXOS](#tinypixos)
|
||||
- [Tizen](#tizen)
|
||||
- [Interactive App](#interactive-app)
|
||||
- [Examples](#examples)
|
||||
- [Tools](#tools)
|
||||
- [ThorVG Viewer](#thorvg-viewer)
|
||||
- [Lottie to GIF](#lottie-to-gif)
|
||||
- [SVG to PNG](#svg-to-png)
|
||||
- [Related Projects](#related-projects)
|
||||
- [API Bindings](#api-bindings)
|
||||
- [Documentation](#documentation)
|
||||
- [References](#references)
|
||||
- [Dependencies](#dependencies)
|
||||
- [Contributors](#contributors)
|
||||
- [Partners](#partners)
|
||||
- [Sponsors](#sponsors)
|
||||
- [Communication](#communication)
|
||||
|
||||
[](#contents)
|
||||
<br />
|
||||
## Installation
|
||||
This section details the steps required to configure the environment for installing ThorVG.<br />
|
||||
<br />
|
||||
### Build and Install
|
||||
ThorVG supports [meson](https://mesonbuild.com/) build system. Install [meson](http://mesonbuild.com/Getting-meson.html) and [ninja](https://ninja-build.org/) if you don't have them already.
|
||||
|
||||
Run meson to configure ThorVG in the thorvg root folder.
|
||||
```
|
||||
meson setup builddir
|
||||
```
|
||||
Run ninja to build & install ThorVG:
|
||||
```
|
||||
ninja -C builddir install
|
||||
```
|
||||
|
||||
Regardless of the installation, all build results (symbols, executable) are generated in the builddir folder in thorvg. Some results such as examples won't be installed, you can check More examples section to see how to change it. <br/>
|
||||
<br/>
|
||||
Note that some systems might include ThorVG package as a default component. In that case, you can skip this manual installation.</br>
|
||||
|
||||
### Build with Visual Studio
|
||||
If you want to create Visual Studio project files, use the command `--backend=vs`. The resulting solution file `thorvg.sln` will be located in the build folder.
|
||||
```
|
||||
meson setup builddir --backend=vs
|
||||
```
|
||||
|
||||
### Build with Xcode
|
||||
If you want to create Xcode project files, use the command `--backend=xcode`. The resulting solution file `thorvg.xcodeproj` will be located in the build folder.
|
||||
```
|
||||
meson setup builddir --backend=xcode
|
||||
```
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Quick Start
|
||||
ThorVG renders vector shapes to a given canvas buffer. The following is a quick start to show you how to use the essential APIs.
|
||||
|
||||
First, you should initialize the ThorVG engine:
|
||||
|
||||
```cpp
|
||||
tvg::Initializer::init(4); //4 threads
|
||||
```
|
||||
|
||||
Then it would be best if you prepared an empty canvas for drawing on it:
|
||||
|
||||
```cpp
|
||||
static uint32_t buffer[WIDTH * HEIGHT]; //canvas target buffer
|
||||
|
||||
auto canvas = tvg::SwCanvas::gen(); //generate a canvas
|
||||
canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::ColorSpace::ARGB8888); //buffer, stride, w, h, Colorspace
|
||||
```
|
||||
|
||||
Next you can draw multiple shapes on the canvas:
|
||||
|
||||
```cpp
|
||||
auto rect = tvg::Shape::gen(); //generate a shape
|
||||
rect->appendRect(50, 50, 200, 200, 20, 20); //define it as a rounded rectangle (x, y, w, h, rx, ry)
|
||||
rect->fill(100, 100, 100); //set its color (r, g, b)
|
||||
canvas->add(rect); //add the rectangle to the canvas
|
||||
|
||||
auto circle = tvg::Shape::gen(); //generate a shape
|
||||
circle->appendCircle(400, 400, 100, 100); //define it as a circle (cx, cy, rx, ry)
|
||||
|
||||
auto fill = tvg::RadialGradient::gen(); //generate a radial gradient
|
||||
fill->radial(400, 400, 150); //set the radial gradient geometry info (cx, cy, radius)
|
||||
|
||||
tvg::Fill::ColorStop colorStops[2]; //gradient colors
|
||||
colorStops[0] = {0.0, 255, 255, 255, 255}; //1st color values (offset, r, g, b, a)
|
||||
colorStops[1] = {1.0, 0, 0, 0, 255}; //2nd color values (offset, r, g, b, a)
|
||||
fill->colorStops(colorStops, 2); //set the gradient colors info
|
||||
|
||||
circle->fill(fill); //set the circle fill
|
||||
canvas->add(circle); //add the circle to the canvas
|
||||
|
||||
```
|
||||
|
||||
This code generates the following result:
|
||||
|
||||
<p align="center">
|
||||
<img width="416" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_shapes.png">
|
||||
</p>
|
||||
|
||||
You can also draw you own shapes and use dashed stroking:
|
||||
|
||||
```cpp
|
||||
auto path = tvg::Shape::gen(); //generate a path
|
||||
path->moveTo(199, 34); //set sequential path coordinates
|
||||
path->lineTo(253, 143);
|
||||
path->lineTo(374, 160);
|
||||
path->lineTo(287, 244);
|
||||
path->lineTo(307, 365);
|
||||
path->lineTo(199, 309);
|
||||
path->lineTo(97, 365);
|
||||
path->lineTo(112, 245);
|
||||
path->lineTo(26, 161);
|
||||
path->lineTo(146, 143);
|
||||
path->close();
|
||||
|
||||
path->fill(150, 150, 255); //path color
|
||||
|
||||
path->strokeWidth(3); //stroke width
|
||||
path->strokeFill(0, 0, 255); //stroke color
|
||||
path->strokeJoin(tvg::StrokeJoin::Round); //stroke join style
|
||||
path->strokeCap(tvg::StrokeCap::Round); //stroke cap style
|
||||
|
||||
float pattern[2] = {10, 10}; //stroke dash pattern (line, gap)
|
||||
path->strokeDash(pattern, 2); //set the stroke pattern
|
||||
|
||||
canvas->add(path); //add the path to the canvas
|
||||
|
||||
```
|
||||
|
||||
The code generates the following result:
|
||||
|
||||
<p align="center">
|
||||
<img width="300" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_path.png">
|
||||
</p>
|
||||
|
||||
Now begin rendering & finish it at a particular time:
|
||||
|
||||
```cpp
|
||||
canvas->draw();
|
||||
canvas->sync();
|
||||
```
|
||||
|
||||
Then you can acquire the rendered image from the buffer memory.
|
||||
|
||||
Lastly, terminate the engine after its usage:
|
||||
|
||||
```cpp
|
||||
tvg::Initializer::term();
|
||||
```
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## SVG
|
||||
|
||||
ThorVG facilitates [SVG Tiny Specification](https://www.w3.org/TR/SVGTiny12/) rendering via its dedicated SVG interpreter. Adhering to the SVG Tiny Specification, the implementation maintains a lightweight profile, rendering it particularly advantageous for embedded systems. While ThorVG comprehensively adheres to [most of the SVG Tiny specs](https://github.com/thorvg/thorvg/wiki/SVG-Support), certain features remain unsupported within the current framework. These include:</br>
|
||||
|
||||
- Animation
|
||||
- Interactivity
|
||||
- Multimedia
|
||||
|
||||
The figure below highlights ThorVG's SVG rendering capabilities:
|
||||
|
||||
<p align="center">
|
||||
<img width="780" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_svg.jpg">
|
||||
</p>
|
||||
|
||||
The following code snippet shows how to draw SVG image using ThorVG:
|
||||
|
||||
```cpp
|
||||
auto picture = tvg::Picture::gen(); //generate a picture
|
||||
picture->load("tiger.svg"); //load a SVG file
|
||||
canvas->add(picture); //add the picture to the canvas
|
||||
```
|
||||
|
||||
The result is:
|
||||
|
||||
<p align="center">
|
||||
<img width="300" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_tiger.png">
|
||||
</p>
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Lottie
|
||||
|
||||
ThorVG supports the most powerful [Lottie Animation features](https://github.com/thorvg/thorvg/wiki/Lottie-Support). Lottie is an industry standard, JSON-based vector animation file format that enables seamless distribution of animations on any platform, akin to shipping static assets. These files are compact and compatible with various devices, scaling up or down without pixelation. With Lottie, you can easily create, edit, test, collaborate, and distribute animations in a user-friendly manner. For more information, please visit [Lottie Animation Community](https://lottie.github.io/)' website. <br />
|
||||
<br />
|
||||
ThorVG offers great flexibility in building its binary. Besides serving as a general graphics engine, it can be configured as a compact Lottie animation playback library with specific build options:
|
||||
|
||||
```
|
||||
$meson setup builddir -Dloaders="lottie"
|
||||
```
|
||||
|
||||
Alternatively, to support additional bitmap image formats:
|
||||
|
||||
```
|
||||
$meson setup builddir -Dloaders="lottie, png, jpg, webp"
|
||||
```
|
||||
|
||||
Please note that ThorVG supports Lottie Expressions by default. Lottie Expressions are small JavaScript code snippets that can be applied to animated properties in your Lottie animations, evaluating to a single value. This is an advanced feature in the Lottie specification and may impact binary size and performance, especially when targeting small devices such as MCUs. If this feature is not essential for your requirements, you can disable it using the `extra` build option in ThorVG:
|
||||
|
||||
```
|
||||
$meson setup builddir -Dloaders="lottie" -Dextra=""
|
||||
```
|
||||
|
||||
The following code snippet demonstrates how to use ThorVG to play a Lottie animation.
|
||||
|
||||
```cpp
|
||||
auto animation = tvg::Animation::gen(); //generate an animation
|
||||
auto picture = animation->picture() //acquire a picture which associated with the animation.
|
||||
picture->load("lottie.json"); //load a Lottie file
|
||||
auto duration = animation->duration(); //figure out the animation duration time in seconds.
|
||||
canvas->add(picture); //add the picture to the canvas
|
||||
```
|
||||
First, an animation and a picture are generated. The Lottie file (lottie.json) is loaded into the picture, and then the picture is added to the canvas. The animation frames are controlled using the animation object to play the Lottie animation. Also you might want to know the animation duration time to run your animation loop.
|
||||
```cpp
|
||||
animation->frame(animation->totalFrame() * progress); //Set a current animation frame to display
|
||||
canvas->update(animation->picture()); //Update the picture to be redrawn.
|
||||
```
|
||||
Let's suppose the progress variable determines the position of the animation, ranging from 0 to 1 based on the total duration time of the animation. Adjusting the progress value allows you to control the animation at the desired position. Afterwards, the canvas is updated to redraw the picture with the updated animation frame.<br />
|
||||
<br />
|
||||
<p align="center">
|
||||
<img width="600" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_lottie.gif">
|
||||
</p>
|
||||
|
||||
Please check out the [ThorVG Test App](https://thorvg-perf-test.vercel.app/) to see the performance of various Lottie animations powered by ThorVG. If you're working on the frontend, you can also download the ThorVG npm package [here](https://www.npmjs.com/package/@thorvg/lottie-player).</br>
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## In Practice
|
||||
### Canva iOS
|
||||
[Canva](https://www.canva.com), is a popular visual communication platform used by millions worldwide. Known for its intuitive interface and rich design resources, Canva empowers users to create high-quality visual content easily. The iOS app switched from its previous Lottie engine to ThorVG, achieving around 80% faster rendering and 70% lower peak memory usage.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_canvaios.png">
|
||||
</p>
|
||||
|
||||
### dotLottie
|
||||
[dotLottie](https://dotlottie.io/) is an open-source format that combines multiple Lottie animations, assets like images and fonts, and supports features such as state machines and interactivity. It uses ZIP compression (.lottie extension) for easy and efficient distribution. As a superset of Lottie, the [dotLottie player](https://github.com/LottieFiles/dotlottie-rs) now runs on ThorVG for rendering.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_dotlottie.png">
|
||||
</p>
|
||||
|
||||
### Espressif
|
||||
[Espressif Systems](https://www.espressif.com/en) provides [ThorVG as an official component](https://docs.espressif.com/projects/esp-iot-solution/en/latest/display/lcd/gui_solution.html#thorvg-component) within its ESP-IDF (IoT Development Framework), simplifying integration into ESP-IDF projects. This allows developers to easily incorporate ThorVG's rendering capabilities into their applications, particularly on IoT devices powered by Espressif’s ESP32 and ESP32-P4 microcontrollers.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_espressif.png">
|
||||
</p>
|
||||
|
||||
### Flux Audio
|
||||
[Flux Audio](https://www.flux.audio/) is a high-performance audio company focused on premium sound and immersive experiences. They use advanced software for consistent audio processing across devices. ThorVG powers their UI with fast, scalable vector rendering, highlighting its flexibility in modern audio platforms.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_flux.jpg">
|
||||
</p>
|
||||
|
||||
### Godot
|
||||
ThorVG is integrated into the Godot game engine to support sleek, high-quality vector-based user interfaces and assets. [Godot](https://www.godotengine.org) is a modern, open-source game engine with a full suite of tools, allowing developers to focus on creating games without reinventing core functionality.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_godot.png">
|
||||
</p>
|
||||
|
||||
### Lottie Creator
|
||||
|
||||
[Lottie Creator](https://creator.lottiefiles.com/) is designed to create ultra-lightweight, highly customizable and interactive animations for web, apps and social. Supercharged with AI-based Motion Copilot. ThorVG is powering the Canvas engine behind Lottie Creator — enabling fast and scalable vector graphics rendering across platforms.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_creator.png">
|
||||
</p>
|
||||
|
||||
### LVGL
|
||||
[LVGL](https://lvgl.io/) is an open-source graphics library specifically designed for embedded systems with limited resources. It is lightweight and highly customizable, providing support for graphical user interfaces (GUIs) on microcontrollers, IoT devices, and other embedded platforms. ThorVG serves as the vector drawing primitives library in the LVGL framework.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_lvgl.png">
|
||||
</p>
|
||||
|
||||
### Segger
|
||||
[SEGGER](https://www.segger.com/) Microcontroller provides products for developing and manufacturing embedded systems, including real-time operating systems (RTOS), middleware libraries, debugging and trace probes, and programming tools. [It has adopted ThorVG](https://doc.segger.com/UM03001_emWin.html#GUI_GPU_ThorVG_ThorVG_driver) as a GPU driver to enable high-performance vector rendering for its GUI apps.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_segger.png">
|
||||
</p>
|
||||
|
||||
### TinyPiXOS
|
||||
[TinyPiXOS](https://www.tinypixos.com/en/) is a lightweight, open-source Linux OS that replaces X11/Wayland with a custom C/C++ graphics stack. It includes minimal window management and GUI tools, all optimized for low resource use. ThorVG handles core GUI rendering, delivering efficient performance and high visual quality in constrained environments.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_tinypixos.png">
|
||||
</p>
|
||||
|
||||
### Tizen
|
||||
ThorVG has been integrated into the [Tizen](https://www.tizen.org) platform as the vector graphics engine. [NUI](https://docs.tizen.org/application/dotnet/guides/user-interface/nui/overview/) is the name of Tizen UI framework which is written in C#. ThorVG is the backend engine of the [NUI Vector Graphics](https://docs.tizen.org/application/dotnet/guides/user-interface/nui/vectorgraphics/Overview/) which is used for vector primitive drawings and scalable image contents such as SVG and Lottie Animation among the Tizen applications.
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/example_tizen.png">
|
||||
</p>
|
||||
</br>
|
||||
|
||||
Would you like us to showcase your project with ThorVG? Feel free to [open an issue](https://github.com/thorvg/thorvg/issues) or submit a pull request!
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Interactive App
|
||||
Check out [Thor Janitor](https://github.com/thorvg/thorvg.janitor), an interactive demo game fully rendered using ThorVG. It renders tens of thousands of objects in real-time with effects like DropShadow and Blur, running stably at 120+ FPS!
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/user-attachments/assets/8a4bd16a-bb72-4b41-b007-eadc2220d1eb"/>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<strong><a href="https://youtu.be/jdnnzmtHy9k">Watch the full video!</a></strong>
|
||||
</p>
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Examples
|
||||
There are plenty of sample code in [thorvg.example](https://github.com/thorvg/thorvg.example) to help you in understanding the ThorVG APIs.
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Tools
|
||||
### ThorVG Viewer
|
||||
ThorVG provides a resource verification tool for the ThorVG engine. The [ThorVG viewer](https://thorvg.github.io/thorvg.viewer/) enables instant rendering directly in the web browser using the ThorVG WebAssembly binary, allowing real-time editing of vector elements. It does not upload your resources to any external server and supports exporting to formats such as GIF, ensuring that designer copyrights remain protected.</br>
|
||||
</br>
|
||||
|
||||
<p align="center">
|
||||
<img width="700" height="auto" src="https://github.com/thorvg/thorvg/assets/3711518/edadcc5e-3bbf-489d-a9a1-9570079c7d55"/>
|
||||
</p>
|
||||
|
||||
### Lottie to GIF
|
||||
ThorVG provides an executable `tvg-lottie2gif` converter that generates a GIF file from a Lottie file.
|
||||
|
||||
To use the `tvg-lottie2gif`, you must turn on this feature in the build option:
|
||||
```
|
||||
meson setup builddir -Dtools=lottie2gif -Dsavers=gif
|
||||
```
|
||||
To use the 'tvg-lottie2gif' converter, you need to provide the 'Lottie files' parameter. This parameter can be a file name with the '.json' extension or a directory name. It also accepts multiple files or directories separated by spaces. If a directory is specified, the converter will search for files with the '.json' extension within that directory and all its subdirectories.<br />
|
||||
<br />
|
||||
Optionally, you can specify the image resolution in the 'WxH' format, with two numbers separated by an 'x' sign, following the '-r' flag.<br />
|
||||
<br />
|
||||
Both flags, if provided, are applied to all of the `.json` files.
|
||||
|
||||
The usage examples of the `tvg-lottie2gif`:
|
||||
```
|
||||
Usage:
|
||||
tvg-lottie2gif [Lottie file] or [Lottie folder] [-r resolution] [-f fps] [-b background color]
|
||||
|
||||
Flags:
|
||||
-r set the output image resolution.
|
||||
-f specifies the frames per second (fps) for the generated animation.
|
||||
-b specifies the base background color (RGB in hex). If not specified, the background color will follow the original content.
|
||||
|
||||
Examples:
|
||||
$ tvg-lottie2gif input.json
|
||||
$ tvg-lottie2gif input.json -f 30
|
||||
$ tvg-lottie2gif input.json -r 600x600 -f 30
|
||||
$ tvg-lottie2gif lottiefolder
|
||||
$ tvg-lottie2gif lottiefolder -r 600x600
|
||||
$ tvg-lottie2gif lottiefolder -r 600x600 -f 30 -b fa7410
|
||||
```
|
||||
|
||||
### SVG to PNG
|
||||
ThorVG provides an executable `tvg-svg2png` converter that generates a PNG file from an SVG file.
|
||||
|
||||
To use the `tvg-svg2png`, you must turn on this feature in the build option:
|
||||
```
|
||||
meson setup builddir -Dtools=svg2png
|
||||
```
|
||||
To use the 'tvg-svg2png' converter, you need to provide the 'SVG files' parameter. This parameter can be a file name with the '.svg' extension or a directory name. It also accepts multiple files or directories separated by spaces. If a directory is specified, the converter will search for files with the '.svg' extension within that directory and all its subdirectories.<br />
|
||||
<br />
|
||||
Optionally, you can specify the image resolution in the 'WxH' format, with two numbers separated by an 'x' sign, following the '-r' flag.<br />
|
||||
<br />
|
||||
The background color can be set with the `-b` flag. The `bgColor` parameter should be passed as a three-bytes hexadecimal value in the `ffffff` format. The default background is transparent.<br />
|
||||
<br />
|
||||
Both flags, if provided, are applied to all of the `.svg` files.
|
||||
|
||||
The usage examples of the `tvg-svg2png`:
|
||||
```
|
||||
Usage:
|
||||
tvg-svg2png [SVG files] [-r resolution] [-b bgColor]
|
||||
|
||||
Flags:
|
||||
-r set the output image resolution.
|
||||
-b set the output image background color.
|
||||
|
||||
Examples:
|
||||
$ tvg-svg2png input.svg
|
||||
$ tvg-svg2png input.svg -r 200x200
|
||||
$ tvg-svg2png input.svg -r 200x200 -b ff00ff
|
||||
$ tvg-svg2png input1.svg input2.svg -r 200x200 -b ff00ff
|
||||
$ tvg-svg2png . -r 200x200
|
||||
```
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Related Projects
|
||||
ThorVG is designed to be portable and extensible across various platforms. The following projects integrate ThorVG into specific environments or tools: </br >
|
||||
|
||||
* [ThorVG Android](https://github.com/thorvg/thorvg.android) – Kotlin-based ThorVG support for Android.
|
||||
* [ThorVG Example](https://github.com/thorvg/thorvg.example) – An example set demonstrates how to use ThorVG's APIs.
|
||||
* [ThorVG Flutter](https://github.com/thorvg/thorvg.flutter) - A Flutter plugin for using ThorVG on Android and iOS.
|
||||
* [ThorVG Janitor](https://github.com/thorvg/thorvg.janitor) - A demo game showcasing ThorVG’s real-time rendering features.
|
||||
* [ThorVG Swift](https://github.com/thorvg/thorvg.swift) - Swift bindings for rendering vector graphics with ThorVG.
|
||||
* [ThorVG Unity](https://github.com/thorvg/thorvg.unity) – ThorVG integration for Unity using C#.
|
||||
* [ThorVG Viewer](https://github.com/thorvg/thorvg.viewer) - A browser-based viewer for ThorVG using WebAssembly.
|
||||
* [ThorVG Web](https://github.com/thorvg/thorvg.web) - WebAssembly-based integration of ThorVG for web apps.
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
|
||||
## API Bindings
|
||||
Our main development APIs are written in C++, but ThorVG also provides API bindings for C.
|
||||
|
||||
To enable CAPI binding, you need to activate this feature in the build options:
|
||||
```
|
||||
meson setup builddir -Dbindings="capi"
|
||||
```
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Documentation
|
||||
The ThorVG API documentation is available at [thorvg.org/apis](https://www.thorvg.org/apis), and can also be found directly in this repository via the [C++ API](https://github.com/thorvg/thorvg/blob/main/inc/thorvg.h) and [C API](https://github.com/thorvg/thorvg/blob/main/src/bindings/capi/thorvg_capi.h).
|
||||
|
||||
For comprehensive and well-structured technical information, please visit the [DeepWiki](https://deepwiki.com/thorvg/thorvg), which offers in-depth guidance on ThorVG's architecture, features, and usage.
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## References
|
||||
- [Universal Motion Graphics across All Platforms: Unleashing Creativity with ThorVG](https://youtu.be/qhHMycRPQ9M?si=RXAag3Fxm8R7W_I0)
|
||||
- [Canva Enhances iOS Lottie Rendering: 80% Faster and 70% More Efficient with ThorVG](https://lottiefiles.com/blog/working-with-lottie-animations/canva-enhances-ios-rendering-faster-and-efficient-with-thorvg)
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Dependencies
|
||||
ThorVG provides flexible image loading capabilities, supporting both static and external loaders. This design ensures that even in environments lacking external libraries, users can rely on built-in static loaders for core functionality. At its core, the ThorVG library is fully self-contained and operates without mandatory external dependencies. However, several optional feature extensions are available, each with its own set of dependencies.
|
||||
|
||||
The following outlines the dependencies for these optional features:
|
||||
|
||||
* **GL Engine**: [OpenGL 3.3](https://www.khronos.org/opengl/), [OpenGL ES 3.0](https://www.khronos.org/opengles/), or a browser with [WebGL2](https://www.khronos.org/webgl/) support.
|
||||
* **WG Engine**: [webgpu-native v0.25](https://github.com/gfx-rs/wgpu-native) or a browser with [WebGPU](https://www.w3.org/TR/webgpu/) support.
|
||||
* **PNG Loader** (external): [libpng](https://github.com/pnggroup/libpng)
|
||||
* **JPEG Loader** (external): [libjpeg-turbo](https://github.com/libjpeg-turbo/libjpeg-turbo)
|
||||
* **WebP Loader** (external): [libwebp](https://developers.google.com/speed/webp/download)
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Contributors
|
||||
ThorVG stands as a purely open-source initiative. We are grateful to the individuals, organizations, and companies that have contributed to the development of the ThorVG project. The dedicated efforts of the individuals and entities listed below have enabled ThorVG to reach its current state.
|
||||
|
||||
* [Individuals](https://github.com/thorvg/thorvg/blob/main/CONTRIBUTORS.md)
|
||||
* [Godot](https://godotengine.org/)
|
||||
* [LVGL](https://lvgl.io/)
|
||||
* [Canva Pty Ltd](https://www.canva.com/)
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Partners
|
||||
Partners engage in strategic collaboration with ThorVG, working together to shape the future of scalable, high-performance vector graphics. We acknowledge organizations that have supported ThorVG’s journey through development, integration, collaboration, and community involvement.
|
||||
|
||||
<p align="center", href="https://www.lottiefiles.com">
|
||||
<a href="https://www.lottiefiles.com">
|
||||
<img width="250" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/partner_lottiefiles.jpg" alt="LottieFiles">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center", href="https://wwww.samsung.com">
|
||||
<a href="https://www.samsung.com">
|
||||
<img width="250" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/partner_samsung.jpg" alt="Samsung">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<br />
|
||||
|
||||
If you’re interested in partnering with ThorVG, we’d love to hear from you. Please reach out at thorvg@thorvg.org
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Sponsors
|
||||
We sincerely thank our financial sponsors for their generous support, which drives the growth and innovation of the ThorVG project. Your contributions help us make ThorVG more powerful, efficient, and accessible for everyone.
|
||||
<br/>
|
||||
<br/>
|
||||
<p align="center", href="https://www.lottiefiles.com">
|
||||
<a href="https://www.lottiefiles.com">
|
||||
<img width="250" height="auto" src="https://github.com/thorvg/thorvg.site/blob/main/readme/partner_lottiefiles.jpg" alt="LottieFiles">
|
||||
</a>
|
||||
</p>
|
||||
<br/>
|
||||
We are also seeking your support to ensure the continued development of the ThorVG project. Your generous donations will help cover operational costs and contribute to the growth of this open-source project. Even a small contribution can make a big difference in securing the future of ThorVG!
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
* [Open Collective](https://opencollective.com/thorvg)
|
||||
|
||||
[Back to contents](#contents)
|
||||
<br />
|
||||
<br />
|
||||
## Communication
|
||||
For real-time conversations and discussions, please join us on [Discord](https://discord.gg/n25xj6J6HM)
|
||||
|
||||
[Back to contents](#contents)
|
||||
19
components/thorvg-main/cross/android_aarch64.txt
Normal file
19
components/thorvg-main/cross/android_aarch64.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
# Android developer (Use the NDK with other build systems)
|
||||
# https://developer.android.com/ndk/guides/other_build_systems
|
||||
|
||||
[binaries]
|
||||
cpp = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/aarch64-linux-androidAPI-clang++'
|
||||
ar = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ar'
|
||||
as = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-as'
|
||||
ranlib = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ranlib'
|
||||
ld = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/ld'
|
||||
strip = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-strip'
|
||||
|
||||
[properties]
|
||||
sys_root = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/sysroot'
|
||||
|
||||
[host_machine]
|
||||
system = 'android'
|
||||
cpu_family = 'arm'
|
||||
cpu = 'aarch64'
|
||||
endian = 'little'
|
||||
19
components/thorvg-main/cross/android_x86_64.txt
Normal file
19
components/thorvg-main/cross/android_x86_64.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
# Android developer (Use the NDK with other build systems)
|
||||
# https://developer.android.com/ndk/guides/other_build_systems
|
||||
|
||||
[binaries]
|
||||
cpp = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/x86_64-linux-androidAPI-clang++'
|
||||
ar = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ar'
|
||||
as = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-as'
|
||||
ranlib = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ranlib'
|
||||
ld = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/ld'
|
||||
strip = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-strip'
|
||||
|
||||
[properties]
|
||||
sys_root = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/sysroot'
|
||||
|
||||
[host_machine]
|
||||
system = 'android'
|
||||
cpu_family = 'x86_64'
|
||||
cpu = 'x86_64'
|
||||
endian = 'little'
|
||||
22
components/thorvg-main/cross/ios_arm64.txt
Normal file
22
components/thorvg-main/cross/ios_arm64.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# build for the ios devices (Apple Silicon)
|
||||
|
||||
[binaries]
|
||||
cpp = ['clang++', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk']
|
||||
ar = 'ar'
|
||||
strip = 'strip'
|
||||
|
||||
[properties]
|
||||
root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer'
|
||||
has_function_printf = true
|
||||
|
||||
[built-in options]
|
||||
cpp_args = ['-miphoneos-version-min=11.0']
|
||||
cpp_link_args = ['-miphoneos-version-min=11.0']
|
||||
|
||||
[host_machine]
|
||||
system = 'darwin'
|
||||
subsystem = 'ios'
|
||||
kernel = 'xnu'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
endian = 'little'
|
||||
23
components/thorvg-main/cross/ios_simulator_arm64.txt
Normal file
23
components/thorvg-main/cross/ios_simulator_arm64.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
# build for the ios simulator (Apple Silicon)
|
||||
|
||||
[binaries]
|
||||
cpp = ['clang++', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk']
|
||||
ar = 'ar'
|
||||
strip = 'strip'
|
||||
|
||||
[properties]
|
||||
root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer'
|
||||
has_function_printf = true
|
||||
|
||||
[built-in options]
|
||||
cpp_args = ['-mios-simulator-version-min=11.0']
|
||||
cpp_link_args = ['-mios-simulator-version-min=11.0']
|
||||
|
||||
[host_machine]
|
||||
system = 'darwin'
|
||||
subsystem = 'ios'
|
||||
kernel = 'xnu'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
endian = 'little'
|
||||
|
||||
22
components/thorvg-main/cross/ios_simulator_x86_64.txt
Normal file
22
components/thorvg-main/cross/ios_simulator_x86_64.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# build for the ios simulator (Intel)
|
||||
|
||||
[binaries]
|
||||
cpp = ['clang++', '-arch', 'x86_64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk']
|
||||
ar = 'ar'
|
||||
strip = 'strip'
|
||||
|
||||
[properties]
|
||||
root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer'
|
||||
has_function_printf = true
|
||||
|
||||
[built-in options]
|
||||
cpp_args = ['-mios-simulator-version-min=11.0']
|
||||
cpp_link_args = ['-mios-simulator-version-min=11.0']
|
||||
|
||||
[host_machine]
|
||||
system = 'darwin'
|
||||
subsystem = 'ios'
|
||||
kernel = 'xnu'
|
||||
cpu_family = 'x86_64'
|
||||
cpu = 'x86_64'
|
||||
endian = 'little'
|
||||
5
components/thorvg-main/inc/meson.build
Normal file
5
components/thorvg-main/inc/meson.build
Normal file
@@ -0,0 +1,5 @@
|
||||
header_files = ['thorvg.h']
|
||||
|
||||
thorvg_inc = include_directories('.')
|
||||
|
||||
install_headers(header_files, subdir: 'thorvg-' + vmaj)
|
||||
2631
components/thorvg-main/inc/thorvg.h
Normal file
2631
components/thorvg-main/inc/thorvg.h
Normal file
File diff suppressed because it is too large
Load Diff
244
components/thorvg-main/meson.build
Normal file
244
components/thorvg-main/meson.build
Normal file
@@ -0,0 +1,244 @@
|
||||
project('thorvg',
|
||||
'cpp',
|
||||
default_options : ['buildtype=debugoptimized', 'b_sanitize=none', 'werror=false', 'optimization=3', 'cpp_std=c++14', 'strip=true'],
|
||||
version : '1.0.0',
|
||||
license : 'MIT')
|
||||
|
||||
v_array = meson.project_version().split('.')
|
||||
vmaj = v_array[0]
|
||||
|
||||
config_h = configuration_data()
|
||||
|
||||
src_dir = '/'.join(meson.current_source_dir().split('\\'))
|
||||
add_project_arguments('-DTEST_DIR="@0@/test/resources"'.format(src_dir),
|
||||
language : 'cpp')
|
||||
|
||||
config_h.set_quoted('THORVG_VERSION_STRING', meson.project_version())
|
||||
|
||||
# Multi-Tasking
|
||||
if get_option('threads')
|
||||
config_h.set10('THORVG_THREAD_SUPPORT', true)
|
||||
endif
|
||||
|
||||
# Engines
|
||||
all_engines = get_option('engines').contains('all')
|
||||
|
||||
sw_engine = false
|
||||
if all_engines or get_option('engines').contains('sw')
|
||||
sw_engine = true
|
||||
config_h.set10('THORVG_SW_RASTER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
gl_engine = false
|
||||
if all_engines or get_option('engines').contains('gl')
|
||||
gl_engine = true
|
||||
config_h.set10('THORVG_GL_RASTER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
wg_engine = false
|
||||
if all_engines or get_option('engines').contains('wg')
|
||||
wg_engine = true
|
||||
config_h.set10('THORVG_WG_RASTER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
# Partial Rendering
|
||||
if get_option('partial')
|
||||
config_h.set10('THORVG_PARTIAL_RENDER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
# Tools
|
||||
all_tools = get_option('tools').contains('all')
|
||||
lottie2gif = all_tools or get_option('tools').contains('lottie2gif')
|
||||
svg2png = all_tools or get_option('tools').contains('svg2png')
|
||||
|
||||
# Loaders
|
||||
all_loaders = get_option('loaders').contains('all')
|
||||
svg_loader = all_loaders or get_option('loaders').contains('svg') or svg2png
|
||||
png_loader = all_loaders or get_option('loaders').contains('png')
|
||||
jpg_loader = all_loaders or get_option('loaders').contains('jpg')
|
||||
lottie_loader = all_loaders or get_option('loaders').contains('lottie') or lottie2gif
|
||||
ttf_loader = all_loaders or get_option('loaders').contains('ttf')
|
||||
webp_loader = all_loaders or get_option('loaders').contains('webp')
|
||||
|
||||
# Savers
|
||||
all_savers = get_option('savers').contains('all')
|
||||
gif_saver = all_savers or get_option('savers').contains('gif') or lottie2gif
|
||||
|
||||
# Logging
|
||||
logging = get_option('log')
|
||||
|
||||
# Loaders/savers/tools config
|
||||
if svg_loader
|
||||
config_h.set10('THORVG_SVG_LOADER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
if png_loader
|
||||
config_h.set10('THORVG_PNG_LOADER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
if jpg_loader
|
||||
config_h.set10('THORVG_JPG_LOADER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
if lottie_loader
|
||||
config_h.set10('THORVG_LOTTIE_LOADER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
if ttf_loader
|
||||
config_h.set10('THORVG_TTF_LOADER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
if webp_loader
|
||||
config_h.set10('THORVG_WEBP_LOADER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
if gif_saver
|
||||
config_h.set10('THORVG_GIF_SAVER_SUPPORT', true)
|
||||
endif
|
||||
|
||||
# Vectorization
|
||||
simd_type = 'none'
|
||||
|
||||
if get_option('simd')
|
||||
if host_machine.cpu_family().startswith('x86')
|
||||
config_h.set10('THORVG_AVX_VECTOR_SUPPORT', true)
|
||||
simd_type = 'avx'
|
||||
elif host_machine.cpu_family().startswith('arm')
|
||||
config_h.set10('THORVG_NEON_VECTOR_SUPPORT', true)
|
||||
simd_type = 'neon-arm'
|
||||
elif host_machine.cpu().startswith('aarch')
|
||||
config_h.set10('THORVG_NEON_VECTOR_SUPPORT', true)
|
||||
simd_type = 'neon-aarch'
|
||||
endif
|
||||
endif
|
||||
|
||||
# Bindings
|
||||
if get_option('bindings').contains('capi')
|
||||
config_h.set10('THORVG_CAPI_BINDING_SUPPORT', true)
|
||||
endif
|
||||
|
||||
# Log
|
||||
if logging
|
||||
config_h.set10('THORVG_LOG_ENABLED', true)
|
||||
endif
|
||||
|
||||
# File IO
|
||||
if get_option('file') == true
|
||||
config_h.set10('THORVG_FILE_IO_SUPPORT', true)
|
||||
endif
|
||||
|
||||
|
||||
# Extra
|
||||
lottie_exp = lottie_loader and get_option('extra').contains('lottie_exp')
|
||||
|
||||
if lottie_exp
|
||||
config_h.set10('THORVG_LOTTIE_EXPRESSIONS_SUPPORT', true)
|
||||
endif
|
||||
|
||||
openmp = get_option('extra').contains('openmp')
|
||||
|
||||
if openmp
|
||||
config_h.set10('THORVG_OPENMP_SUPPORT', true)
|
||||
endif
|
||||
|
||||
gl_variant = ''
|
||||
|
||||
if gl_engine
|
||||
if get_option('extra').contains('opengl_es')
|
||||
gl_variant = 'OpenGL ES'
|
||||
else
|
||||
gl_variant = 'OpenGL'
|
||||
endif
|
||||
else
|
||||
gl_variant = 'None'
|
||||
endif
|
||||
|
||||
# Miscellaneous
|
||||
config_h.set10('WIN32_LEAN_AND_MEAN', true)
|
||||
|
||||
configure_file(
|
||||
output: 'config.h',
|
||||
configuration: config_h
|
||||
)
|
||||
|
||||
headers = [include_directories('inc'), include_directories('.')]
|
||||
|
||||
subdir('inc')
|
||||
subdir('src')
|
||||
subdir('tools')
|
||||
|
||||
if get_option('tests')
|
||||
subdir('test')
|
||||
endif
|
||||
|
||||
summary(
|
||||
{
|
||||
'Build Type': get_option('buildtype'),
|
||||
'Prefix': get_option('prefix'),
|
||||
'File I/O': get_option('file'),
|
||||
'Multi-Tasking': get_option('threads'),
|
||||
'Partial Rendering': get_option('partial'),
|
||||
'SIMD Instruction': simd_type,
|
||||
'Log Message': get_option('log'),
|
||||
'Tests': get_option('tests')
|
||||
},
|
||||
bool_yn: true,
|
||||
)
|
||||
|
||||
summary(
|
||||
{
|
||||
'SW': sw_engine,
|
||||
'GL': gl_engine,
|
||||
'WG': wg_engine,
|
||||
},
|
||||
section: 'Raster Engine',
|
||||
bool_yn: true,
|
||||
)
|
||||
|
||||
summary(
|
||||
{
|
||||
'SVG': svg_loader,
|
||||
'TTF': ttf_loader,
|
||||
'LOTTIE': lottie_loader,
|
||||
'PNG': png_loader,
|
||||
'JPG': jpg_loader,
|
||||
'WEBP': webp_loader,
|
||||
},
|
||||
section: 'Loader',
|
||||
bool_yn: true,
|
||||
)
|
||||
|
||||
summary(
|
||||
{
|
||||
'GIF': gif_saver,
|
||||
},
|
||||
section: 'Saver',
|
||||
bool_yn: true,
|
||||
)
|
||||
|
||||
summary(
|
||||
{
|
||||
'CAPI': get_option('bindings').contains('capi'),
|
||||
},
|
||||
section: 'Binding',
|
||||
bool_yn: true,
|
||||
)
|
||||
|
||||
summary(
|
||||
{
|
||||
'Svg2Png': svg2png,
|
||||
'Lottie2Gif': lottie2gif,
|
||||
},
|
||||
section: 'Tool',
|
||||
bool_yn: true,
|
||||
)
|
||||
|
||||
summary(
|
||||
{
|
||||
'Lottie Expressions': lottie_exp,
|
||||
'OpenMP': openmp,
|
||||
'OpenGL Variant': gl_variant
|
||||
},
|
||||
section: 'Extra',
|
||||
bool_yn: true,
|
||||
)
|
||||
70
components/thorvg-main/meson_options.txt
Normal file
70
components/thorvg-main/meson_options.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
option('engines',
|
||||
type: 'array',
|
||||
choices: ['sw', 'gl', 'wg', 'all'],
|
||||
value: ['sw'],
|
||||
description: 'Enable Rasterizer Engine in thorvg')
|
||||
|
||||
option('partial',
|
||||
type: 'boolean',
|
||||
value: true,
|
||||
description: 'Enable Partial Rendering in thorvg')
|
||||
|
||||
option('loaders',
|
||||
type: 'array',
|
||||
choices: ['', 'svg', 'png', 'jpg', 'lottie', 'ttf', 'webp', 'all'],
|
||||
value: ['svg', 'lottie', 'ttf'],
|
||||
description: 'Enable File Loaders in thorvg')
|
||||
|
||||
option('savers',
|
||||
type: 'array',
|
||||
choices: ['', 'gif', 'all'],
|
||||
value: [''],
|
||||
description: 'Enable File Savers in thorvg')
|
||||
|
||||
option('threads',
|
||||
type: 'boolean',
|
||||
value: true,
|
||||
description: 'Enable the multi-threading task scheduler in thorvg')
|
||||
|
||||
option('simd',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
description: 'Enable CPU Vectorization(SIMD) in thorvg')
|
||||
|
||||
option('bindings',
|
||||
type: 'array',
|
||||
choices: ['', 'capi'],
|
||||
value: [''],
|
||||
description: 'Enable API bindings')
|
||||
|
||||
option('tools',
|
||||
type: 'array',
|
||||
choices: ['', 'svg2png', 'lottie2gif', 'all'],
|
||||
value: [''],
|
||||
description: 'Enable building thorvg tools')
|
||||
|
||||
option('tests',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
description: 'Enable building Unit Tests')
|
||||
|
||||
option('log',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
description: 'Enable log message')
|
||||
|
||||
option('static',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
description: 'Force to use static linking modules in thorvg')
|
||||
|
||||
option('file',
|
||||
type: 'boolean',
|
||||
value: true,
|
||||
description: 'Enable File IO calls in thorvg')
|
||||
|
||||
option('extra',
|
||||
type: 'array',
|
||||
choices: ['', 'opengl_es', 'lottie_exp', 'openmp'],
|
||||
value: ['lottie_exp', 'openmp'],
|
||||
description: 'Enable support for extra options')
|
||||
11
components/thorvg-main/src/bindings/capi/meson.build
Normal file
11
components/thorvg-main/src/bindings/capi/meson.build
Normal file
@@ -0,0 +1,11 @@
|
||||
source_file = [
|
||||
'tvgCapi.cpp',
|
||||
]
|
||||
|
||||
thorvg_lib_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
sources : source_file
|
||||
)]
|
||||
|
||||
install_headers('thorvg_capi.h', subdir: 'thorvg-' + vmaj)
|
||||
headers += include_directories('.')
|
||||
3190
components/thorvg-main/src/bindings/capi/thorvg_capi.h
Normal file
3190
components/thorvg-main/src/bindings/capi/thorvg_capi.h
Normal file
File diff suppressed because it is too large
Load Diff
1235
components/thorvg-main/src/bindings/capi/tvgCapi.cpp
Normal file
1235
components/thorvg-main/src/bindings/capi/tvgCapi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3
components/thorvg-main/src/bindings/meson.build
Normal file
3
components/thorvg-main/src/bindings/meson.build
Normal file
@@ -0,0 +1,3 @@
|
||||
if get_option('bindings').contains('capi')
|
||||
subdir('capi')
|
||||
endif
|
||||
18
components/thorvg-main/src/common/meson.build
Normal file
18
components/thorvg-main/src/common/meson.build
Normal file
@@ -0,0 +1,18 @@
|
||||
source_file = [
|
||||
'tvgArray.h',
|
||||
'tvgCommon.h',
|
||||
'tvgColor.h',
|
||||
'tvgCompressor.h',
|
||||
'tvgInlist.h',
|
||||
'tvgLock.h',
|
||||
'tvgMath.h',
|
||||
'tvgStr.h',
|
||||
'tvgColor.cpp',
|
||||
'tvgCompressor.cpp',
|
||||
'tvgMath.cpp',
|
||||
'tvgStr.cpp'
|
||||
]
|
||||
|
||||
utils_dep = declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
sources : source_file)
|
||||
57
components/thorvg-main/src/common/tvgAllocator.h
Normal file
57
components/thorvg-main/src/common/tvgAllocator.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_ALLOCATOR_H_
|
||||
#define _TVG_ALLOCATOR_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
|
||||
//separate memory alloators for clean customization
|
||||
namespace tvg
|
||||
{
|
||||
template<typename T = void>
|
||||
static inline T* malloc(size_t size)
|
||||
{
|
||||
return static_cast<T*>(std::malloc(size));
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
static inline T* calloc(size_t nmem, size_t size)
|
||||
{
|
||||
return static_cast<T*>(std::calloc(nmem, size));
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
static inline T* realloc(T* ptr, size_t size)
|
||||
{
|
||||
return static_cast<T*>(std::realloc(ptr, size));
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
static inline void free(T* ptr)
|
||||
{
|
||||
std::free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif //_TVG_ALLOCATOR_H_
|
||||
197
components/thorvg-main/src/common/tvgArray.h
Normal file
197
components/thorvg-main/src/common/tvgArray.h
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_ARRAY_H_
|
||||
#define _TVG_ARRAY_H_
|
||||
|
||||
#include "tvgCommon.h"
|
||||
|
||||
#define ARRAY_FOREACH(A, B) \
|
||||
for (auto A = (B).begin(); A < (B).end(); ++A)
|
||||
|
||||
#define ARRAY_REVERSE_FOREACH(A, B) \
|
||||
for (auto A = (B).end() - 1; A >= (B).begin(); --A)
|
||||
|
||||
namespace tvg
|
||||
{
|
||||
|
||||
template<class T>
|
||||
struct Array
|
||||
{
|
||||
T* data = nullptr;
|
||||
uint32_t count = 0;
|
||||
uint32_t reserved = 0;
|
||||
|
||||
Array() = default;
|
||||
|
||||
Array(int32_t size)
|
||||
{
|
||||
reserve(size);
|
||||
}
|
||||
|
||||
Array(const Array& rhs)
|
||||
{
|
||||
reset();
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
void push(T element)
|
||||
{
|
||||
if (count + 1 > reserved) {
|
||||
reserved = count + (count + 2) / 2;
|
||||
data = tvg::realloc<T>(data, sizeof(T) * reserved);
|
||||
}
|
||||
data[count++] = element;
|
||||
}
|
||||
|
||||
void push(const Array<T>& rhs)
|
||||
{
|
||||
if (rhs.count == 0) return;
|
||||
grow(rhs.count);
|
||||
memcpy(data + count, rhs.data, rhs.count * sizeof(T));
|
||||
count += rhs.count;
|
||||
}
|
||||
|
||||
bool reserve(uint32_t size)
|
||||
{
|
||||
if (size > reserved) {
|
||||
reserved = size;
|
||||
data = tvg::realloc<T>(data, sizeof(T) * reserved);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool grow(uint32_t size)
|
||||
{
|
||||
return reserve(count + size);
|
||||
}
|
||||
|
||||
const T& operator[](size_t idx) const
|
||||
{
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
T& operator[](size_t idx)
|
||||
{
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
void operator=(const Array& rhs)
|
||||
{
|
||||
reserve(rhs.count);
|
||||
if (rhs.count > 0) memcpy(data, rhs.data, sizeof(T) * rhs.count);
|
||||
count = rhs.count;
|
||||
}
|
||||
|
||||
void move(Array& to)
|
||||
{
|
||||
to.reset();
|
||||
to.data = data;
|
||||
to.count = count;
|
||||
to.reserved = reserved;
|
||||
|
||||
data = nullptr;
|
||||
count = reserved = 0;
|
||||
}
|
||||
|
||||
const T* begin() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
T* begin()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
T* end()
|
||||
{
|
||||
return data + count;
|
||||
}
|
||||
|
||||
const T* end() const
|
||||
{
|
||||
return data + count;
|
||||
}
|
||||
|
||||
const T& last() const
|
||||
{
|
||||
return data[count - 1];
|
||||
}
|
||||
|
||||
const T& first() const
|
||||
{
|
||||
return data[0];
|
||||
}
|
||||
|
||||
T& last()
|
||||
{
|
||||
return data[count - 1];
|
||||
}
|
||||
|
||||
T& next()
|
||||
{
|
||||
if (full()) grow(count + 1);
|
||||
return data[count++];
|
||||
}
|
||||
|
||||
T& first()
|
||||
{
|
||||
return data[0];
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
if (count > 0) --count;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
tvg::free(data);
|
||||
data = nullptr;
|
||||
count = reserved = 0;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
bool full()
|
||||
{
|
||||
return count == reserved;
|
||||
}
|
||||
|
||||
~Array()
|
||||
{
|
||||
tvg::free(data);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //_TVG_ARRAY_H_
|
||||
67
components/thorvg-main/src/common/tvgColor.cpp
Normal file
67
components/thorvg-main/src/common/tvgColor.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tvgMath.h"
|
||||
#include "tvgColor.h"
|
||||
namespace tvg
|
||||
{
|
||||
|
||||
void hsl2rgb(float h, float s, float l, uint8_t& r, uint8_t& g, uint8_t& b)
|
||||
{
|
||||
if (tvg::zero(s)) {
|
||||
r = g = b = (uint8_t)nearbyint(l * 255.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tvg::equal(h, 360.0f)) {
|
||||
h = 0.0f;
|
||||
} else {
|
||||
h = fmod(h, 360.0f);
|
||||
if (h < 0.0f) h += 360.0f;
|
||||
h /= 60.0f;
|
||||
}
|
||||
|
||||
auto v = (l <= 0.5f) ? (l * (1.0f + s)) : (l + s - (l * s));
|
||||
auto p = l + l - v;
|
||||
auto sv = tvg::zero(v) ? 0.0f : (v - p) / v;
|
||||
auto i = static_cast<uint8_t>(h);
|
||||
auto f = h - i;
|
||||
auto vsf = v * sv * f;
|
||||
auto t = p + vsf;
|
||||
auto q = v - vsf;
|
||||
float tr, tg, tb;
|
||||
|
||||
switch (i) {
|
||||
case 0: tr = v; tg = t; tb = p; break;
|
||||
case 1: tr = q; tg = v; tb = p; break;
|
||||
case 2: tr = p; tg = v; tb = t; break;
|
||||
case 3: tr = p; tg = q; tb = v; break;
|
||||
case 4: tr = t; tg = p; tb = v; break;
|
||||
case 5: tr = v; tg = p; tb = q; break;
|
||||
default: tr = tg = tb = 0.0f; break;
|
||||
}
|
||||
r = (uint8_t)nearbyint(tr * 255.0f);
|
||||
g = (uint8_t)nearbyint(tg * 255.0f);
|
||||
b = (uint8_t)nearbyint(tb * 255.0f);
|
||||
}
|
||||
|
||||
}
|
||||
49
components/thorvg-main/src/common/tvgColor.h
Normal file
49
components/thorvg-main/src/common/tvgColor.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_COLOR_H_
|
||||
#define _TVG_COLOR_H_
|
||||
|
||||
|
||||
#include "tvgCommon.h"
|
||||
|
||||
namespace tvg
|
||||
{
|
||||
struct RGB
|
||||
{
|
||||
uint8_t r, g, b;
|
||||
};
|
||||
|
||||
struct RGBA
|
||||
{
|
||||
uint8_t r, g, b, a;
|
||||
};
|
||||
|
||||
struct HSL
|
||||
{
|
||||
float h, s, l;
|
||||
};
|
||||
|
||||
void hsl2rgb(float h, float s, float l, uint8_t& r, uint8_t& g, uint8_t& b);
|
||||
}
|
||||
|
||||
#endif //_TVG_COLOR_H_
|
||||
104
components/thorvg-main/src/common/tvgCommon.h
Normal file
104
components/thorvg-main/src/common/tvgCommon.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_COMMON_H_
|
||||
#define _TVG_COMMON_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(WINAPI_ENTRY)
|
||||
#if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#elif !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "config.h"
|
||||
#include "thorvg.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace tvg;
|
||||
|
||||
//for MSVC Compat
|
||||
#ifdef _MSC_VER
|
||||
#define TVG_UNUSED
|
||||
#define strncasecmp _strnicmp
|
||||
#define strcasecmp _stricmp
|
||||
#define strtok_r strtok_s
|
||||
#else
|
||||
#define TVG_UNUSED __attribute__ ((__unused__))
|
||||
#endif
|
||||
|
||||
// Portable 'fallthrough' attribute
|
||||
#if __has_cpp_attribute(fallthrough)
|
||||
#ifdef _MSC_VER
|
||||
#define TVG_FALLTHROUGH [[fallthrough]];
|
||||
#else
|
||||
#define TVG_FALLTHROUGH __attribute__ ((fallthrough));
|
||||
#endif
|
||||
#else
|
||||
#define TVG_FALLTHROUGH
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(__clang__)
|
||||
#define strncpy strncpy_s
|
||||
#endif
|
||||
|
||||
void* operator new(std::size_t size);
|
||||
void operator delete(void* ptr) noexcept;
|
||||
|
||||
namespace tvg {
|
||||
|
||||
enum class FileType { Png = 0, Jpg, Webp, Svg, Lot, Ttf, Raw, Gif, Unknown };
|
||||
|
||||
#ifdef THORVG_LOG_ENABLED
|
||||
constexpr auto ErrorColor = "\033[31m"; //red
|
||||
constexpr auto ErrorBgColor = "\033[41m";//bg red
|
||||
constexpr auto LogColor = "\033[32m"; //green
|
||||
constexpr auto LogBgColor = "\033[42m"; //bg green
|
||||
constexpr auto GreyColor = "\033[90m"; //grey
|
||||
constexpr auto ResetColors = "\033[0m"; //default
|
||||
#define TVGERR(tag, fmt, ...) fprintf(stderr, "%s[E]%s %s" tag "%s (%s %d): %s" fmt "\n", ErrorBgColor, ResetColors, ErrorColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__)
|
||||
#define TVGLOG(tag, fmt, ...) fprintf(stdout, "%s[L]%s %s" tag "%s (%s %d): %s" fmt "\n", LogBgColor, ResetColors, LogColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__)
|
||||
#else
|
||||
#define TVGERR(...) do {} while(0)
|
||||
#define TVGLOG(...) do {} while(0)
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
static inline T* to(const Paint* p)
|
||||
{
|
||||
return static_cast<T*>(const_cast<Paint*>(p));
|
||||
}
|
||||
|
||||
uint16_t THORVG_VERSION_NUMBER();
|
||||
|
||||
extern int engineInit;
|
||||
}
|
||||
|
||||
#include "tvgAllocator.h"
|
||||
|
||||
#endif //_TVG_COMMON_H_
|
||||
98
components/thorvg-main/src/common/tvgCompressor.cpp
Normal file
98
components/thorvg-main/src/common/tvgCompressor.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgCompressor.h"
|
||||
|
||||
namespace tvg {
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* B64 Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
size_t b64Decode(const char* encoded, const size_t len, char** decoded)
|
||||
{
|
||||
static constexpr const char B64_INDEX[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55, 56, 57,
|
||||
58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
|
||||
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
||||
};
|
||||
|
||||
|
||||
if (!decoded || !encoded || len == 0) return 0;
|
||||
|
||||
auto reserved = 3 * (1 + (len >> 2)) + 1;
|
||||
auto output = tvg::malloc<char>(reserved * sizeof(char));
|
||||
if (!output) return 0;
|
||||
output[reserved - 1] = '\0';
|
||||
|
||||
size_t idx = 0;
|
||||
|
||||
while (*encoded && *(encoded + 1)) {
|
||||
if (*encoded <= 0x20) {
|
||||
++encoded;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto value1 = B64_INDEX[(size_t)encoded[0]];
|
||||
auto value2 = B64_INDEX[(size_t)encoded[1]];
|
||||
output[idx++] = (value1 << 2) + ((value2 & 0x30) >> 4);
|
||||
|
||||
if (!encoded[2] || encoded[3] < 0 || encoded[2] == '=' || encoded[2] == '.') break;
|
||||
auto value3 = B64_INDEX[(size_t)encoded[2]];
|
||||
output[idx++] = ((value2 & 0x0f) << 4) + ((value3 & 0x3c) >> 2);
|
||||
|
||||
if (!encoded[3] || encoded[3] < 0 || encoded[3] == '=' || encoded[3] == '.') break;
|
||||
auto value4 = B64_INDEX[(size_t)encoded[3]];
|
||||
output[idx++] = ((value3 & 0x03) << 6) + value4;
|
||||
encoded += 4;
|
||||
}
|
||||
*decoded = output;
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* DJB2 Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
unsigned long djb2Encode(const char* str)
|
||||
{
|
||||
if (!str) return 0;
|
||||
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
|
||||
while ((c = *str++)) {
|
||||
hash = ((hash << 5) + hash) + c; // hash * 33 + c
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
||||
34
components/thorvg-main/src/common/tvgCompressor.h
Normal file
34
components/thorvg-main/src/common/tvgCompressor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_COMPRESSOR_H_
|
||||
#define _TVG_COMPRESSOR_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace tvg
|
||||
{
|
||||
size_t b64Decode(const char* encoded, const size_t len, char** decoded);
|
||||
unsigned long djb2Encode(const char* str);
|
||||
}
|
||||
|
||||
#endif //_TVG_COMPRESSOR_H_
|
||||
124
components/thorvg-main/src/common/tvgInlist.h
Normal file
124
components/thorvg-main/src/common/tvgInlist.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_INLIST_H_
|
||||
#define _TVG_INLIST_H_
|
||||
|
||||
namespace tvg {
|
||||
|
||||
//NOTE: declare this in your list item
|
||||
#define INLIST_ITEM(T) \
|
||||
T* prev; \
|
||||
T* next
|
||||
|
||||
template<typename T>
|
||||
struct Inlist
|
||||
{
|
||||
T* head = nullptr;
|
||||
T* tail = nullptr;
|
||||
|
||||
~Inlist()
|
||||
{
|
||||
free();
|
||||
}
|
||||
|
||||
void free()
|
||||
{
|
||||
while (head) {
|
||||
auto t = head;
|
||||
head = t->next;
|
||||
delete(t);
|
||||
}
|
||||
head = tail = nullptr;
|
||||
}
|
||||
|
||||
void back(T* element)
|
||||
{
|
||||
if (tail) {
|
||||
tail->next = element;
|
||||
element->prev = tail;
|
||||
element->next = nullptr;
|
||||
tail = element;
|
||||
} else {
|
||||
head = tail = element;
|
||||
element->prev = nullptr;
|
||||
element->next = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void front(T* element)
|
||||
{
|
||||
if (head) {
|
||||
head->prev = element;
|
||||
element->prev = nullptr;
|
||||
element->next = head;
|
||||
head = element;
|
||||
} else {
|
||||
head = tail = element;
|
||||
element->prev = nullptr;
|
||||
element->next = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
T* back()
|
||||
{
|
||||
if (!tail) return nullptr;
|
||||
auto t = tail;
|
||||
tail = t->prev;
|
||||
if (!tail) head = nullptr;
|
||||
return t;
|
||||
}
|
||||
|
||||
T* front()
|
||||
{
|
||||
if (!head) return nullptr;
|
||||
auto t = head;
|
||||
head = t->next;
|
||||
if (!head) tail = nullptr;
|
||||
return t;
|
||||
}
|
||||
|
||||
void remove(T* element)
|
||||
{
|
||||
if (element->prev) element->prev->next = element->next;
|
||||
if (element->next) element->next->prev = element->prev;
|
||||
if (element == head) head = element->next;
|
||||
if (element == tail) tail = element->prev;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return head ? false : true;
|
||||
}
|
||||
};
|
||||
|
||||
#define INLIST_FOREACH(inlist, cur) \
|
||||
for (auto cur = inlist.head; cur; cur = cur->next)
|
||||
|
||||
#define INLIST_SAFE_FOREACH(inlist, cur) \
|
||||
auto cur = inlist.head; \
|
||||
auto next = cur ? cur->next : nullptr; \
|
||||
for (; cur; cur = next, next = (cur ? cur->next : nullptr))
|
||||
|
||||
}
|
||||
|
||||
#endif // _TVG_INLIST_H_
|
||||
76
components/thorvg-main/src/common/tvgLock.h
Normal file
76
components/thorvg-main/src/common/tvgLock.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2024 the ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_LOCK_H_
|
||||
#define _TVG_LOCK_H_
|
||||
|
||||
#ifdef THORVG_THREAD_SUPPORT
|
||||
|
||||
#include <mutex>
|
||||
#include "tvgTaskScheduler.h"
|
||||
|
||||
namespace tvg {
|
||||
|
||||
struct Key
|
||||
{
|
||||
std::mutex mtx;
|
||||
};
|
||||
|
||||
struct ScopedLock
|
||||
{
|
||||
Key* key = nullptr;
|
||||
|
||||
ScopedLock(Key& k)
|
||||
{
|
||||
if (TaskScheduler::threads() > 0) {
|
||||
k.mtx.lock();
|
||||
key = &k;
|
||||
}
|
||||
}
|
||||
|
||||
~ScopedLock()
|
||||
{
|
||||
if (TaskScheduler::threads() > 0) {
|
||||
key->mtx.unlock();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#else //THORVG_THREAD_SUPPORT
|
||||
|
||||
namespace tvg {
|
||||
|
||||
struct Key {};
|
||||
|
||||
struct ScopedLock
|
||||
{
|
||||
ScopedLock(Key& key) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //THORVG_THREAD_SUPPORT
|
||||
|
||||
#endif //_TVG_LOCK_H_
|
||||
|
||||
513
components/thorvg-main/src/common/tvgMath.cpp
Normal file
513
components/thorvg-main/src/common/tvgMath.cpp
Normal file
@@ -0,0 +1,513 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tvgMath.h"
|
||||
#include "tvgArray.h"
|
||||
|
||||
#define BEZIER_EPSILON 1e-2f
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static float _lineLengthApprox(const Point& pt1, const Point& pt2)
|
||||
{
|
||||
/* approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm.
|
||||
With alpha = 1, beta = 3/8, giving results with the largest error less
|
||||
than 7% compared to the exact value. */
|
||||
Point diff = {pt2.x - pt1.x, pt2.y - pt1.y};
|
||||
if (diff.x < 0) diff.x = -diff.x;
|
||||
if (diff.y < 0) diff.y = -diff.y;
|
||||
return (diff.x > diff.y) ? (diff.x + diff.y * 0.375f) : (diff.y + diff.x * 0.375f);
|
||||
}
|
||||
|
||||
|
||||
static float _lineLength(const Point& pt1, const Point& pt2)
|
||||
{
|
||||
Point diff = {pt2.x - pt1.x, pt2.y - pt1.y};
|
||||
return sqrtf(diff.x * diff.x + diff.y * diff.y);
|
||||
}
|
||||
|
||||
|
||||
template<typename LengthFunc>
|
||||
float _bezLength(const Bezier& cur, LengthFunc lineLengthFunc)
|
||||
{
|
||||
Bezier left, right;
|
||||
auto len = lineLengthFunc(cur.start, cur.ctrl1) + lineLengthFunc(cur.ctrl1, cur.ctrl2) + lineLengthFunc(cur.ctrl2, cur.end);
|
||||
auto chord = lineLengthFunc(cur.start, cur.end);
|
||||
|
||||
if (fabsf(len - chord) > BEZIER_EPSILON) {
|
||||
cur.split(left, right);
|
||||
return _bezLength(left, lineLengthFunc) + _bezLength(right, lineLengthFunc);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
template<typename LengthFunc>
|
||||
float _bezAt(const Bezier& bz, float at, float length, LengthFunc lineLengthFunc)
|
||||
{
|
||||
auto biggest = 1.0f;
|
||||
auto smallest = 0.0f;
|
||||
auto t = 0.5f;
|
||||
|
||||
//just in case to prevent an infinite loop
|
||||
if (at <= 0) return 0.0f;
|
||||
if (at >= length) return 1.0f;
|
||||
|
||||
while (true) {
|
||||
auto right = bz;
|
||||
Bezier left;
|
||||
right.split(t, left);
|
||||
length = _bezLength(left, lineLengthFunc);
|
||||
if (fabsf(length - at) < BEZIER_EPSILON || fabsf(smallest - biggest) < 1e-3f) {
|
||||
break;
|
||||
}
|
||||
if (length < at) {
|
||||
smallest = t;
|
||||
t = (t + biggest) * 0.5f;
|
||||
} else {
|
||||
biggest = t;
|
||||
t = (smallest + t) * 0.5f;
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
namespace tvg {
|
||||
|
||||
|
||||
uint8_t lerp(const uint8_t &start, const uint8_t &end, float t)
|
||||
{
|
||||
return static_cast<uint8_t>(tvg::clamp(static_cast<int>(start + (end - start) * t), 0, 255));
|
||||
}
|
||||
|
||||
|
||||
float length(const PathCommand* cmds, uint32_t cmdsCnt, const Point* pts, uint32_t ptsCnt)
|
||||
{
|
||||
if (ptsCnt < 2) return 0.0f;
|
||||
|
||||
auto start = pts;
|
||||
auto length = 0.0f;
|
||||
|
||||
while (cmdsCnt-- > 0) {
|
||||
switch (*cmds) {
|
||||
case PathCommand::Close: {
|
||||
length += tvg::length(*(pts - 1), *start);
|
||||
break;
|
||||
}
|
||||
case PathCommand::MoveTo: {
|
||||
start = pts;
|
||||
++pts;
|
||||
break;
|
||||
}
|
||||
case PathCommand::LineTo: {
|
||||
length += tvg::length(*(pts - 1), *pts);
|
||||
++pts;
|
||||
break;
|
||||
}
|
||||
case PathCommand::CubicTo: {
|
||||
length += Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}.length();
|
||||
pts += 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++cmds;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
//https://en.wikipedia.org/wiki/Remez_algorithm
|
||||
float atan2(float y, float x)
|
||||
{
|
||||
if (y == 0.0f && x == 0.0f) return 0.0f;
|
||||
auto a = std::min(fabsf(x), fabsf(y)) / std::max(fabsf(x), fabsf(y));
|
||||
auto s = a * a;
|
||||
auto r = ((-0.0464964749f * s + 0.15931422f) * s - 0.327622764f) * s * a + a;
|
||||
if (fabsf(y) > fabsf(x)) r = 1.57079637f - r;
|
||||
if (x < 0) r = 3.14159274f - r;
|
||||
if (y < 0) return -r;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
bool inverse(const Matrix* m, Matrix* out)
|
||||
{
|
||||
auto det = m->e11 * (m->e22 * m->e33 - m->e32 * m->e23) -
|
||||
m->e12 * (m->e21 * m->e33 - m->e23 * m->e31) +
|
||||
m->e13 * (m->e21 * m->e32 - m->e22 * m->e31);
|
||||
|
||||
auto invDet = 1.0f / det;
|
||||
if (std::isinf(invDet)) return false;
|
||||
|
||||
out->e11 = (m->e22 * m->e33 - m->e32 * m->e23) * invDet;
|
||||
out->e12 = (m->e13 * m->e32 - m->e12 * m->e33) * invDet;
|
||||
out->e13 = (m->e12 * m->e23 - m->e13 * m->e22) * invDet;
|
||||
out->e21 = (m->e23 * m->e31 - m->e21 * m->e33) * invDet;
|
||||
out->e22 = (m->e11 * m->e33 - m->e13 * m->e31) * invDet;
|
||||
out->e23 = (m->e21 * m->e13 - m->e11 * m->e23) * invDet;
|
||||
out->e31 = (m->e21 * m->e32 - m->e31 * m->e22) * invDet;
|
||||
out->e32 = (m->e31 * m->e12 - m->e11 * m->e32) * invDet;
|
||||
out->e33 = (m->e11 * m->e22 - m->e21 * m->e12) * invDet;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool identity(const Matrix* m)
|
||||
{
|
||||
if (m->e11 != 1.0f || m->e12 != 0.0f || m->e13 != 0.0f ||
|
||||
m->e21 != 0.0f || m->e22 != 1.0f || m->e23 != 0.0f ||
|
||||
m->e31 != 0.0f || m->e32 != 0.0f || m->e33 != 1.0f) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void rotate(Matrix* m, float degree)
|
||||
{
|
||||
if (degree == 0.0f) return;
|
||||
|
||||
auto radian = degree / 180.0f * MATH_PI;
|
||||
auto cosVal = cosf(radian);
|
||||
auto sinVal = sinf(radian);
|
||||
|
||||
m->e12 = m->e11 * -sinVal;
|
||||
m->e11 *= cosVal;
|
||||
m->e21 = m->e22 * sinVal;
|
||||
m->e22 *= cosVal;
|
||||
}
|
||||
|
||||
|
||||
Matrix operator*(const Matrix& lhs, const Matrix& rhs)
|
||||
{
|
||||
Matrix m;
|
||||
|
||||
m.e11 = lhs.e11 * rhs.e11 + lhs.e12 * rhs.e21 + lhs.e13 * rhs.e31;
|
||||
m.e12 = lhs.e11 * rhs.e12 + lhs.e12 * rhs.e22 + lhs.e13 * rhs.e32;
|
||||
m.e13 = lhs.e11 * rhs.e13 + lhs.e12 * rhs.e23 + lhs.e13 * rhs.e33;
|
||||
|
||||
m.e21 = lhs.e21 * rhs.e11 + lhs.e22 * rhs.e21 + lhs.e23 * rhs.e31;
|
||||
m.e22 = lhs.e21 * rhs.e12 + lhs.e22 * rhs.e22 + lhs.e23 * rhs.e32;
|
||||
m.e23 = lhs.e21 * rhs.e13 + lhs.e22 * rhs.e23 + lhs.e23 * rhs.e33;
|
||||
|
||||
m.e31 = lhs.e31 * rhs.e11 + lhs.e32 * rhs.e21 + lhs.e33 * rhs.e31;
|
||||
m.e32 = lhs.e31 * rhs.e12 + lhs.e32 * rhs.e22 + lhs.e33 * rhs.e32;
|
||||
m.e33 = lhs.e31 * rhs.e13 + lhs.e32 * rhs.e23 + lhs.e33 * rhs.e33;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const Matrix& lhs, const Matrix& rhs)
|
||||
{
|
||||
if (!tvg::equal(lhs.e11, rhs.e11) || !tvg::equal(lhs.e12, rhs.e12) || !tvg::equal(lhs.e13, rhs.e13) ||
|
||||
!tvg::equal(lhs.e21, rhs.e21) || !tvg::equal(lhs.e22, rhs.e22) || !tvg::equal(lhs.e23, rhs.e23) ||
|
||||
!tvg::equal(lhs.e31, rhs.e31) || !tvg::equal(lhs.e32, rhs.e32) || !tvg::equal(lhs.e33, rhs.e33)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void operator*=(Point& pt, const Matrix& m)
|
||||
{
|
||||
auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13;
|
||||
auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23;
|
||||
pt.x = tx;
|
||||
pt.y = ty;
|
||||
}
|
||||
|
||||
|
||||
Point operator*(const Point& pt, const Matrix& m)
|
||||
{
|
||||
auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13;
|
||||
auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23;
|
||||
return {tx, ty};
|
||||
}
|
||||
|
||||
|
||||
Point normal(const Point& p1, const Point& p2)
|
||||
{
|
||||
auto dir = p2 - p1;
|
||||
auto len = length(dir);
|
||||
if (tvg::zero(len)) return {};
|
||||
|
||||
auto unitDir = dir / len;
|
||||
return {-unitDir.y, unitDir.x};
|
||||
}
|
||||
|
||||
|
||||
void normalize(Point& pt)
|
||||
{
|
||||
if (zero(pt)) return; //prevent zero division
|
||||
auto ilength = 1.0f / sqrtf((pt.x * pt.x) + (pt.y * pt.y));
|
||||
pt.x *= ilength;
|
||||
pt.y *= ilength;
|
||||
}
|
||||
|
||||
|
||||
float Line::length() const
|
||||
{
|
||||
return _lineLength(pt1, pt2);
|
||||
}
|
||||
|
||||
|
||||
void Line::split(float at, Line& left, Line& right) const
|
||||
{
|
||||
auto len = length();
|
||||
auto dx = ((pt2.x - pt1.x) / len) * at;
|
||||
auto dy = ((pt2.y - pt1.y) / len) * at;
|
||||
left.pt1 = pt1;
|
||||
left.pt2.x = left.pt1.x + dx;
|
||||
left.pt2.y = left.pt1.y + dy;
|
||||
right.pt1 = left.pt2;
|
||||
right.pt2 = pt2;
|
||||
}
|
||||
|
||||
|
||||
Bezier::Bezier(const Point& st, const Point& ed, float radius)
|
||||
{
|
||||
// Calculate the angle between the start and end points
|
||||
auto angle = tvg::atan2(ed.y - st.y, ed.x - st.x);
|
||||
|
||||
// Calculate the control points of the cubic bezier curve
|
||||
auto c = radius * PATH_KAPPA; // c = radius * (4/3) * tan(pi/8)
|
||||
|
||||
start = {st.x, st.y};
|
||||
ctrl1 = {st.x + radius * cos(angle), st.y + radius * sin(angle)};
|
||||
ctrl2 = {ed.x - c * cos(angle), ed.y - c * sin(angle)};
|
||||
end = {ed.x, ed.y};
|
||||
}
|
||||
|
||||
|
||||
void Bezier::split(Bezier& left, Bezier& right) const
|
||||
{
|
||||
auto c = (ctrl1.x + ctrl2.x) * 0.5f;
|
||||
left.ctrl1.x = (start.x + ctrl1.x) * 0.5f;
|
||||
right.ctrl2.x = (ctrl2.x + end.x) * 0.5f;
|
||||
left.start.x = start.x;
|
||||
right.end.x = end.x;
|
||||
left.ctrl2.x = (left.ctrl1.x + c) * 0.5f;
|
||||
right.ctrl1.x = (right.ctrl2.x + c) * 0.5f;
|
||||
left.end.x = right.start.x = (left.ctrl2.x + right.ctrl1.x) * 0.5f;
|
||||
|
||||
c = (ctrl1.y + ctrl2.y) * 0.5f;
|
||||
left.ctrl1.y = (start.y + ctrl1.y) * 0.5f;
|
||||
right.ctrl2.y = (ctrl2.y + end.y) * 0.5f;
|
||||
left.start.y = start.y;
|
||||
right.end.y = end.y;
|
||||
left.ctrl2.y = (left.ctrl1.y + c) * 0.5f;
|
||||
right.ctrl1.y = (right.ctrl2.y + c) * 0.5f;
|
||||
left.end.y = right.start.y = (left.ctrl2.y + right.ctrl1.y) * 0.5f;
|
||||
}
|
||||
|
||||
|
||||
void Bezier::split(float at, Bezier& left, Bezier& right) const
|
||||
{
|
||||
right = *this;
|
||||
auto t = right.at(at, right.length());
|
||||
right.split(t, left);
|
||||
}
|
||||
|
||||
|
||||
float Bezier::length() const
|
||||
{
|
||||
return _bezLength(*this, _lineLength);
|
||||
}
|
||||
|
||||
|
||||
float Bezier::lengthApprox() const
|
||||
{
|
||||
return _bezLength(*this, _lineLengthApprox);
|
||||
}
|
||||
|
||||
|
||||
void Bezier::split(float t, Bezier& left)
|
||||
{
|
||||
left.start = start;
|
||||
|
||||
left.ctrl1.x = start.x + t * (ctrl1.x - start.x);
|
||||
left.ctrl1.y = start.y + t * (ctrl1.y - start.y);
|
||||
|
||||
left.ctrl2.x = ctrl1.x + t * (ctrl2.x - ctrl1.x); //temporary holding spot
|
||||
left.ctrl2.y = ctrl1.y + t * (ctrl2.y - ctrl1.y); //temporary holding spot
|
||||
|
||||
ctrl2.x = ctrl2.x + t * (end.x - ctrl2.x);
|
||||
ctrl2.y = ctrl2.y + t * (end.y - ctrl2.y);
|
||||
|
||||
ctrl1.x = left.ctrl2.x + t * (ctrl2.x - left.ctrl2.x);
|
||||
ctrl1.y = left.ctrl2.y + t * (ctrl2.y - left.ctrl2.y);
|
||||
|
||||
left.ctrl2.x = left.ctrl1.x + t * (left.ctrl2.x - left.ctrl1.x);
|
||||
left.ctrl2.y = left.ctrl1.y + t * (left.ctrl2.y - left.ctrl1.y);
|
||||
|
||||
left.end.x = start.x = left.ctrl2.x + t * (ctrl1.x - left.ctrl2.x);
|
||||
left.end.y = start.y = left.ctrl2.y + t * (ctrl1.y - left.ctrl2.y);
|
||||
}
|
||||
|
||||
|
||||
float Bezier::at(float at, float length) const
|
||||
{
|
||||
return _bezAt(*this, at, length, _lineLength);
|
||||
}
|
||||
|
||||
|
||||
float Bezier::atApprox(float at, float length) const
|
||||
{
|
||||
return _bezAt(*this, at, length, _lineLengthApprox);
|
||||
}
|
||||
|
||||
|
||||
Point Bezier::at(float t) const
|
||||
{
|
||||
Point cur;
|
||||
auto it = 1.0f - t;
|
||||
|
||||
auto ax = start.x * it + ctrl1.x * t;
|
||||
auto bx = ctrl1.x * it + ctrl2.x * t;
|
||||
auto cx = ctrl2.x * it + end.x * t;
|
||||
ax = ax * it + bx * t;
|
||||
bx = bx * it + cx * t;
|
||||
cur.x = ax * it + bx * t;
|
||||
|
||||
float ay = start.y * it + ctrl1.y * t;
|
||||
float by = ctrl1.y * it + ctrl2.y * t;
|
||||
float cy = ctrl2.y * it + end.y * t;
|
||||
ay = ay * it + by * t;
|
||||
by = by * it + cy * t;
|
||||
cur.y = ay * it + by * t;
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
|
||||
float Bezier::angle(float t) const
|
||||
{
|
||||
if (t < 0 || t > 1) return 0;
|
||||
|
||||
//derivate
|
||||
// p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 *
|
||||
// t^2) * p2 + t^2 * p3)
|
||||
float mt = 1.0f - t;
|
||||
float d = t * t;
|
||||
float a = -mt * mt;
|
||||
float b = 1 - 4 * t + 3 * d;
|
||||
float c = 2 * t - 3 * d;
|
||||
|
||||
Point pt ={a * start.x + b * ctrl1.x + c * ctrl2.x + d * end.x, a * start.y + b * ctrl1.y + c * ctrl2.y + d * end.y};
|
||||
pt.x *= 3;
|
||||
pt.y *= 3;
|
||||
|
||||
return rad2deg(tvg::atan2(pt.y, pt.x));
|
||||
}
|
||||
|
||||
|
||||
void Bezier::bounds(BBox& box, const Point& start, const Point& ctrl1, const Point& ctrl2, const Point& end)
|
||||
{
|
||||
if (box.min.x > start.x) box.min.x = start.x;
|
||||
if (box.min.y > start.y) box.min.y = start.y;
|
||||
if (box.min.x > end.x) box.min.x = end.x;
|
||||
if (box.min.y > end.y) box.min.y = end.y;
|
||||
|
||||
if (box.max.x < start.x) box.max.x = start.x;
|
||||
if (box.max.y < start.y) box.max.y = start.y;
|
||||
if (box.max.x < end.x) box.max.x = end.x;
|
||||
if (box.max.y < end.y) box.max.y = end.y;
|
||||
|
||||
//find x/y-direction extrema (solving derivative of Bezier curve)
|
||||
auto findMinMax = [&](float start, float ctrl1, float ctrl2, float end, float& min, float& max) -> void {
|
||||
auto a = -1.0f * start + 3.0f * ctrl1 - 3.0f * ctrl2 + end;
|
||||
auto b = start - 2.0f * ctrl1 + ctrl2;
|
||||
auto c = -1.0f * start + ctrl1;
|
||||
auto h = b * b - a * c;
|
||||
if (h <= 0.0f) return;
|
||||
h = sqrtf(h);
|
||||
float t[2] = {(-b - h) / a, (-b + h) / a};
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (t[i] <= 0.0f || t[i] >= 1.0f) continue;
|
||||
auto s = 1.0f - t[i];
|
||||
auto q = s * s * s * start + 3.0f * s * s * t[i] * ctrl1 + 3.0f * s * t[i] * t[i] * ctrl2 + t[i] * t[i] * t[i] * end;
|
||||
if (q < min) min = q;
|
||||
if (q > max) max = q;
|
||||
}
|
||||
};
|
||||
|
||||
findMinMax(start.x, ctrl1.x, ctrl2.x, end.x, box.min.x, box.max.x);
|
||||
findMinMax(start.y, ctrl1.y, ctrl2.y, end.y, box.min.y, box.max.y);
|
||||
}
|
||||
|
||||
|
||||
bool Bezier::flatten() const
|
||||
{
|
||||
float diff1_x = fabsf((ctrl1.x * 3.f) - (start.x * 2.f) - end.x);
|
||||
float diff1_y = fabsf((ctrl1.y * 3.f) - (start.y * 2.f) - end.y);
|
||||
float diff2_x = fabsf((ctrl2.x * 3.f) - (end.x * 2.f) - start.x);
|
||||
float diff2_y = fabsf((ctrl2.y * 3.f) - (end.y * 2.f) - start.y);
|
||||
if (diff1_x < diff2_x) diff1_x = diff2_x;
|
||||
if (diff1_y < diff2_y) diff1_y = diff2_y;
|
||||
return (diff1_x + diff1_y <= 0.5f);
|
||||
}
|
||||
|
||||
|
||||
uint32_t Bezier::segments() const
|
||||
{
|
||||
static constexpr uint32_t MaxSegments = 1u << 10; // 2^10 segments cap keeps runtime bounded
|
||||
uint32_t count = 0;
|
||||
Array<Bezier> stack;
|
||||
stack.push(*this);
|
||||
Bezier left, right;
|
||||
|
||||
while (!stack.empty()) {
|
||||
auto current = stack.last();
|
||||
stack.pop();
|
||||
if (current.flatten()) {
|
||||
++count;
|
||||
continue;
|
||||
}
|
||||
if (count + stack.count + 2 >= MaxSegments) {
|
||||
TVGERR("Common", "Bezier segments count exceeded the maximum limit.");
|
||||
return MaxSegments;
|
||||
}
|
||||
current.split(left, right);
|
||||
stack.push(left);
|
||||
stack.push(right);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
Bezier Bezier::operator*(const Matrix& m)
|
||||
{
|
||||
return Bezier{start * m, ctrl1* m, ctrl2 * m, end * m};
|
||||
}
|
||||
|
||||
}
|
||||
486
components/thorvg-main/src/common/tvgMath.h
Normal file
486
components/thorvg-main/src/common/tvgMath.h
Normal file
@@ -0,0 +1,486 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_MATH_H_
|
||||
#define _TVG_MATH_H_
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include <float.h>
|
||||
#include <cmath>
|
||||
#include "tvgCommon.h"
|
||||
|
||||
namespace tvg
|
||||
{
|
||||
|
||||
#define MATH_PI 3.14159265358979323846f
|
||||
#define MATH_PI2 1.57079632679489661923f
|
||||
#define FLOAT_EPSILON 1.0e-06f //1.192092896e-07f
|
||||
#define PATH_KAPPA 0.552284f
|
||||
|
||||
/************************************************************************/
|
||||
/* General functions */
|
||||
/************************************************************************/
|
||||
|
||||
float atan2(float y, float x);
|
||||
float length(const PathCommand* cmds, uint32_t cmdsCnt, const Point* pts, uint32_t ptsCnt);
|
||||
|
||||
|
||||
static inline float deg2rad(float degree)
|
||||
{
|
||||
return degree * (MATH_PI / 180.0f);
|
||||
}
|
||||
|
||||
|
||||
static inline float rad2deg(float radian)
|
||||
{
|
||||
return radian * (180.0f / MATH_PI);
|
||||
}
|
||||
|
||||
|
||||
static inline bool zero(float a)
|
||||
{
|
||||
return (fabsf(a) <= FLOAT_EPSILON) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
static inline bool equal(float a, float b)
|
||||
{
|
||||
return tvg::zero(a - b);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static inline constexpr const T& clamp(const T& v, const T& min, const T& max)
|
||||
{
|
||||
if (v < min) return min;
|
||||
else if (v > max) return max;
|
||||
return v;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* Matrix functions */
|
||||
/************************************************************************/
|
||||
|
||||
void rotate(Matrix* m, float degree);
|
||||
bool inverse(const Matrix* m, Matrix* out);
|
||||
bool identity(const Matrix* m);
|
||||
Matrix operator*(const Matrix& lhs, const Matrix& rhs);
|
||||
bool operator==(const Matrix& lhs, const Matrix& rhs);
|
||||
|
||||
|
||||
static inline float radian(const Matrix& m)
|
||||
{
|
||||
return fabsf(tvg::atan2(m.e21, m.e11));
|
||||
}
|
||||
|
||||
|
||||
static inline bool rightAngle(const Matrix& m)
|
||||
{
|
||||
auto radian = tvg::radian(m);
|
||||
if (tvg::zero(radian) || tvg::zero(radian - MATH_PI2) || tvg::zero(radian - MATH_PI)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static inline bool skewed(const Matrix& m)
|
||||
{
|
||||
return !tvg::zero(m.e21 + m.e12);
|
||||
}
|
||||
|
||||
|
||||
static inline void identity(Matrix* m)
|
||||
{
|
||||
m->e11 = 1.0f;
|
||||
m->e12 = 0.0f;
|
||||
m->e13 = 0.0f;
|
||||
m->e21 = 0.0f;
|
||||
m->e22 = 1.0f;
|
||||
m->e23 = 0.0f;
|
||||
m->e31 = 0.0f;
|
||||
m->e32 = 0.0f;
|
||||
m->e33 = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
static inline constexpr const Matrix identity()
|
||||
{
|
||||
return {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
}
|
||||
|
||||
|
||||
static inline float scaling(const Matrix& m)
|
||||
{
|
||||
return sqrtf(m.e11 * m.e11 + m.e21 * m.e21);
|
||||
}
|
||||
|
||||
|
||||
static inline void scale(Matrix* m, const Point& p)
|
||||
{
|
||||
m->e11 *= p.x;
|
||||
m->e22 *= p.y;
|
||||
}
|
||||
|
||||
|
||||
static inline void scaleR(Matrix* m, const Point& p)
|
||||
{
|
||||
if (p.x != 1.0f) {
|
||||
m->e11 *= p.x;
|
||||
m->e21 *= p.x;
|
||||
}
|
||||
if (p.y != 1.0f) {
|
||||
m->e22 *= p.y;
|
||||
m->e12 *= p.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void translate(Matrix* m, const Point& p)
|
||||
{
|
||||
m->e13 += p.x;
|
||||
m->e23 += p.y;
|
||||
}
|
||||
|
||||
|
||||
static inline void translateR(Matrix* m, const Point& p)
|
||||
{
|
||||
if (p.x == 0.0f && p.y == 0.0f) return;
|
||||
m->e13 += (p.x * m->e11 + p.y * m->e12);
|
||||
m->e23 += (p.x * m->e21 + p.y * m->e22);
|
||||
}
|
||||
|
||||
|
||||
static inline bool operator!=(const Matrix& lhs, const Matrix& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
static inline void operator*=(Matrix& lhs, const Matrix& rhs)
|
||||
{
|
||||
lhs = lhs * rhs;
|
||||
}
|
||||
|
||||
|
||||
static inline Matrix operator*(const Matrix* lhs, const Matrix& rhs)
|
||||
{
|
||||
if (lhs) return *lhs * rhs;
|
||||
return rhs;
|
||||
}
|
||||
|
||||
|
||||
static inline void log(const Matrix& m)
|
||||
{
|
||||
TVGLOG("COMMON", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m.e11, m.e12, m.e13, m.e21, m.e22, m.e23, m.e31, m.e32, m.e33);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Point functions */
|
||||
/************************************************************************/
|
||||
|
||||
void operator*=(Point& pt, const Matrix& m);
|
||||
Point operator*(const Point& pt, const Matrix& m);
|
||||
Point normal(const Point& p1, const Point& p2);
|
||||
void normalize(Point& pt);
|
||||
|
||||
static inline constexpr const Point operator*=(Point& pt, const Matrix* m)
|
||||
{
|
||||
if (m) pt *= *m;
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator*(const Point& pt, const Matrix* m)
|
||||
{
|
||||
if (m) return pt * *m;
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
static inline Point min(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return {std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y)};
|
||||
}
|
||||
|
||||
|
||||
static inline Point max(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return {std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y)};
|
||||
}
|
||||
|
||||
|
||||
static inline float dot(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return lhs.x * rhs.x + lhs.y * rhs.y;
|
||||
}
|
||||
|
||||
|
||||
static inline float cross(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return lhs.x * rhs.y - rhs.x * lhs.y;
|
||||
}
|
||||
|
||||
|
||||
static inline bool zero(const Point& p)
|
||||
{
|
||||
return tvg::zero(p.x) && tvg::zero(p.y);
|
||||
}
|
||||
|
||||
|
||||
static inline float length(const Point& a, const Point& b)
|
||||
{
|
||||
auto x = b.x - a.x;
|
||||
auto y = b.y - a.y;
|
||||
|
||||
if (x < 0) x = -x;
|
||||
if (y < 0) y = -y;
|
||||
|
||||
return (x > y) ? (x + 0.375f * y) : (y + 0.375f * x);
|
||||
}
|
||||
|
||||
|
||||
static inline float length(const Point& a)
|
||||
{
|
||||
return sqrtf(a.x * a.x + a.y * a.y);
|
||||
}
|
||||
|
||||
|
||||
static inline float length2(const Point& a)
|
||||
{
|
||||
return a.x * a.x + a.y * a.y;
|
||||
};
|
||||
|
||||
|
||||
static inline bool operator==(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return tvg::equal(lhs.x, rhs.x) && tvg::equal(lhs.y, rhs.y);
|
||||
}
|
||||
|
||||
|
||||
static inline bool operator!=(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator-(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return {lhs.x - rhs.x, lhs.y - rhs.y};
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator-(const Point& lhs, const float rhs)
|
||||
{
|
||||
return {lhs.x - rhs, lhs.y - rhs};
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator+(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return {lhs.x + rhs.x, lhs.y + rhs.y};
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator+(const Point& lhs, const float rhs)
|
||||
{
|
||||
return {lhs.x + rhs, lhs.y + rhs};
|
||||
}
|
||||
|
||||
|
||||
static inline void operator+=(Point& lhs, const Point& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator*(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return {lhs.x * rhs.x, lhs.y * rhs.y};
|
||||
}
|
||||
|
||||
|
||||
static inline void operator*=(Point& lhs, const Point& rhs)
|
||||
{
|
||||
lhs.x *= rhs.x;
|
||||
lhs.y *= rhs.y;
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator*(const Point& lhs, const float rhs)
|
||||
{
|
||||
return {lhs.x * rhs, lhs.y * rhs};
|
||||
}
|
||||
|
||||
|
||||
static inline void operator*=(Point& lhs, const float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator*(const float& lhs, const Point& rhs)
|
||||
{
|
||||
return {lhs * rhs.x, lhs * rhs.y};
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator/(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
return {lhs.x / rhs.x, lhs.y / rhs.y};
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator/(const Point& lhs, const float rhs)
|
||||
{
|
||||
return {lhs.x / rhs, lhs.y / rhs};
|
||||
}
|
||||
|
||||
|
||||
static inline Point operator-(const Point& a)
|
||||
{
|
||||
return {-a.x, -a.y};
|
||||
}
|
||||
|
||||
enum class Orientation
|
||||
{
|
||||
Linear = 0,
|
||||
Clockwise,
|
||||
CounterClockwise,
|
||||
};
|
||||
|
||||
|
||||
static inline Orientation orientation(const Point& p1, const Point& p2, const Point& p3)
|
||||
{
|
||||
auto val = cross(p2 - p1, p3 - p1);
|
||||
if (zero(val)) return Orientation::Linear;
|
||||
else return val > 0 ? Orientation::Clockwise : Orientation::CounterClockwise;
|
||||
}
|
||||
|
||||
|
||||
static inline void log(const Point& pt)
|
||||
{
|
||||
TVGLOG("COMMON", "Point: [%f %f]", pt.x, pt.y);
|
||||
}
|
||||
|
||||
|
||||
static inline bool closed(const Point& lhs, const Point& rhs, float tolerance)
|
||||
{
|
||||
float dx = lhs.x - rhs.x;
|
||||
float dy = lhs.y - rhs.y;
|
||||
return (dx * dx + dy * dy) < (tolerance * tolerance);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Line functions */
|
||||
/************************************************************************/
|
||||
|
||||
struct Line
|
||||
{
|
||||
Point pt1;
|
||||
Point pt2;
|
||||
|
||||
void split(float at, Line& left, Line& right) const;
|
||||
float length() const;
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Geometry functions */
|
||||
/************************************************************************/
|
||||
|
||||
struct BBox
|
||||
{
|
||||
Point min, max;
|
||||
|
||||
void init()
|
||||
{
|
||||
min = {FLT_MAX, FLT_MAX};
|
||||
max = {-FLT_MAX, -FLT_MAX};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static inline uint32_t arcSegmentsCnt(float arcAngle, float pixelRadius)
|
||||
{
|
||||
if (pixelRadius < FLOAT_EPSILON) return 2;
|
||||
static constexpr auto PX_TOLERANCE = 0.25f;
|
||||
// Sagitta-based formula Approximation: 1 - cos(θ/2) ≈ (θ/2)²/2, so θ ≈ 2 * sqrt(2 * s/r)
|
||||
auto segmentAngle = 2.0f * sqrtf(2.0f * PX_TOLERANCE / pixelRadius);
|
||||
return static_cast<uint32_t>(ceilf(fabsf(arcAngle) / segmentAngle)) + 1;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Bezier functions */
|
||||
/************************************************************************/
|
||||
|
||||
struct Bezier
|
||||
{
|
||||
Point start;
|
||||
Point ctrl1;
|
||||
Point ctrl2;
|
||||
Point end;
|
||||
|
||||
Bezier() {}
|
||||
Bezier(const Point& p0, const Point& p1, const Point& p2, const Point& p3):
|
||||
start(p0), ctrl1(p1), ctrl2(p2), end(p3) {}
|
||||
// Constructor that approximates a quarter-circle segment of arc between 'start' and 'end' points
|
||||
// using a cubic Bezier curve with a given 'radius'.
|
||||
Bezier(const Point& start, const Point& end, float radius);
|
||||
|
||||
void split(float t, Bezier& left);
|
||||
void split(Bezier& left, Bezier& right) const;
|
||||
void split(float at, Bezier& left, Bezier& right) const;
|
||||
float length() const;
|
||||
float lengthApprox() const;
|
||||
float at(float at, float length) const;
|
||||
float atApprox(float at, float length) const;
|
||||
Point at(float t) const;
|
||||
float angle(float t) const;
|
||||
bool flatten() const;
|
||||
uint32_t segments() const;
|
||||
|
||||
Bezier operator*(const Matrix& m);
|
||||
|
||||
static void bounds(BBox& box, const Point& start, const Point& ctrl1, const Point& ctrl2, const Point& end);
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Interpolation functions */
|
||||
/************************************************************************/
|
||||
|
||||
template <typename T>
|
||||
static inline T lerp(const T &start, const T &end, float t)
|
||||
{
|
||||
return static_cast<T>(start + (end - start) * t);
|
||||
}
|
||||
|
||||
uint8_t lerp(const uint8_t &start, const uint8_t &end, float t);
|
||||
|
||||
}
|
||||
|
||||
#endif //_TVG_MATH_H_
|
||||
279
components/thorvg-main/src/common/tvgStr.cpp
Normal file
279
components/thorvg-main/src/common/tvgStr.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <cmath>
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgMath.h"
|
||||
#include "tvgStr.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static inline bool _floatExact(float a, float b)
|
||||
{
|
||||
return memcmp(&a, &b, sizeof(float)) == 0;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
namespace tvg {
|
||||
|
||||
/*
|
||||
* https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strtof-strtof-l-wcstof-wcstof-l?view=msvc-160
|
||||
*
|
||||
* src should be one of the following form :
|
||||
*
|
||||
* [whitespace] [sign] {digits [radix digits] | radix digits} [{e | E} [sign] digits]
|
||||
* [whitespace] [sign] {INF | INFINITY}
|
||||
* [whitespace] [sign] NAN [sequence]
|
||||
*
|
||||
* No hexadecimal form supported
|
||||
* no sequence supported after NAN
|
||||
*/
|
||||
float toFloat(const char *str, char **end)
|
||||
{
|
||||
if (end) *end = (char *) (str);
|
||||
if (!str) return 0.0f;
|
||||
|
||||
auto a = str;
|
||||
auto iter = str;
|
||||
auto val = 0.0f;
|
||||
unsigned long long integerPart = 0;
|
||||
int minus = 1;
|
||||
|
||||
//ignore leading whitespaces
|
||||
while (isspace(*iter)) iter++;
|
||||
|
||||
//signed or not
|
||||
if (*iter == '-') {
|
||||
minus = -1;
|
||||
iter++;
|
||||
} else if (*iter == '+') {
|
||||
iter++;
|
||||
}
|
||||
|
||||
if (tolower(*iter) == 'i') {
|
||||
if ((tolower(*(iter + 1)) == 'n') && (tolower(*(iter + 2)) == 'f')) iter += 3;
|
||||
else goto error;
|
||||
|
||||
if (tolower(*(iter)) == 'i') {
|
||||
if ((tolower(*(iter + 1)) == 'n') && (tolower(*(iter + 2)) == 'i') && (tolower(*(iter + 3)) == 't') &&
|
||||
(tolower(*(iter + 4)) == 'y'))
|
||||
iter += 5;
|
||||
else goto error;
|
||||
}
|
||||
if (end) *end = (char *) (iter);
|
||||
return (minus == -1) ? -INFINITY : INFINITY;
|
||||
}
|
||||
|
||||
if (tolower(*iter) == 'n') {
|
||||
if ((tolower(*(iter + 1)) == 'a') && (tolower(*(iter + 2)) == 'n')) iter += 3;
|
||||
else goto error;
|
||||
|
||||
if (end) *end = (char *) (iter);
|
||||
return (minus == -1) ? -NAN : NAN;
|
||||
}
|
||||
|
||||
//Optional: integer part before dot
|
||||
if (isdigit(*iter)) {
|
||||
for (; isdigit(*iter); iter++) {
|
||||
integerPart = integerPart * 10ULL + (unsigned long long) (*iter - '0');
|
||||
}
|
||||
a = iter;
|
||||
} else if (*iter != '.') {
|
||||
goto success;
|
||||
}
|
||||
|
||||
val = static_cast<float>(integerPart);
|
||||
|
||||
//Optional: decimal part after dot
|
||||
if (*iter == '.') {
|
||||
unsigned long long decimalPart = 0;
|
||||
unsigned long long pow10 = 1;
|
||||
int count = 0;
|
||||
|
||||
iter++;
|
||||
|
||||
if (isdigit(*iter)) {
|
||||
for (; isdigit(*iter); iter++, count++) {
|
||||
if (count < 19) {
|
||||
decimalPart = decimalPart * 10ULL + +static_cast<unsigned long long>(*iter - '0');
|
||||
pow10 *= 10ULL;
|
||||
}
|
||||
}
|
||||
} else if (isspace(*iter)) { //skip if there is a space after the dot.
|
||||
a = iter;
|
||||
goto success;
|
||||
}
|
||||
|
||||
val += static_cast<float>(decimalPart) / static_cast<float>(pow10);
|
||||
a = iter;
|
||||
}
|
||||
|
||||
//Optional: exponent
|
||||
if (*iter == 'e' || *iter == 'E') {
|
||||
++iter;
|
||||
|
||||
//Exception: svg may have 'em' unit for fonts. ex) 5em, 10.5em
|
||||
if ((*iter == 'm') || (*iter == 'M')) {
|
||||
//TODO: We don't support font em unit now, but has to multiply val * font size later...
|
||||
a = iter + 1;
|
||||
goto success;
|
||||
}
|
||||
|
||||
//signed or not
|
||||
int minus_e = 1;
|
||||
|
||||
if (*iter == '-') {
|
||||
minus_e = -1;
|
||||
++iter;
|
||||
} else if (*iter == '+') {
|
||||
iter++;
|
||||
}
|
||||
|
||||
unsigned int exponentPart = 0;
|
||||
|
||||
if (isdigit(*iter)) {
|
||||
while (*iter == '0') iter++;
|
||||
for (; isdigit(*iter); iter++) {
|
||||
exponentPart = exponentPart * 10U + static_cast<unsigned int>(*iter - '0');
|
||||
}
|
||||
} else if (!isdigit(*(a - 1))) {
|
||||
a = str;
|
||||
goto success;
|
||||
} else if (*iter == 0) {
|
||||
goto success;
|
||||
}
|
||||
|
||||
//if ((_floatExact(val, 2.2250738585072011f)) && ((minus_e * static_cast<int>(exponentPart)) <= -308)) {
|
||||
if ((_floatExact(val, 1.175494351f)) && ((minus_e * static_cast<int>(exponentPart)) <= -38)) {
|
||||
//val *= 1.0e-308f;
|
||||
val *= 1.0e-38f;
|
||||
a = iter;
|
||||
goto success;
|
||||
}
|
||||
|
||||
a = iter;
|
||||
auto scale = 1.0f;
|
||||
|
||||
while (exponentPart >= 8U) {
|
||||
scale *= 1E8f;
|
||||
exponentPart -= 8U;
|
||||
}
|
||||
while (exponentPart > 0U) {
|
||||
scale *= 10.0f;
|
||||
exponentPart--;
|
||||
}
|
||||
val = (minus_e == -1) ? (val / scale) : (val * scale);
|
||||
} else if ((iter > str) && !isdigit(*(iter - 1))) {
|
||||
a = str;
|
||||
goto success;
|
||||
}
|
||||
|
||||
success:
|
||||
if (end) *end = (char *)a;
|
||||
if (!std::isfinite(val)) return 0.0f;
|
||||
|
||||
return minus * val;
|
||||
|
||||
error:
|
||||
if (end) *end = (char *)str;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
char* duplicate(const char *str, size_t n)
|
||||
{
|
||||
auto len = strlen(str);
|
||||
if (len < n) n = len;
|
||||
|
||||
auto ret = tvg::malloc<char>(n + 1);
|
||||
ret[n] = '\0';
|
||||
|
||||
return (char*)memcpy(ret, str, n);
|
||||
}
|
||||
|
||||
|
||||
char* append(char* lhs, const char* rhs, size_t n)
|
||||
{
|
||||
if (!rhs) return lhs;
|
||||
if (!lhs) return duplicate(rhs, n);
|
||||
lhs = tvg::realloc<char>(lhs, strlen(lhs) + n + 1);
|
||||
return strncat(lhs, rhs, n);
|
||||
}
|
||||
|
||||
|
||||
char* dirname(const char* path)
|
||||
{
|
||||
auto ptr = strrchr(path, '/');
|
||||
#ifdef _WIN32
|
||||
auto ptr2 = strrchr(ptr ? ptr : path, '\\');
|
||||
if (ptr2) ptr = ptr2;
|
||||
#endif
|
||||
auto len = ptr ? size_t(ptr - path + 1) : SIZE_MAX;
|
||||
return duplicate(path, len);
|
||||
}
|
||||
|
||||
|
||||
char* filename(const char* path)
|
||||
{
|
||||
const char* ptr = strrchr(path, '/');
|
||||
#ifdef _WIN32
|
||||
auto ptr2 = strrchr(ptr ? ptr : path, '\\');
|
||||
if (ptr2) ptr = ptr2;
|
||||
#endif
|
||||
if (ptr) ++ptr;
|
||||
else ptr = path;
|
||||
auto dot = fileext(ptr);
|
||||
auto len = (dot > ptr) ? (size_t)(dot - ptr - 1) : strlen(ptr);
|
||||
return duplicate(ptr, len);
|
||||
}
|
||||
|
||||
|
||||
const char* fileext(const char* path)
|
||||
{
|
||||
auto ext = path;
|
||||
while (ext) {
|
||||
auto p = strchr(ext, '.');
|
||||
if (!p) break;
|
||||
ext = p + 1;
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
char* concat(const char* a, const char* b)
|
||||
{
|
||||
auto len = strlen(a) + strlen(b) + 1;
|
||||
auto ret = tvg::malloc<char>(len * sizeof(char));
|
||||
strcpy(ret, a);
|
||||
strcat(ret, b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
45
components/thorvg-main/src/common/tvgStr.h
Normal file
45
components/thorvg-main/src/common/tvgStr.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_STR_H_
|
||||
#define _TVG_STR_H_
|
||||
|
||||
#include "tvgCommon.h"
|
||||
|
||||
namespace tvg
|
||||
{
|
||||
|
||||
static inline bool equal(const char* a, const char* b)
|
||||
{
|
||||
return !strcmp(a, b) && strlen(a) == strlen(b);
|
||||
}
|
||||
|
||||
char* concat(const char* a, const char* b);
|
||||
float toFloat(const char *str, char **end); //convert to float
|
||||
char* duplicate(const char *str, size_t n = SIZE_MAX); //copy the string
|
||||
char* append(char* lhs, const char* rhs, size_t n); //append the rhs to the lhs
|
||||
char* dirname(const char* path); //return the full directory name
|
||||
char* filename(const char* path); //return the file name without extension
|
||||
const char* fileext(const char* path); //return the file extension name
|
||||
|
||||
}
|
||||
#endif //_TVG_STR_H_
|
||||
18
components/thorvg-main/src/loaders/external_jpg/meson.build
Normal file
18
components/thorvg-main/src/loaders/external_jpg/meson.build
Normal file
@@ -0,0 +1,18 @@
|
||||
source_file = [
|
||||
'tvgJpgLoader.h',
|
||||
'tvgJpgLoader.cpp',
|
||||
]
|
||||
|
||||
jpg_dep = dependency('libturbojpeg', required: false)
|
||||
|
||||
if not jpg_dep.found()
|
||||
jpg_dep = cc.find_library('turbojpeg', required: false)
|
||||
endif
|
||||
|
||||
if jpg_dep.found()
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : jpg_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
endif
|
||||
135
components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.cpp
Normal file
135
components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <turbojpeg.h>
|
||||
#include "tvgJpgLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void JpgLoader::clear()
|
||||
{
|
||||
if (freeData) tvg::free(data);
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
JpgLoader::JpgLoader() : ImageLoader(FileType::Jpg)
|
||||
{
|
||||
jpegDecompressor = tjInitDecompress();
|
||||
}
|
||||
|
||||
|
||||
JpgLoader::~JpgLoader()
|
||||
{
|
||||
clear();
|
||||
tjDestroy(jpegDecompressor);
|
||||
|
||||
//This image is shared with raster engine.
|
||||
tjFree(surface.buf8);
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* path)
|
||||
{
|
||||
#ifdef THORVG_FILE_IO_SUPPORT
|
||||
if (!(data = (unsigned char*) LoadModule::open(path, size))) return false;
|
||||
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
freeData = true;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
||||
|
||||
if (copy) {
|
||||
this->data = tvg::malloc<unsigned char>(size);
|
||||
if (!this->data) return false;
|
||||
memcpy((unsigned char *)this->data, data, size);
|
||||
freeData = true;
|
||||
} else {
|
||||
this->data = (unsigned char *) data;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
this->size = size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
if (!LoadModule::read()) return true;
|
||||
|
||||
if (w == 0 || h == 0) return false;
|
||||
|
||||
//determine the image format
|
||||
TJPF format;
|
||||
if (ImageLoader::cs == ColorSpace::ARGB8888 || ImageLoader::cs == ColorSpace::ARGB8888S) {
|
||||
format = TJPF_BGRX;
|
||||
surface.cs = ColorSpace::ARGB8888;
|
||||
} else {
|
||||
format = TJPF_RGBX;
|
||||
surface.cs = ColorSpace::ABGR8888;
|
||||
}
|
||||
|
||||
auto image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[format]);
|
||||
if (!image) return false;
|
||||
|
||||
//decompress jpg image
|
||||
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), format, 0) < 0) {
|
||||
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
|
||||
tjFree(image);
|
||||
image = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
//setup the surface
|
||||
surface.buf8 = image;
|
||||
surface.stride = w;
|
||||
surface.w = w;
|
||||
surface.h = h;
|
||||
surface.channelSize = sizeof(uint32_t);
|
||||
surface.premultiplied = true;
|
||||
|
||||
clear();
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_JPG_LOADER_H_
|
||||
#define _TVG_JPG_LOADER_H_
|
||||
|
||||
#include "tvgLoader.h"
|
||||
|
||||
using tjhandle = void*;
|
||||
|
||||
//TODO: Use Task?
|
||||
class JpgLoader : public ImageLoader
|
||||
{
|
||||
public:
|
||||
JpgLoader();
|
||||
~JpgLoader();
|
||||
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
tjhandle jpegDecompressor;
|
||||
unsigned char* data = nullptr;
|
||||
uint32_t size = 0;
|
||||
bool freeData = false;
|
||||
};
|
||||
|
||||
#endif //_TVG_JPG_LOADER_H_
|
||||
14
components/thorvg-main/src/loaders/external_png/meson.build
Normal file
14
components/thorvg-main/src/loaders/external_png/meson.build
Normal file
@@ -0,0 +1,14 @@
|
||||
source_file = [
|
||||
'tvgPngLoader.h',
|
||||
'tvgPngLoader.cpp',
|
||||
]
|
||||
|
||||
png_dep = dependency('libpng', required: false)
|
||||
|
||||
if png_dep.found()
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : png_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
endif
|
||||
116
components/thorvg-main/src/loaders/external_png/tvgPngLoader.cpp
Normal file
116
components/thorvg-main/src/loaders/external_png/tvgPngLoader.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void PngLoader::clear()
|
||||
{
|
||||
png_image_free(image);
|
||||
tvg::free(image);
|
||||
image = nullptr;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
PngLoader::PngLoader() : ImageLoader(FileType::Png)
|
||||
{
|
||||
image = tvg::calloc<png_image>(1, sizeof(png_image));
|
||||
image->version = PNG_IMAGE_VERSION;
|
||||
image->opaque = nullptr;
|
||||
}
|
||||
|
||||
PngLoader::~PngLoader()
|
||||
{
|
||||
clear();
|
||||
tvg::free(surface.buf32);
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const char* path)
|
||||
{
|
||||
image->opaque = nullptr;
|
||||
|
||||
if (!png_image_begin_read_from_file(image, path)) return false;
|
||||
|
||||
w = (float)image->width;
|
||||
h = (float)image->height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
#ifdef THORVG_FILE_IO_SUPPORT
|
||||
image->opaque = nullptr;
|
||||
|
||||
if (!png_image_begin_read_from_memory(image, data, size)) return false;
|
||||
|
||||
w = (float)image->width;
|
||||
h = (float)image->height;
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::read()
|
||||
{
|
||||
if (!LoadModule::read()) return true;
|
||||
|
||||
if (w == 0 || h == 0) return false;
|
||||
|
||||
if (ImageLoader::cs == ColorSpace::ARGB8888 || ImageLoader::cs == ColorSpace::ARGB8888S) {
|
||||
image->format = PNG_FORMAT_BGRA;
|
||||
surface.cs = ColorSpace::ARGB8888S;
|
||||
} else {
|
||||
image->format = PNG_FORMAT_RGBA;
|
||||
surface.cs = ColorSpace::ABGR8888S;
|
||||
}
|
||||
|
||||
auto buffer = tvg::malloc<png_byte>(PNG_IMAGE_SIZE((*image)));
|
||||
if (!png_image_finish_read(image, NULL, buffer, 0, NULL)) {
|
||||
tvg::free(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
//setup the surface
|
||||
surface.buf32 = reinterpret_cast<uint32_t*>(buffer);
|
||||
surface.stride = (uint32_t)w;
|
||||
surface.w = (uint32_t)w;
|
||||
surface.h = (uint32_t)h;
|
||||
surface.channelSize = sizeof(uint32_t);
|
||||
//TODO: we can acquire a pre-multiplied image. See "png_structrp"
|
||||
surface.premultiplied = false;
|
||||
|
||||
clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_PNG_LOADER_H_
|
||||
#define _TVG_PNG_LOADER_H_
|
||||
|
||||
#include <png.h>
|
||||
#include "tvgLoader.h"
|
||||
|
||||
class PngLoader : public ImageLoader
|
||||
{
|
||||
public:
|
||||
PngLoader();
|
||||
~PngLoader();
|
||||
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
png_imagep image = nullptr;
|
||||
};
|
||||
|
||||
#endif //_TVG_PNG_LOADER_H_
|
||||
14
components/thorvg-main/src/loaders/external_webp/meson.build
Normal file
14
components/thorvg-main/src/loaders/external_webp/meson.build
Normal file
@@ -0,0 +1,14 @@
|
||||
source_file = [
|
||||
'tvgWebpLoader.h',
|
||||
'tvgWebpLoader.cpp',
|
||||
]
|
||||
|
||||
webp_dep = dependency('libwebp', required: false)
|
||||
|
||||
if webp_dep.found()
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : webp_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
endif
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
#include <webp/decode.h>
|
||||
|
||||
#include "tvgWebpLoader.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void WebpLoader::run(unsigned tid)
|
||||
{
|
||||
//TODO: acquire the current colorspace format & pre-multiplied alpha image.
|
||||
surface.buf8 = WebPDecodeBGRA(data, size, nullptr, nullptr);
|
||||
surface.stride = (uint32_t)w;
|
||||
surface.w = (uint32_t)w;
|
||||
surface.h = (uint32_t)h;
|
||||
surface.channelSize = sizeof(uint32_t);
|
||||
surface.cs = ColorSpace::ARGB8888;
|
||||
surface.premultiplied = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
WebpLoader::WebpLoader() : ImageLoader(FileType::Webp)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
WebpLoader::~WebpLoader()
|
||||
{
|
||||
done();
|
||||
|
||||
if (freeData) tvg::free(data);
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
freeData = false;
|
||||
WebPFree(surface.buf8);
|
||||
}
|
||||
|
||||
|
||||
bool WebpLoader::open(const char* path)
|
||||
{
|
||||
#ifdef THORVG_FILE_IO_SUPPORT
|
||||
if (!(data = (unsigned char*)LoadModule::open(path, size))) return false;
|
||||
|
||||
int width, height;
|
||||
if (!WebPGetInfo(data, size, &width, &height)) return false;
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
freeData = true;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
if (copy) {
|
||||
this->data = tvg::malloc<unsigned char>(size);
|
||||
if (!this->data) return false;
|
||||
memcpy((unsigned char *)this->data, data, size);
|
||||
freeData = true;
|
||||
} else {
|
||||
this->data = (unsigned char *) data;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if (!WebPGetInfo(this->data, size, &width, &height)) return false;
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
surface.cs = ColorSpace::ARGB8888;
|
||||
this->size = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WebpLoader::read()
|
||||
{
|
||||
if (!LoadModule::read()) return true;
|
||||
|
||||
if (!data || w == 0 || h == 0) return false;
|
||||
|
||||
TaskScheduler::request(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RenderSurface* WebpLoader::bitmap()
|
||||
{
|
||||
this->done();
|
||||
|
||||
return ImageLoader::bitmap();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_WEBP_LOADER_H_
|
||||
#define _TVG_WEBP_LOADER_H_
|
||||
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgTaskScheduler.h"
|
||||
|
||||
class WebpLoader : public ImageLoader, public Task
|
||||
{
|
||||
public:
|
||||
WebpLoader();
|
||||
~WebpLoader();
|
||||
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
RenderSurface* bitmap() override;
|
||||
|
||||
private:
|
||||
void run(unsigned tid) override;
|
||||
|
||||
unsigned char* data = nullptr;
|
||||
uint32_t size = 0;
|
||||
bool freeData = false;
|
||||
};
|
||||
|
||||
#endif //_TVG_WEBP_LOADER_H_
|
||||
11
components/thorvg-main/src/loaders/jpg/meson.build
Normal file
11
components/thorvg-main/src/loaders/jpg/meson.build
Normal file
@@ -0,0 +1,11 @@
|
||||
source_file = [
|
||||
'tvgJpgd.h',
|
||||
'tvgJpgLoader.h',
|
||||
'tvgJpgd.cpp',
|
||||
'tvgJpgLoader.cpp',
|
||||
]
|
||||
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
sources : source_file
|
||||
)]
|
||||
135
components/thorvg-main/src/loaders/jpg/tvgJpgLoader.cpp
Normal file
135
components/thorvg-main/src/loaders/jpg/tvgJpgLoader.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tvgJpgLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void JpgLoader::clear()
|
||||
{
|
||||
jpgdDelete(decoder);
|
||||
if (freeData) tvg::free(data);
|
||||
decoder = nullptr;
|
||||
data = nullptr;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
|
||||
void JpgLoader::run(unsigned tid)
|
||||
{
|
||||
surface.cs = ImageLoader::cs;
|
||||
surface.buf8 = jpgdDecompress(decoder, surface.cs);
|
||||
surface.stride = static_cast<uint32_t>(w);
|
||||
surface.w = static_cast<uint32_t>(w);
|
||||
surface.h = static_cast<uint32_t>(h);
|
||||
surface.channelSize = sizeof(uint32_t);
|
||||
surface.premultiplied = true;
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
JpgLoader::JpgLoader() : ImageLoader(FileType::Jpg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
JpgLoader::~JpgLoader()
|
||||
{
|
||||
done();
|
||||
clear();
|
||||
tvg::free(surface.buf8);
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* path)
|
||||
{
|
||||
#ifdef THORVG_FILE_IO_SUPPORT
|
||||
int width, height;
|
||||
if (!(decoder = jpgdHeader(path, &width, &height))) return false;
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
if (copy) {
|
||||
this->data = tvg::malloc<char>(size);
|
||||
if (!this->data) return false;
|
||||
memcpy((char *)this->data, data, size);
|
||||
freeData = true;
|
||||
} else {
|
||||
this->data = (char *) data;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
decoder = jpgdHeader(this->data, size, &width, &height);
|
||||
if (!decoder) return false;
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
if (!LoadModule::read()) return true;
|
||||
|
||||
if (!decoder || w == 0 || h == 0) return false;
|
||||
|
||||
TaskScheduler::request(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::close()
|
||||
{
|
||||
if (!LoadModule::close()) return false;
|
||||
this->done();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RenderSurface* JpgLoader::bitmap()
|
||||
{
|
||||
this->done();
|
||||
return ImageLoader::bitmap();
|
||||
}
|
||||
52
components/thorvg-main/src/loaders/jpg/tvgJpgLoader.h
Normal file
52
components/thorvg-main/src/loaders/jpg/tvgJpgLoader.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_JPG_LOADER_H_
|
||||
#define _TVG_JPG_LOADER_H_
|
||||
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgTaskScheduler.h"
|
||||
#include "tvgJpgd.h"
|
||||
|
||||
class JpgLoader : public ImageLoader, public Task
|
||||
{
|
||||
private:
|
||||
jpeg_decoder* decoder = nullptr;
|
||||
char* data = nullptr;
|
||||
bool freeData = false;
|
||||
|
||||
void clear();
|
||||
void run(unsigned tid) override;
|
||||
|
||||
public:
|
||||
JpgLoader();
|
||||
~JpgLoader();
|
||||
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
RenderSurface* bitmap() override;
|
||||
};
|
||||
|
||||
#endif //_TVG_JPG_LOADER_H_
|
||||
2520
components/thorvg-main/src/loaders/jpg/tvgJpgd.cpp
Normal file
2520
components/thorvg-main/src/loaders/jpg/tvgJpgd.cpp
Normal file
File diff suppressed because it is too large
Load Diff
35
components/thorvg-main/src/loaders/jpg/tvgJpgd.h
Normal file
35
components/thorvg-main/src/loaders/jpg/tvgJpgd.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2021 - 2026 ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
// jpgd.h - C++ class for JPEG decompression.
|
||||
// Public domain, Rich Geldreich <richgel99@gmail.com>
|
||||
#ifndef _TVG_JPGD_H_
|
||||
#define _TVG_JPGD_H_
|
||||
|
||||
class jpeg_decoder;
|
||||
|
||||
jpeg_decoder* jpgdHeader(const char* data, int size, int* width, int* height);
|
||||
jpeg_decoder* jpgdHeader(const char* filename, int* width, int* height);
|
||||
unsigned char* jpgdDecompress(jpeg_decoder* decoder, ColorSpace cs);
|
||||
void jpgdDelete(jpeg_decoder* decoder);
|
||||
|
||||
#endif //_TVG_JPGD_H_
|
||||
@@ -0,0 +1,634 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "ecma-eval.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-init-finalize.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "jcontext.h"
|
||||
|
||||
/** \addtogroup jerry Jerry engine interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Turn on API availability
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static inline void
|
||||
jerry_api_enable (void)
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_ENABLED;
|
||||
#endif /* JERRY_NDEBUG */
|
||||
} /* jerry_make_api_available */
|
||||
|
||||
/**
|
||||
* Turn off API availability
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static inline void
|
||||
jerry_api_disable (void)
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_API_ENABLED;
|
||||
#endif /* JERRY_NDEBUG */
|
||||
} /* jerry_make_api_unavailable */
|
||||
|
||||
/**
|
||||
* Create an API compatible return value.
|
||||
*
|
||||
* @return return value for Jerry API functions
|
||||
*/
|
||||
static jerry_value_t
|
||||
jerry_return (const jerry_value_t value) /**< return value */
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return ecma_create_exception_from_context ();
|
||||
}
|
||||
|
||||
return value;
|
||||
} /* jerry_return */
|
||||
|
||||
/**
|
||||
* Jerry engine initialization
|
||||
*/
|
||||
void
|
||||
jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */
|
||||
{
|
||||
#if JERRY_EXTERNAL_CONTEXT
|
||||
size_t total_size = jerry_port_context_alloc (sizeof (jerry_context_t));
|
||||
JERRY_UNUSED (total_size);
|
||||
#endif /* JERRY_EXTERNAL_CONTEXT */
|
||||
|
||||
jerry_context_t *context_p = &JERRY_CONTEXT_STRUCT;
|
||||
memset (context_p, 0, sizeof (jerry_context_t));
|
||||
|
||||
#if JERRY_EXTERNAL_CONTEXT && !JERRY_SYSTEM_ALLOCATOR
|
||||
uint32_t heap_start_offset = JERRY_ALIGNUP (sizeof (jerry_context_t), JMEM_ALIGNMENT);
|
||||
uint8_t *heap_p = ((uint8_t *) context_p) + heap_start_offset;
|
||||
uint32_t heap_size = JERRY_ALIGNDOWN (total_size - heap_start_offset, JMEM_ALIGNMENT);
|
||||
|
||||
JERRY_ASSERT (heap_p + heap_size <= ((uint8_t *) context_p) + total_size);
|
||||
|
||||
context_p->heap_p = (jmem_heap_t *) heap_p;
|
||||
context_p->heap_size = heap_size;
|
||||
#endif /* JERRY_EXTERNAL_CONTEXT && !JERRY_SYSTEM_ALLOCATOR */
|
||||
|
||||
JERRY_CONTEXT (jerry_init_flags) = flags;
|
||||
|
||||
jerry_api_enable ();
|
||||
|
||||
jmem_init ();
|
||||
ecma_init ();
|
||||
} /* jerry_init */
|
||||
|
||||
/**
|
||||
* Terminate Jerry engine
|
||||
*/
|
||||
void
|
||||
jerry_cleanup (void)
|
||||
{
|
||||
for (jerry_context_data_header_t *this_p = JERRY_CONTEXT (context_data_p); this_p != NULL; this_p = this_p->next_p)
|
||||
{
|
||||
if (this_p->manager_p->deinit_cb)
|
||||
{
|
||||
void *data = (this_p->manager_p->bytes_needed > 0) ? JERRY_CONTEXT_DATA_HEADER_USER_DATA (this_p) : NULL;
|
||||
this_p->manager_p->deinit_cb (data);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_free_all_enqueued_jobs ();
|
||||
ecma_finalize ();
|
||||
jerry_api_disable ();
|
||||
|
||||
for (jerry_context_data_header_t *this_p = JERRY_CONTEXT (context_data_p), *next_p = NULL; this_p != NULL;
|
||||
this_p = next_p)
|
||||
{
|
||||
next_p = this_p->next_p;
|
||||
|
||||
if (this_p->manager_p->finalize_cb)
|
||||
{
|
||||
void *data = (this_p->manager_p->bytes_needed > 0) ? JERRY_CONTEXT_DATA_HEADER_USER_DATA (this_p) : NULL;
|
||||
this_p->manager_p->finalize_cb (data);
|
||||
}
|
||||
|
||||
jmem_heap_free_block (this_p, sizeof (jerry_context_data_header_t) + this_p->manager_p->bytes_needed);
|
||||
}
|
||||
|
||||
jmem_finalize ();
|
||||
#if JERRY_EXTERNAL_CONTEXT
|
||||
jerry_port_context_free ();
|
||||
#endif /* JERRY_EXTERNAL_CONTEXT */
|
||||
} /* jerry_cleanup */
|
||||
|
||||
/**
|
||||
* Perform eval
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return result of eval, may be error value.
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_eval (const jerry_char_t *source_p, /**< source code */
|
||||
size_t source_size, /**< length of source code */
|
||||
uint32_t flags) /**< jerry_parse_opts_t flags */
|
||||
{
|
||||
parser_source_char_t source_char;
|
||||
source_char.source_p = source_p;
|
||||
source_char.source_size = source_size;
|
||||
|
||||
return jerry_return (ecma_op_eval_chars_buffer ((void *) &source_char, flags));
|
||||
} /* jerry_eval */
|
||||
|
||||
/**
|
||||
* Get global object
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return api value of global object
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_current_realm (void)
|
||||
{
|
||||
ecma_object_t *global_obj_p = ecma_builtin_get_global ();
|
||||
ecma_ref_object (global_obj_p);
|
||||
return ecma_make_object_value (global_obj_p);
|
||||
} /* jerry_current_realm */
|
||||
|
||||
/**
|
||||
* Check if the specified value is an error or abort value.
|
||||
*
|
||||
* @return true - if the specified value is an error value,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_exception (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
return ecma_is_value_exception (value);
|
||||
} /* jerry_value_is_exception */
|
||||
|
||||
/**
|
||||
* Check if the specified value is number.
|
||||
*
|
||||
* @return true - if the specified value is number,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_number (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
return ecma_is_value_number (value);
|
||||
} /* jerry_value_is_number */
|
||||
|
||||
/**
|
||||
* Check if the specified value is object.
|
||||
*
|
||||
* @return true - if the specified value is object,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_object (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
return ecma_is_value_object (value);
|
||||
} /* jerry_value_is_object */
|
||||
|
||||
/**
|
||||
* Check if the specified value is string.
|
||||
*
|
||||
* @return true - if the specified value is string,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_string (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
return ecma_is_value_string (value);
|
||||
} /* jerry_value_is_string */
|
||||
|
||||
/**
|
||||
* Check if the specified value is undefined.
|
||||
*
|
||||
* @return true - if the specified value is undefined,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_value_is_undefined (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
return ecma_is_value_undefined (value);
|
||||
} /* jerry_value_is_undefined */
|
||||
|
||||
/**
|
||||
* Get number from the specified value as a double.
|
||||
*
|
||||
* @return stored number as double
|
||||
*/
|
||||
float
|
||||
jerry_value_as_number (const jerry_value_t value) /**< api value */
|
||||
{
|
||||
return (float) ecma_get_number_from_value (value);
|
||||
} /* jerry_value_as_number */
|
||||
|
||||
/**
|
||||
* Call ToObject operation on the api value.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return converted object value - if success
|
||||
* thrown error - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_value_to_object (const jerry_value_t value) /**< input value */
|
||||
{
|
||||
return jerry_return (ecma_op_to_object (value));
|
||||
} /* jerry_value_to_object */
|
||||
|
||||
/**
|
||||
* Call the ToString ecma builtin operation on the api value.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return converted string value - if success
|
||||
* thrown error - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_value_to_string (const jerry_value_t value) /**< input value */
|
||||
{
|
||||
ecma_string_t *str_p = ecma_op_to_string (value);
|
||||
return ecma_make_string_value (str_p);
|
||||
} /* jerry_value_to_string */
|
||||
|
||||
/**
|
||||
* Convert any number to int32 number.
|
||||
*
|
||||
* Note:
|
||||
* For non-number values 0 is returned.
|
||||
*
|
||||
* @return int32 representation of the number.
|
||||
*/
|
||||
int32_t
|
||||
jerry_value_as_int32 (const jerry_value_t value) /**< input value */
|
||||
{
|
||||
return ecma_number_to_int32 (ecma_get_number_from_value (value));
|
||||
} /* jerry_value_as_int32 */
|
||||
|
||||
/**
|
||||
* Convert any number to uint32 number.
|
||||
*
|
||||
* Note:
|
||||
* For non-number values 0 is returned.
|
||||
*
|
||||
* @return uint32 representation of the number.
|
||||
*/
|
||||
uint32_t
|
||||
jerry_value_as_uint32 (const jerry_value_t value) /**< input value */
|
||||
{
|
||||
return ecma_number_to_uint32 (ecma_get_number_from_value (value));
|
||||
} /* jerry_value_as_uint32 */
|
||||
|
||||
/**
|
||||
* Release ownership of the argument value
|
||||
*/
|
||||
void
|
||||
jerry_value_free (jerry_value_t value) /**< value */
|
||||
{
|
||||
ecma_free_value (value);
|
||||
} /* jerry_value_free */
|
||||
|
||||
/**
|
||||
* Create a jerry_value_t representing a boolean value from the given boolean parameter.
|
||||
*
|
||||
* @return value of the created boolean
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_boolean (bool value) /**< bool value from which a jerry_value_t will be created */
|
||||
{
|
||||
return ecma_make_boolean_value (value);
|
||||
} /* jerry_boolean */
|
||||
|
||||
/**
|
||||
* Create an external function object
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return value of the constructed function object
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_function_external (jerry_external_handler_t handler) /**< native handler
|
||||
* for the function */
|
||||
{
|
||||
ecma_object_t *func_obj_p = ecma_op_create_external_function_object (handler);
|
||||
return ecma_make_object_value (func_obj_p);
|
||||
} /* jerry_function_external */
|
||||
|
||||
/**
|
||||
* Creates a jerry_value_t representing a number value.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return jerry_value_t created from the given double argument.
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_number (float value) /**< double value from which a jerry_value_t will be created */
|
||||
{
|
||||
return ecma_make_number_value ((ecma_number_t) value);
|
||||
} /* jerry_number */
|
||||
|
||||
/**
|
||||
* Creates a jerry_value_t representing an undefined value.
|
||||
*
|
||||
* @return value of undefined
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_undefined (void)
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
} /* jerry_undefined */
|
||||
|
||||
/**
|
||||
* Create new JavaScript object, like with new Object().
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return value of the created object
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object (void)
|
||||
{
|
||||
return ecma_make_object_value (ecma_op_create_object_object_noarg ());
|
||||
} /* jerry_object */
|
||||
|
||||
/**
|
||||
* Create string value from the input zero-terminated ASCII string.
|
||||
*
|
||||
* @return created string
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_string_sz (const char *str_p) /**< pointer to string */
|
||||
{
|
||||
const jerry_char_t *data_p = (const jerry_char_t *) str_p;
|
||||
return jerry_string (data_p, lit_zt_utf8_string_size (data_p), JERRY_ENCODING_CESU8);
|
||||
} /* jerry_string_sz */
|
||||
|
||||
/**
|
||||
* Create a string value from the input buffer using the specified encoding.
|
||||
* The content of the buffer is assumed to be valid in the specified encoding, it's the callers responsibility to
|
||||
* validate the input.
|
||||
*
|
||||
* See also: jerry_validate_string
|
||||
*
|
||||
* @return created string
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_string (const jerry_char_t *buffer_p, /**< pointer to buffer */
|
||||
jerry_size_t buffer_size, /**< buffer size */
|
||||
jerry_encoding_t encoding) /**< buffer encoding */
|
||||
{
|
||||
ecma_string_t *ecma_str_p = NULL;
|
||||
//JERRY_ASSERT (jerry_validate_string (buffer_p, buffer_size, encoding));
|
||||
|
||||
switch (encoding)
|
||||
{
|
||||
case JERRY_ENCODING_CESU8:
|
||||
{
|
||||
ecma_str_p = ecma_new_ecma_string_from_utf8 (buffer_p, buffer_size);
|
||||
break;
|
||||
}
|
||||
case JERRY_ENCODING_UTF8:
|
||||
{
|
||||
ecma_str_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (buffer_p, buffer_size);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return jerry_undefined();
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_string_value (ecma_str_p);
|
||||
} /* jerry_string */
|
||||
|
||||
/**
|
||||
* Get length of a string value
|
||||
*
|
||||
* @return number of characters in the string
|
||||
* 0 - if value is not a string
|
||||
*/
|
||||
jerry_length_t
|
||||
jerry_string_length (const jerry_value_t value) /**< input string */
|
||||
{
|
||||
return ecma_string_get_length (ecma_get_string_from_value (value));
|
||||
} /* jerry_string_length */
|
||||
|
||||
/**
|
||||
* Copy the characters of a string into the specified buffer using the specified encoding. The string is truncated to
|
||||
* fit the buffer. If the value is not a string, nothing will be copied to the buffer.
|
||||
*
|
||||
* @return number of bytes copied to the buffer
|
||||
*/
|
||||
jerry_size_t
|
||||
jerry_string_to_buffer (const jerry_value_t value, /**< input string value */
|
||||
jerry_encoding_t encoding, /**< output encoding */
|
||||
jerry_char_t *buffer_p, /**< [out] output characters buffer */
|
||||
jerry_size_t buffer_size) /**< size of output buffer */
|
||||
{
|
||||
ecma_string_t *str_p = ecma_get_string_from_value (value);
|
||||
return ecma_string_copy_to_buffer (str_p, (lit_utf8_byte_t *) buffer_p, buffer_size, encoding);
|
||||
} /* jerry_string_to_char_buffer */
|
||||
|
||||
/**
|
||||
* Get value of a property to the specified object with the given name.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return value of the property - if success
|
||||
* value marked with error flag - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object_get (const jerry_value_t object, /**< object value */
|
||||
const jerry_value_t key) /**< property name (string value) */
|
||||
{
|
||||
jerry_value_t ret_value = ecma_op_object_get (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key));
|
||||
return jerry_return (ret_value);
|
||||
} /* jerry_object_get */
|
||||
|
||||
/**
|
||||
* Get value of a property to the specified object with the given name.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return value of the property - if success
|
||||
* value marked with error flag - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object_get_sz (const jerry_value_t object, /**< object value */
|
||||
const char *key_p) /**< property key */
|
||||
{
|
||||
jerry_value_t key_str = jerry_string_sz (key_p);
|
||||
jerry_value_t result = jerry_object_get (object, key_str);
|
||||
ecma_free_value (key_str);
|
||||
return result;
|
||||
} /* jerry_object_get */
|
||||
|
||||
/**
|
||||
* Get value by an index from the specified object.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return value of the property specified by the index - if success
|
||||
* value marked with error flag - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object_get_index (const jerry_value_t object, /**< object value */
|
||||
uint32_t index) /**< index to be written */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_op_object_get_by_index (ecma_get_object_from_value (object), index);
|
||||
return jerry_return (ret_value);
|
||||
} /* jerry_object_get_index */
|
||||
|
||||
/**
|
||||
* Set a property to the specified object with the given name.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return true value - if the operation was successful
|
||||
* value marked with error flag - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object_set (jerry_value_t object, /**< object value */
|
||||
const jerry_value_t key, /**< property name (string value) */
|
||||
const jerry_value_t value) /**< value to set */
|
||||
{
|
||||
return jerry_return (ecma_op_object_put (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key), value, true));
|
||||
} /* jerry_object_set */
|
||||
|
||||
/**
|
||||
* Set a property to the specified object with the given name.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return true value - if the operation was successful
|
||||
* value marked with error flag - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object_set_sz (jerry_value_t object, /**< object value */
|
||||
const char *key_p, /**< property key */
|
||||
const jerry_value_t value) /**< value to set */
|
||||
{
|
||||
jerry_value_t key_str = jerry_string_sz (key_p);
|
||||
jerry_value_t result = jerry_object_set (object, key_str, value);
|
||||
ecma_free_value (key_str);
|
||||
return result;
|
||||
} /* jerry_object_set */
|
||||
|
||||
/**
|
||||
* Set indexed value in the specified object
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_value_free, when it is no longer needed.
|
||||
*
|
||||
* @return true value - if the operation was successful
|
||||
* value marked with error flag - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_object_set_index (jerry_value_t object, /**< object value */
|
||||
uint32_t index, /**< index to be written */
|
||||
const jerry_value_t value) /**< value to set */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_op_object_put_by_index (ecma_get_object_from_value (object), index, value, true);
|
||||
return jerry_return (ret_value);
|
||||
} /* jerry_object_set_index */
|
||||
|
||||
/**
|
||||
* Get native pointer and its type information, associated with the given native type info.
|
||||
*
|
||||
* Note:
|
||||
* If native pointer is present, its type information is returned in out_native_pointer_p
|
||||
*
|
||||
* @return found native pointer,
|
||||
* or NULL
|
||||
*/
|
||||
void *
|
||||
jerry_object_get_native_ptr (const jerry_value_t object, /**< object to get native pointer from */
|
||||
const jerry_object_native_info_t *native_info_p) /**< the type info
|
||||
* of the native pointer */
|
||||
{
|
||||
if (!ecma_is_value_object (object))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (object);
|
||||
ecma_native_pointer_t *native_pointer_p = ecma_get_native_pointer_value (obj_p, (jerry_object_native_info_t *) native_info_p);
|
||||
|
||||
if (native_pointer_p == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return native_pointer_p->native_p;
|
||||
} /* jerry_object_get_native_ptr */
|
||||
|
||||
/**
|
||||
* Set native pointer and an optional type info for the specified object.
|
||||
*
|
||||
*
|
||||
* Note:
|
||||
* If native pointer was already set for the object, its value is updated.
|
||||
*
|
||||
* Note:
|
||||
* If a non-NULL free callback is specified in the native type info,
|
||||
* it will be called by the garbage collector when the object is freed.
|
||||
* Referred values by this method must have at least 1 reference. (Correct API usage satisfies this condition)
|
||||
* The type info always overwrites the previous value, so passing
|
||||
* a NULL value deletes the current type info.
|
||||
*/
|
||||
void
|
||||
jerry_object_set_native_ptr (jerry_value_t object, /**< object to set native pointer in */
|
||||
const jerry_object_native_info_t *native_info_p, /**< object's native type info */
|
||||
void *native_pointer_p) /**< native pointer */
|
||||
{
|
||||
if (ecma_is_value_object (object))
|
||||
{
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (object);
|
||||
|
||||
ecma_create_native_pointer_property (object_p, native_pointer_p, native_info_p);
|
||||
}
|
||||
} /* jerry_object_set_native_ptr */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,8 @@
|
||||
source_file = [
|
||||
'jerryscript.cpp'
|
||||
]
|
||||
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
sources : source_file
|
||||
)]
|
||||
@@ -0,0 +1,232 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#include "jmem.h"
|
||||
#include "jrt.h"
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (ecma_property_value_t) == sizeof (ecma_value_t)),
|
||||
size_of_ecma_property_value_t_must_be_equal_to_size_of_ecma_value_t);
|
||||
JERRY_STATIC_ASSERT (((sizeof (ecma_property_value_t) - 1) & sizeof (ecma_property_value_t)) == 0,
|
||||
size_of_ecma_property_value_t_must_be_power_of_2);
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <= sizeof (uint64_t)),
|
||||
size_of_ecma_extended_object_part_must_be_less_than_or_equal_to_8_bytes);
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of routines for allocation/freeing memory for ECMA data types.
|
||||
*
|
||||
* All allocation routines from this module have the same structure:
|
||||
* 1. Try to allocate memory.
|
||||
* 2. If allocation was successful, return pointer to the allocated block.
|
||||
* 3. Run garbage collection.
|
||||
* 4. Try to allocate memory.
|
||||
* 5. If allocation was successful, return pointer to the allocated block;
|
||||
* else - shutdown engine.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-number
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_number_t *
|
||||
ecma_alloc_number (void)
|
||||
{
|
||||
return (ecma_number_t *) jmem_pools_alloc (sizeof (ecma_number_t));
|
||||
} /* ecma_alloc_number */
|
||||
|
||||
/**
|
||||
* Dealloc memory from an ecma-number
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_number (ecma_number_t *number_p) /**< number to be freed */
|
||||
{
|
||||
jmem_pools_free ((uint8_t *) number_p, sizeof (ecma_number_t));
|
||||
} /* ecma_dealloc_number */
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-object
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_alloc_object (void)
|
||||
{
|
||||
return (ecma_object_t *) jmem_pools_alloc (sizeof (ecma_object_t));
|
||||
} /* ecma_alloc_object */
|
||||
|
||||
/**
|
||||
* Dealloc memory from an ecma-object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_object (ecma_object_t *object_p) /**< object to be freed */
|
||||
{
|
||||
jmem_pools_free (object_p, sizeof (ecma_object_t));
|
||||
} /* ecma_dealloc_object */
|
||||
|
||||
/**
|
||||
* Allocate memory for extended object
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_extended_object_t *
|
||||
ecma_alloc_extended_object (size_t size) /**< size of object */
|
||||
{
|
||||
return (ecma_extended_object_t *) jmem_heap_alloc_block (size);
|
||||
} /* ecma_alloc_extended_object */
|
||||
|
||||
/**
|
||||
* Dealloc memory of an extended object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_extended_object (ecma_object_t *object_p, /**< extended object */
|
||||
size_t size) /**< size of object */
|
||||
{
|
||||
jmem_heap_free_block (object_p, size);
|
||||
} /* ecma_dealloc_extended_object */
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-string descriptor
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_alloc_string (void)
|
||||
{
|
||||
return (ecma_string_t *) jmem_pools_alloc (sizeof (ecma_string_t));
|
||||
} /* ecma_alloc_string */
|
||||
|
||||
/**
|
||||
* Dealloc memory from ecma-string descriptor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_string (ecma_string_t *string_p) /**< string to be freed */
|
||||
{
|
||||
jmem_pools_free (string_p, sizeof (ecma_string_t));
|
||||
} /* ecma_dealloc_string */
|
||||
|
||||
/**
|
||||
* Allocate memory for extended ecma-string descriptor
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_extended_string_t *
|
||||
ecma_alloc_extended_string (void)
|
||||
{
|
||||
return (ecma_extended_string_t *) jmem_heap_alloc_block (sizeof (ecma_extended_string_t));
|
||||
} /* ecma_alloc_extended_string */
|
||||
|
||||
/**
|
||||
* Dealloc memory from extended ecma-string descriptor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_extended_string (ecma_extended_string_t *ext_string_p) /**< extended string to be freed */
|
||||
{
|
||||
jmem_heap_free_block (ext_string_p, sizeof (ecma_extended_string_t));
|
||||
} /* ecma_dealloc_extended_string */
|
||||
|
||||
/**
|
||||
* Allocate memory for external ecma-string descriptor
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_external_string_t *
|
||||
ecma_alloc_external_string (void)
|
||||
{
|
||||
return (ecma_external_string_t *) jmem_heap_alloc_block (sizeof (ecma_external_string_t));
|
||||
} /* ecma_alloc_external_string */
|
||||
|
||||
/**
|
||||
* Dealloc memory from external ecma-string descriptor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_external_string (ecma_external_string_t *ext_string_p) /**< external string to be freed */
|
||||
{
|
||||
jmem_heap_free_block (ext_string_p, sizeof (ecma_external_string_t));
|
||||
} /* ecma_dealloc_external_string */
|
||||
|
||||
/**
|
||||
* Allocate memory for an string with character data
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_alloc_string_buffer (size_t size) /**< size of string */
|
||||
{
|
||||
return (ecma_string_t *) jmem_heap_alloc_block (size);
|
||||
} /* ecma_alloc_string_buffer */
|
||||
|
||||
/**
|
||||
* Dealloc memory of a string with character data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_string_buffer (ecma_string_t *string_p, /**< string with data */
|
||||
size_t size) /**< size of string */
|
||||
{
|
||||
jmem_heap_free_block (string_p, size);
|
||||
} /* ecma_dealloc_string_buffer */
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-property pair
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_property_pair_t *
|
||||
ecma_alloc_property_pair (void)
|
||||
{
|
||||
return (ecma_property_pair_t *) jmem_heap_alloc_block (sizeof (ecma_property_pair_t));
|
||||
} /* ecma_alloc_property_pair */
|
||||
|
||||
/**
|
||||
* Dealloc memory of an ecma-property
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p) /**< property pair to be freed */
|
||||
{
|
||||
jmem_heap_free_block (property_pair_p, sizeof (ecma_property_pair_t));
|
||||
} /* ecma_dealloc_property_pair */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,129 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_ALLOC_H
|
||||
#define ECMA_ALLOC_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-object
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_object_t *ecma_alloc_object (void);
|
||||
|
||||
/**
|
||||
* Dealloc memory from an ecma-object
|
||||
*/
|
||||
void ecma_dealloc_object (ecma_object_t *object_p);
|
||||
|
||||
/**
|
||||
* Allocate memory for extended object
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_extended_object_t *ecma_alloc_extended_object (size_t size);
|
||||
|
||||
/**
|
||||
* Dealloc memory of an extended object
|
||||
*/
|
||||
void ecma_dealloc_extended_object (ecma_object_t *object_p, size_t size);
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-number
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_number_t *ecma_alloc_number (void);
|
||||
|
||||
/**
|
||||
* Dealloc memory from an ecma-number
|
||||
*/
|
||||
void ecma_dealloc_number (ecma_number_t *number_p);
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-string descriptor
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_string_t *ecma_alloc_string (void);
|
||||
|
||||
/**
|
||||
* Dealloc memory from ecma-string descriptor
|
||||
*/
|
||||
void ecma_dealloc_string (ecma_string_t *string_p);
|
||||
|
||||
/**
|
||||
* Allocate memory for extended ecma-string descriptor
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_extended_string_t *ecma_alloc_extended_string (void);
|
||||
|
||||
/**
|
||||
* Dealloc memory from extended ecma-string descriptor
|
||||
*/
|
||||
void ecma_dealloc_extended_string (ecma_extended_string_t *string_p);
|
||||
|
||||
/**
|
||||
* Allocate memory for external ecma-string descriptor
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_external_string_t *ecma_alloc_external_string (void);
|
||||
|
||||
/**
|
||||
* Dealloc memory from external ecma-string descriptor
|
||||
*/
|
||||
void ecma_dealloc_external_string (ecma_external_string_t *string_p);
|
||||
|
||||
/**
|
||||
* Allocate memory for string with character data
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_string_t *ecma_alloc_string_buffer (size_t size);
|
||||
|
||||
/**
|
||||
* Dealloc memory of a string with character data
|
||||
*/
|
||||
void ecma_dealloc_string_buffer (ecma_string_t *string_p, size_t size);
|
||||
|
||||
/**
|
||||
* Allocate memory for ecma-property pair
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_property_pair_t *ecma_alloc_property_pair (void);
|
||||
|
||||
/**
|
||||
* Dealloc memory from an ecma-property pair
|
||||
*/
|
||||
void ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_ALLOC_H */
|
||||
@@ -0,0 +1,743 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* This file is automatically generated by the gen-strings.py script
|
||||
* from ecma-error-messages.ini. Do not edit! */
|
||||
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_GROUP, "Invalid group")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ESCAPE, "Invalid escape")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_ATOMICS || JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_LENGTH, "Invalid length")
|
||||
#endif /* JERRY_BUILTIN_ATOMICS \
|
||||
|| JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_OFFSET, "Invalid offset")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_OBJECT_EXPECTED, "Object expected")
|
||||
#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARGUMENT, "Invalid argument")
|
||||
#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ENCODING, "Invalid encoding")
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_NOTHING_TO_REPEAT, "Nothing to repeat")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_AN_OBJECT, "Expected an object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_CAPABILITY, "Invalid capability")
|
||||
#if JERRY_BUILTIN_STRING
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_CODE_POINT, "Invalid code point")
|
||||
#endif /* JERRY_BUILTIN_STRING */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_QUANTIFIER, "Invalid quantifier")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_NO_SOURCE_ARGUMENT, "No source argument")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNTERMINATED_GROUP, "Unterminated group")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_FUNCTION, "Expected a function")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_UTF8_STRING, "Invalid UTF8 string")
|
||||
#if JERRY_BUILTIN_STRING
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_COUNT_VALUE, "Invalid count value")
|
||||
#endif /* JERRY_BUILTIN_STRING */
|
||||
#if !(JERRY_BUILTIN_REALMS)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REALMS_ARE_DISABLED, "Realms are disabled")
|
||||
#endif /* !(JERRY_BUILTIN_REALMS) */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNDEFINED_REFERENCE, "Undefined reference")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARRAY_LENGTH, "Invalid Array length")
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_REGEXP_FLAGS, "Invalid RegExp flags")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_STACK_LIMIT_EXCEEDED, "Stack limit exceeded")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_WEAKREF
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_IS_NOT_OBJECT, "Target is not Object")
|
||||
#endif /* JERRY_BUILTIN_WEAKREF */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BIGINT_VALUE_EXPECTED, "BigInt value expected")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BINDING_CANNOT_SET, "Binding cannot be set")
|
||||
#if JERRY_BUILTIN_STRING
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_STRING_, "Invalid string length")
|
||||
#endif /* JERRY_BUILTIN_STRING */
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_KEY_MUST_BE_AN_OBJECT, "Key must be an object")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MISSING_ARRAY_ELEMENT, "Missing Array element")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
#if JERRY_BUILTIN_WEAKREF
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_IS_NOT_WEAKREF, "Target is not weakRef")
|
||||
#endif /* JERRY_BUILTIN_WEAKREF */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_NOT_EXTENSIBLE, "Target not extensible")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_ANNEXB
|
||||
ECMA_ERROR_DEF (ECMA_ERR_GETTER_IS_NOT_CALLABLE, "Getter is not callable")
|
||||
#endif /* JERRY_BUILTIN_ANNEXB */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_HANDLER_CANNOT_BE_NULL, "Handler cannot be null")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_UTF8_CHARACTER, "Invalid UTF8 character")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_UTF8_CODEPOINT, "Invalid UTF8 codepoint")
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_CONTAINER_TYPE, "Invalid container type")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_RANGE_OF_INDEX, "Invalid range of index")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if !(JERRY_BUILTIN_PROXY)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROXY_IS_NOT_SUPPORTED, "Proxy is not supported")
|
||||
#endif /* !(JERRY_BUILTIN_PROXY) */
|
||||
#if !(JERRY_BUILTIN_REALMS)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REALM_IS_NOT_AVAILABLE, "Realm is not available")
|
||||
#endif /* !(JERRY_BUILTIN_REALMS) */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BIGINT_ZERO_DIVISION, "BigInt division by zero")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_AN_ARRAYBUFFER, "Expected an ArrayBuffer")
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_CHARACTER_CLASS, "Invalid character class")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ESCAPE_SEQUENCE, "Invalid escape sequence")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_SNAPSHOT_FORMAT, "Invalid snapshot format")
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_LONE_QUANTIFIER_BRACKET, "Lone quantifier bracket")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_OBJECT_CANNOT_BE_FROZEN, "Object cannot be frozen")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_OBJECT_CANNOT_BE_SEALED, "Object cannot be sealed")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if !(JERRY_BUILTIN_REGEXP)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REGEXP_IS_NOT_SUPPORTED, "RegExp is not supported")
|
||||
#endif /* !(JERRY_BUILTIN_REGEXP) */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNMATCHED_CLOSE_BRACKET, "Unmatched close bracket")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_NOT_MODULE, "Argument is not a module")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SET_PROTOTYPE, "Cannot set [[Prototype]]")
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_NEW_ARRAY_LENGTH, "Invalid new Array length")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_IS_NOT_CALLABLE, "Iterator is not callable")
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_IS_IN_ERROR_STATE, "Module is in error state")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REJECT_MUST_BE_UNDEFINED, "Reject must be undefined")
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REQUEST_IS_NOT_AVAILABLE, "Request is not available")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT, "Argument is not an object")
|
||||
#if JERRY_BUILTIN_ATOMICS
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_NOT_SUPPORTED, "Argument is not supported")
|
||||
#endif /* JERRY_BUILTIN_ATOMICS */
|
||||
#if JERRY_BUILTIN_STRING
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_CODE_POINT_ERROR, "Error: Invalid code point")
|
||||
#endif /* JERRY_BUILTIN_STRING */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_TYPEDARRAY_LENGTH, "Invalid TypedArray length")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_HEXADECIMAL_VALUE, "Invalid hexadecimal value")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_IS_NOT_AN_OBJECT, "Iterator is not an object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RESOLVE_MUST_BE_UNDEFINED, "Resolve must be undefined")
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_BUFFER_SMALL, "Snapshot buffer too small")
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNEXPECTED_END_OF_PATTERN, "Unexpected end of pattern")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE, "Unsupported compiled code")
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
#if !(JERRY_BUILTIN_BIGINT)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BIGINT_NOT_SUPPORTED, "BigInt support is disabled")
|
||||
#endif /* !(JERRY_BUILTIN_BIGINT) */
|
||||
#if JERRY_BUILTIN_DATAVIEW
|
||||
ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_DATAVIEW_OBJECT, "Expected a DataView object")
|
||||
#endif /* JERRY_BUILTIN_DATAVIEW */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_FUNCTION_OBJECT, "Expected a function object")
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARRAYBUFFER_LENGTH, "Invalid ArrayBuffer length")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if !(JERRY_MODULE_SYSTEM)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_NOT_SUPPORTED, "Module support is disabled")
|
||||
#endif /* !(JERRY_MODULE_SYSTEM) */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_OBJECT_IS_NOT_A_TYPEDARRAY, "Object is not a TypedArray")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RECEIVER_MUST_BE_AN_OBJECT, "Receiver must be an object")
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BIGINT_SERIALIZED, "BigInt cannot be serialized")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_IS_NOT_AN_OBJECT, "Container is not an object.")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_HEX_ESCAPE_SEQUENCE, "Invalid hex escape sequence")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_SPECIES_CONSTRUCTOR, "Invalid species constructor")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH, "Proxy trap returned falsish")
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MIN_GREATER_THAN_MAX, "Quantifier error: min > max")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SYMBOL_IS_NOT_A_CONSTRUCTOR, "Symbol is not a constructor")
|
||||
#if JERRY_BUILTIN_REFLECT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_IS_NOT_A_CONSTRUCTOR, "Target is not a constructor")
|
||||
#endif /* JERRY_BUILTIN_REFLECT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ACCESSOR_WRITABLE, "Accessors cannot be writable")
|
||||
#if !(JERRY_BUILTIN_DATAVIEW)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_DATA_VIEW_NOT_SUPPORTED, "DataView support is disabled")
|
||||
#endif /* !(JERRY_BUILTIN_DATAVIEW) */
|
||||
#if JERRY_BUILTIN_DATE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_DATE_MUST_BE_A_FINITE_NUMBER, "Date must be a finite number")
|
||||
#endif /* JERRY_BUILTIN_DATE */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED, "Local variable is redeclared")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNSUPPORTED_BINARY_OPERATION, "Unsupported binary operation")
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNTERMINATED_CHARACTER_CLASS, "Unterminated character class")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARRAYBUFFER_IS_DETACHED, "ArrayBuffer has been detached")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_NOT_AN_OBJECT, "Constructor must be an object")
|
||||
#if !(JERRY_BUILTIN_CONTAINER)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_NOT_SUPPORTED, "Container support is disabled")
|
||||
#endif /* !(JERRY_BUILTIN_CONTAINER) */
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ECMA_ERROR_DEF (ECMA_ERR_FIRST_ARGUMENT_IS_NOT_A_REALM, "First argument is not a realm")
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INCOMPATIBLE_TYPEDARRAY_TYPES, "Incompatible TypedArray types")
|
||||
#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_TYPE_FOR_TYPEDARRAY, "Incorrect type for TypedArray")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_OR_OUT_OF_RANGE_INDEX, "Invalid or out-of-range index")
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE, "Maximum snapshot size reached")
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_CANNOT_BE_INSTANTIATED, "Module cannot be instantiated")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SPECIES_MUST_BE_A_CONSTRUCTOR, "Species must be a constructor")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_IS_NOT_A_PROXY, "Argument is not a Proxy object")
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_NOT_ARRAY_BUFFER, "Argument is not an ArrayBuffer")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_MAP_REQUIRES_NEW, "Constructor Map requires 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_SET_REQUIRES_NEW, "Constructor Set requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_MUST_BE_IN_LINKED_STATE, "Module must be in linked state")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNKNOWN_EXPORT, "Native module export not found")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PASSED_ARGUMENT_IS_NOT_A_REALM, "Passed argument is not a realm")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_METHOD_IS_NOT_WRITABLE, "Private method is not writable")
|
||||
#if JERRY_BUILTIN_BIGINT || JERRY_BUILTIN_NUMBER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RADIX_IS_OUT_OF_RANGE, "Radix must be between 2 and 36")
|
||||
#endif /* JERRY_BUILTIN_BIGINT \
|
||||
|| JERRY_BUILTIN_NUMBER */
|
||||
#if !(JERRY_SNAPSHOT_EXEC)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_EXEC_DISABLED, "Snapshot execution is disabled")
|
||||
#endif /* !(JERRY_SNAPSHOT_EXEC) */
|
||||
#if !(JERRY_BUILTIN_TYPEDARRAY)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TYPED_ARRAY_NOT_SUPPORTED, "TypedArray support is disabled")
|
||||
#endif /* !(JERRY_BUILTIN_TYPEDARRAY) */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING, "Unicode surrogate pair missing")
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_CONTROL_ESCAPE_SEQUENCE, "Invalid control escape sequence")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE, "Invalid unicode escape sequence")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_NEXT_IS_NOT_CALLABLE, "Iterator 'next' is not callable")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT, "Iterator value is not an object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE, "Resolve method must be callable")
|
||||
#if !(JERRY_SNAPSHOT_SAVE)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_SAVE_DISABLED, "Snapshot generation is disabled")
|
||||
#endif /* !(JERRY_SNAPSHOT_SAVE) */
|
||||
#if !(JERRY_PARSER)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PARSER_NOT_SUPPORTED, "Source code parsing is disabled")
|
||||
#endif /* !(JERRY_PARSER) */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_MUST_RETURN_WITH_AN_OBJECT, "Trap must return with an object")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNSUPPORTED_CONTAINER_OPERATION, "Unsupported container operation")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_METHOD_RETURN_IS_NOT_CALLABLE, "method 'return' is not callable")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_PROMISE, "Argument 'this' is not a Promise")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT, "Argument 'this' is not an object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_SYMBOL, "Argument 'this' must be a Symbol")
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CALLBACK_RESULT_NOT_MODULE, "Callback result must be a module")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CLASS_CONSTRUCTOR_REQUIRES_NEW, "Class constructor requires 'new'")
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_COMPARE_FUNC_NOT_CALLABLE, "Compare function is not callable")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_PROXY_REQUIRES_NEW, "Constructor Proxy requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_CONFIGURABLE_PROPERTY, "Expected a configurable property")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_FIRST_PARAMETER_MUST_BE_CALLABLE, "First parameter must be callable")
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_FUNCTION_ADD_ORSET_IS_NOT_CALLABLE, "Function add/set is not callable")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_RESULT_IS_NOT_AN_OBJECT, "Iterator result is not an object")
|
||||
#if (JERRY_STACK_LIMIT != 0)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED, "Maximum call stack size exceeded")
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_STRING_LENGTH_IS_REACHED, "Maximum string length is reached")
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_MUST_BE_IN_UNLINKED_STATE, "Module must be in unlinked state")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
ECMA_ERROR_DEF (ECMA_ERR_STATIC_SNAPSHOTS_ARE_NOT_ENABLED, "Static snapshots are not enabled")
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
#if JERRY_BUILTIN_WEAKREF
|
||||
ECMA_ERROR_DEF (ECMA_ERR_WEAKREF_TARGET_MUST_BE_AN_OBJECT, "WeakRef target must be an object")
|
||||
#endif /* JERRY_BUILTIN_WEAKREF */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_FUNCTION, "Argument 'this' is not a function")
|
||||
#if JERRY_BUILTIN_ATOMICS
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_NOT_SHARED_ARRAY_BUFFER, "Argument is not SharedArrayBuffer")
|
||||
#endif /* JERRY_BUILTIN_ATOMICS */
|
||||
#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_CONTAINER || JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE, "Callback function is not callable")
|
||||
#endif /* JERRY_BUILTIN_ARRAY \
|
||||
|| JERRY_BUILTIN_CONTAINER \
|
||||
|| JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED, "Initial value cannot be undefined")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_SHARED_ARRAYBUFFER_LENGTH, "Invalid Shared ArrayBuffer length")
|
||||
#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_TYPE_FOR_CONSTRUCTOR_CALL, "Invalid type for constructor call")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE, "Iterator 'throw' is not available")
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_NAMESPACE_OBJECT_IS_NOT_AVAILABLE, "Namespace object is not available")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROXY_TARGET_IS_NOT_A_CONSTRUCTOR, "Proxy target is not a constructor")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SECOND_ARGUMENT_MUST_BE_AN_OBJECT, "Second argument must be an object")
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
#if JERRY_BUILTIN_DATAVIEW
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_BUFFER_NOT_OBJECT, "Argument 'buffer' is not an object")
|
||||
#endif /* JERRY_BUILTIN_DATAVIEW */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR, "Argument 'this' is not an iterator")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_VALUE_MSG, "Argument cannot be marked as error")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_PROMISE_REQUIRES_NEW, "Constructor Promise requires 'new'")
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_WEAKMAP_REQUIRES_NEW, "Constructor WeakMap requires 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_WEAKSET_REQUIRES_NEW, "Constructor WeakSet requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_TYPEDARRAY_SIZE_IS_REACHED, "Maximum TypedArray size is reached")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_THE_GIVEN_ARGUMENT_IS_NOT_A_SYMBOL, "The given argument is not a Symbol")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PARAMETER_REJECT_MUST_BE_CALLABLE, "'reject' parameter must be callable")
|
||||
#if JERRY_BUILTIN_ATOMICS || JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY, "Argument 'this' is not a TypedArray")
|
||||
#endif /* JERRY_BUILTIN_ATOMICS \
|
||||
|| JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS, "Cannot allocate memory for literals")
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVOKE_NULLABLE_SUPER_METHOD, "Cannot invoke nullable super method")
|
||||
#if JERRY_BUILTIN_DATAVIEW
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_DATAVIEW_REQUIRES_NEW, "Constructor DataView requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_DATAVIEW */
|
||||
#if JERRY_BUILTIN_WEAKREF
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_WEAKREF_REQUIRES_NEW, "Constructor WeakRef requires 'new'.")
|
||||
#endif /* JERRY_BUILTIN_WEAKREF */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SUPER_BINDING_MUST_BE_A_CONSTRUCTOR, "Super binding must be a constructor")
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_VALUE_CANNOT_BE_CONVERTED_TO_BIGINT, "Value cannot be converted to BigInt")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PARAMETER_RESOLVE_MUST_BE_CALLABLE, "'resolve' parameter must be callable")
|
||||
#if JERRY_BUILTIN_DATE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_DATE_OBJECT, "Argument 'this' is not a Date object")
|
||||
#endif /* JERRY_BUILTIN_DATE */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_CONSTRUCTOR, "Argument 'this' is not a constructor")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BIGINT_FUNCTION_NOT_CONSTRUCTOR, "BigInt function is not a constructor")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTED_OBJECT_IS_NOT_TYPEDARRAY, "Constructed object is not TypedArray")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_INT8_ARRAY_REQUIRES_NEW, "Constructor Int8Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT, "Container is not a container object.")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_DATE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARGUMENT_TYPE_IN_TOPRIMITIVE, "Invalid argument type in toPrimitive")
|
||||
#endif /* JERRY_BUILTIN_DATE */
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_METHODS_INVOKE_WITH_NEW, "Methods cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_EXPORTS_MUST_BE_STRING_VALUES, "Module exports must be string values")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROTOTYPE_IS_NEITHER_OBJECT_NOR_NULL, "Prototype is neither object nor null")
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_THE_MAPFN_ARGUMENT_IS_NOT_CALLABLE, "The 'mapfn' argument is not callable")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_THE_TWO_DESCRIPTORS_ARE_INCOMPATIBLE, "The two descriptors are incompatible")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_WRONG_ARGS_MSG, "This type of argument is not allowed")
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_NEEDED, "Value is not a Container or Iterator")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP, "Argument 'this' is not a valid RegExp")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARRAY_BUFFER_DETACHED, "ArrayBuffer has already been detached")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BUILTIN_ROUTINES_HAVE_NO_CONSTRUCTOR, "Built-in routines have no constructor")
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_INT16_ARRAY_REQUIRES_NEW, "Constructor Int16Array requires 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_INT32_ARRAY_REQUIRES_NEW, "Constructor Int32Array requires 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT8_ARRAY_REQUIRES_NEW, "Constructor Uint8Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
ECMA_ERROR_DEF (ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM, "Function index is higher than maximum")
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RANGE_OUT_OF_ORDER_IN_CHARACTER_CLASS, "Range out of order in character class")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RESULT_OF_DEFAULTVALUE_IS_INVALID, "Result of [[DefaultValue]] is invalid")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RIGHT_VALUE_OF_IN_MUST_BE_AN_OBJECT, "Right value of 'in' must be an object")
|
||||
#if !(JERRY_BUILTIN_SHAREDARRAYBUFFER)
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SHARED_ARRAYBUFFER_NOT_SUPPORTED, "SharedArrayBuffer support is disabled")
|
||||
#endif /* !(JERRY_BUILTIN_SHAREDARRAYBUFFER) */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_RETURNED_NEITHER_OBJECT_NOR_NULL, "Trap returned neither object nor null")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_WITH_DUPLICATED_ENTRIES, "Trap returned with duplicated entries")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNARY_PLUS_IS_NOT_ALLOWED_FOR_BIGINTS, "Unary plus is not allowed for BigInts")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_IS_NOT_AN_REGEXP, "Argument 'this' is not a RegExp object")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ALLOCATE_ARRAY_BUFFER, "Cannot allocate memory for ArrayBuffer")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTANT_BINDINGS_CANNOT_BE_REASSIGNED, "Constant bindings cannot be reassigned")
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_ARRAYBUFFER_REQUIRES_NEW, "Constructor ArrayBuffer requires 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT16_ARRAY_REQUIRES_NEW, "Constructor Uint16Array requires 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT32_ARRAY_REQUIRES_NEW, "Constructor Uint32Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION, "Generator is currently under execution")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_RETURN_RESULT_IS_NOT_OBJECT, "Iterator 'return' result is not object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SEARCH_STRING_CANNOT_BE_OF_TYPE_REGEXP, "Search string can't be of type: RegExp")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_VALUE_RECEIVED_BY_YIELD_IS_NOT_OBJECT, "Value received by yield* is not object")
|
||||
#if JERRY_BUILTIN_BOOLEAN
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_BOOLEAN_OBJECT, "Argument 'this' is not a Boolean object")
|
||||
#endif /* JERRY_BUILTIN_BOOLEAN */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_DECLARE_SAME_PRIVATE_FIELD_TWICE, "Cannot declare same private field twice")
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_FLOAT32_ARRAY_REQUIRES_NEW, "Constructor Float32Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_FLOAT64_ARRAY_REQUIRES_NEW, "Constructor Float64Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_FUNCTION_PROTOTYPE_NOT_A_CONSTRUCTOR, "Function.prototype is not a constructor")
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE, "Imported binding shadows local variable")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROTOTYPE_FROM_REVOKED_PROXY_IS_INVALID, "Prototype from revoked Proxy is invalid")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_REGEXP && JERRY_BUILTIN_STRING
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REGEXP_ARGUMENT_SHOULD_HAVE_GLOBAL_FLAG, "RegExp argument should have global flag")
|
||||
#endif /* JERRY_BUILTIN_REGEXP && JERRY_BUILTIN_STRING */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_IS_NEITHER_AN_OBJECT_NOR_UNDEFINED, "Trap is neither an object nor undefined")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROMISE_RESOLVE_ITSELF, "A promise cannot be resolved with itself")
|
||||
#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_BIGINT64_ARRAY_REQUIRES_NEW, "Constructor BigInt64Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_MODULE_EXPORTS_MUST_BE_VALID_IDENTIFIERS, "Module exports must be valid identifiers")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_GENERATOR_OBJECT, "Argument 'this' is not a generator object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_CANNOT_CONVERT_TO_OBJECT, "Argument cannot be converted to an object")
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ALLOCATE_BIGINT_VALUE, "Cannot allocate memory for a BigInt value")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONVERT_BIGINT_TO_NUMBER, "Cannot convert a BigInt value to a number")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONVERT_SYMBOL_TO_NUMBER, "Cannot convert a Symbol value to a number")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONVERT_SYMBOL_TO_STRING, "Cannot convert a Symbol value to a string")
|
||||
#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_BIG_UINT64_ARRAY_REQUIRES_NEW, "Constructor BigUInt64Array requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_NUMBER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_FRACTION_DIGITS_OUT_OF_RANGE, "Fraction digits must be between 0 and 100")
|
||||
#endif /* JERRY_BUILTIN_NUMBER */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RETURN_VALUE_IS_NOT_AN_ARRAYBUFFER_OBJECT, "Return value is not an ArrayBuffer object")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SUPER_CONSTRUCTOR_MAY_ONLY_BE_CALLED_ONCE, "Super constructor may only be called once")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_BINDING_NOT_EXIST_OR_UNINITIALIZED, "Binding does not exist or is uninitialised")
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_CONVERT_TO_OBJECT, "Cannot convert undefined or null to object")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
#if JERRY_BUILTIN_NUMBER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PRECISION_DIGITS_MUST_BE_BETWEEN_IN_RANGE, "Precision digits must be between 1 and 100")
|
||||
#endif /* JERRY_BUILTIN_NUMBER */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_GETTER, "Private field was defined without a getter")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_SETTER, "Private field was defined without a setter")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROPERTY_NAME_IS_NEITHER_SYMBOL_NOR_STRING, "Property name is neither Symbol nor string")
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_STRING_CANNOT_BE_CONVERTED_TO_BIGINT_VALUE, "String cannot be converted to BigInt value")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_TYPE_CALL, "Operator called on incorrect container type")
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE, "Reduce of empty Array with no initial value")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP_OBJECT, "Argument 'this' is not a valid RegExp object")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_ARRAY_BUFFER_OBJECT, "Argument 'this' is not an ArrayBuffer object")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARROW_FUNCTIONS_INVOKE_WITH_NEW, "Arrow functions cannot be invoked with 'new'")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ASYNC_FUNCTIONS_INVOKE_WITH_NEW, "Async functions cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SET_EXTENSIBLE_PROPERTY, "Cannot set [[Extensible]] property of object")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_SHAREDARRAYBUFFER_REQUIRES_NEW, "Constructor SharedArrayBuffer requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT8_CLAMPED_ARRAY_REQUIRES_NEW, "Constructor Uint8ClampedArray requires 'new'")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_NEGATIVE_EXPONENT_IS_NOT_ALLOWED_FOR_BIGINTS, "Negative exponent is not allowed for BigInts")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROMISE_ALL_REMAINING_ELEMENTS_LIMIT_REACHED, "Promise.all remaining elements limit reached")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_VALUE_RECEIVED_BY_FOR_ASYNC_OF_IS_NOT_OBJECT, "Value received by for-async-of is not object")
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INFINITY_OR_NAN_CANNOT_BE_CONVERTED_TO_BIGINT, "Infinity or NaN cannot be converted to BigInt")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_OPERATOR_DELETE_RETURNED_FALSE_IN_STRICT_MODE, "Operator delete returned false in strict mode")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROPERTY_PROTOTYPE_IS_NOT_AN_OBJECT, "Property 'prototype' is not an object or null")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROXY_HANDLER_IS_NULL_FOR_ISARRAY_OPERATION, "Proxy handler is null for 'isArray' operation")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED, "Regular expression literals are not supported")
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RIGHT_VALUE_OF_INSTANCEOF_MUST_BE_AN_OBJECT, "Right value of 'instanceof' must be an object")
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
ECMA_ERROR_DEF (ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY, "Static snapshots cannot be copied into memory")
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TAGGED_TEMPLATE_LITERALS, "Unsupported feature: tagged template literals")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED, "Unsupported generate snapshot flags specified")
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED, "Unsupported snapshot exec flags are specified")
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_VALUE_FOR_CLASS_HERITAGE_IS_NOT_A_CONSTRUCTOR, "Value for class heritage is not a constructor")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TOO_MANY_ARGUMENTS_DECLARED_FOR_FUNCTION_APPLY,
|
||||
"Too many arguments declared for Function.apply")
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ACCESSOR_FUNCTIONS_INVOKE_WITH_NEW, "Accessor functions cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ECMA_ERROR_DEF (ECMA_ERR_LINK_TO_MODULE_IN_ERROR_STATE, "Cannot link to a module which is in error state")
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ONLY_INTEGER_NUMBERS_CAN_BE_CONVERTED_TO_BIGINT,
|
||||
"Only integer numbers can be converted to BigInt")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TYPEDARRAY_INTRINSIC_DIRECTLY_CALLED, "TypedArray intrinsic cannot be directly called")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNSIGNED_RIGHT_SHIFT_IS_NOT_ALLOWED_FOR_BIGINTS,
|
||||
"Unsigned right shift is not allowed for BigInts")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR, "Argument 'this' is not an async generator object")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CLASS_EXTENDS_NOT_CONSTRUCTOR, "Class extends value is not a constructor or null")
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW, "Generator functions cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
ECMA_ERROR_DEF (ECMA_ERR_RETURN_VALUE_OF_EXEC_MUST_BE_AN_OBJECT_OR_NULL,
|
||||
"Return value of 'exec' must be an object or null")
|
||||
#endif /* JERRY_BUILTIN_REGEXP */
|
||||
#if JERRY_BUILTIN_DATAVIEW
|
||||
ECMA_ERROR_DEF (ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER,
|
||||
"Start offset is outside the bounds of the buffer")
|
||||
#endif /* JERRY_BUILTIN_DATAVIEW */
|
||||
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER, "Argument 'this' is not a SharedArrayBuffer object")
|
||||
#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CLASS_CONSTRUCTOR_NEW, "Class constructor cannot be invoked without 'new'")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_RETURN_PROXY_GET_TRAP, "Incorrect value is returned by a Proxy 'get' trap")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_RETURN_PROXY_SET_TRAP, "Incorrect value is returned by a Proxy 'set' trap")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CLASS_IS_NON_CONFIGURABLE, "Prototype property of a class is non-configurable")
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PUSHING_TOO_HIGH_ELEMENT, "Pushing element over 2**53-1 length is disallowed")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_THE_REQUESTED_PROPERTY_UPDATE_CANNOT_BE_PERFORMED,
|
||||
"The requested property update cannot be performed")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_CONFIGURABLE_KEYS,
|
||||
"Trap result did not include all configurable keys")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_TARGET_NOT_EXTENSIBLE, "Trap returned truish for target is not extensible")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_NUMBER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_NUMBER, "Argument 'this' is not a number or a Number object")
|
||||
#endif /* JERRY_BUILTIN_NUMBER */
|
||||
#if JERRY_BUILTIN_STRING
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_STRING_OBJECT, "Argument 'this' is not a string or a String object")
|
||||
#endif /* JERRY_BUILTIN_STRING */
|
||||
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER_OBJECT,
|
||||
"Argument 'this' is not an SharedArrayBuffer object")
|
||||
#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ASYNC_ARROW_FUNCTIONS_INVOKE_WITH_NEW, "Async arrow functions cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_BUILTIN_ARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_UNSHIFT_TOO_HIGH, "Unshift elements over 2**53-1 length is disallowed")
|
||||
#endif /* JERRY_BUILTIN_ARRAY */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_NON_CONFIGURABLE_KEYS,
|
||||
"Trap result did not include all non-configurable keys")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ASYNC_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW,
|
||||
"Async generator functions cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_BUILTIN_REFLECT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_REFLECT_EXPECTS_AN_OBJECT_AS_SECOND_ARGUMENT,
|
||||
"Reflect.construct expects an object as second argument")
|
||||
#endif /* JERRY_BUILTIN_REFLECT */
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ECMA_ERROR_DEF (ECMA_ERR_SCRIPT_GLOBAL_FUNCTIONS_INVOKE_WITH_NEW,
|
||||
"Script (global) functions cannot be invoked with 'new'")
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_CREATE_PROXY, "Cannot create Proxy with a non-object target or handler")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_DERIVED_CTOR_RETURN_NOR_OBJECT_OR_UNDEFINED,
|
||||
"Derived constructors may only return object or undefined")
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
ECMA_ERROR_DEF (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES,
|
||||
"Invalid snapshot version or unsupported features present")
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TYPEDARRAY_SMALLER_THAN_FILTER_CALL_RESULT,
|
||||
"Constructed TypedArray is smaller than filter call result")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_DERIVED_ARRAY_BUFFER_CTOR_BUFFER_TOO_SMALL,
|
||||
"Derived ArrayBuffer constructor created a too small buffer")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_EXTENSIBILITY,
|
||||
"Trap result does not reflect extensibility of Proxy target")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_EXTRA_KEYS_FOR_A_NON_EXTENSIBLE_TARGET,
|
||||
"Trap returned extra keys for a non-extensible Proxy target")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARRAY_BUFFER_RETURNED_THIS_FROM_CONSTRUCTOR,
|
||||
"ArrayBuffer subclass returned this from species constructor")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_DATAVIEW
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_BUFFER_NOT_ARRAY_OR_SHARED_BUFFER,
|
||||
"Argument 'buffer' is not an ArrayBuffer or SharedArrayBuffer")
|
||||
#endif /* JERRY_BUILTIN_DATAVIEW */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_INEXTENSIBILITY,
|
||||
"Trap result does not reflect inextensibility of Proxy target")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TYPEDARRAY_INTRINSIC_CALLED_BY_NEW_EXPRESSION,
|
||||
"TypedArray intrinsic cannot be called by a 'new' expression")
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CONTENTTYPE_RETURNED_TYPEDARRAY_NOT_MATCH_SOURCE,
|
||||
"TypedArray returned by [[ContentType]] does not match source")
|
||||
#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ECMA_ERROR_DEF (ECMA_ERR_ALLOCATE_BIGINT_STRING, "Cannot allocate memory for a string representation of a BigInt value")
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_NOT_EXTENSIBLE_DIFFERENT_PROTOTYPE_RETURNED,
|
||||
"Target object is non-extensible and trap returned different prototype")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_ADDING_PROPERTY_NON_EXTENSIBLE_TARGET,
|
||||
"Trap returned truish for adding property to the non-extensible target")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_READ_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT,
|
||||
"Cannot read private member to an object whose class did not declare it")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_GIVEN_PROPERTY_IS_A_NON_CONFIGURABLE,
|
||||
"Given property is a non-configurable data property on the proxy target")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_WRITE_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT,
|
||||
"Cannot write private member to an object whose class did not declare it")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_FALSISH_PROPERTY_TARGET_NOT_EXTENSIBLE,
|
||||
"Trap returned falsish for property but the proxy target is not extensible")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_PROXY_PROPERTY_NOT_CONFIGURABLE_NOT_HAVE_GETTER,
|
||||
"Property of a Proxy is non-configurable and does not have a getter function")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_PROPERTY_CONFIGURE_ACCESSOR_WITHOUT_SETTER,
|
||||
"The property of a Proxy target is a non configurable accessor without a setter")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_LET_CONST_NOT_INITIALIZED,
|
||||
"Variables declared by let/const must be initialized before reading their value")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_PROPERTY_NON_CONFIGURABLE,
|
||||
"Trap returned truish for property which is non-configurable in the proxy target")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TARGET_NOT_EXTENSIBLE_NOT_RETURNED_ITS_PROTOTYPE,
|
||||
"Proxy target is non-extensible, but the trap did not return its actual prototype")
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_FALSISH_PROPERTY_NON_CONFIGURABLE,
|
||||
"Trap returned falsish for property which exists in the proxy target as non-configurable")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CALL_SUPER_CONSTRUCTOR_DERIVED_CLASS_BEFORE_THIS,
|
||||
"Must call super constructor in derived class before accessing 'this' or returning from it")
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY,
|
||||
"Trap returned truish for defining non-configurable property which is nonexistent in the target")
|
||||
ECMA_ERROR_DEF (
|
||||
ECMA_ERR_TRAP_TRUISH_ADD_PROPERTY_INCOMPATIBLE_OTHER_PROP,
|
||||
"Trap returned truish for adding property that is incompatible with the existing property in the target")
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
ECMA_ERROR_DEF (ECMA_ERR_CANNOT_ACCESS_CALLER_CALLEE_ARGUMENTS,
|
||||
"'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the "
|
||||
"arguments objects for calls to them")
|
||||
@@ -0,0 +1,331 @@
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
[ECMA_ERROR_MESSAGES]
|
||||
|
||||
ECMA_ERR_CANNOT_ACCESS_CALLER_CALLEE_ARGUMENTS = "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them"
|
||||
ECMA_ERR_PARAMETER_REJECT_MUST_BE_CALLABLE = "'reject' parameter must be callable"
|
||||
ECMA_ERR_PARAMETER_RESOLVE_MUST_BE_CALLABLE = "'resolve' parameter must be callable"
|
||||
ECMA_ERR_PROMISE_RESOLVE_ITSELF = "A promise cannot be resolved with itself"
|
||||
ECMA_ERR_ACCESSOR_WRITABLE = "Accessors cannot be writable"
|
||||
ECMA_ERR_ARGUMENT_BUFFER_NOT_ARRAY_OR_SHARED_BUFFER = "Argument 'buffer' is not an ArrayBuffer or SharedArrayBuffer"
|
||||
ECMA_ERR_ARGUMENT_BUFFER_NOT_OBJECT = "Argument 'buffer' is not an object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_ARRAY_BUFFER_OBJECT = "Argument 'this' is not an ArrayBuffer object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_BOOLEAN_OBJECT = "Argument 'this' is not a Boolean object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_DATE_OBJECT = "Argument 'this' is not a Date object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_PROMISE = "Argument 'this' is not a Promise"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER = "Argument 'this' is not a SharedArrayBuffer object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY = "Argument 'this' is not a TypedArray"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_CONSTRUCTOR = "Argument 'this' is not a constructor"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_FUNCTION = "Argument 'this' is not a function"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_GENERATOR_OBJECT = "Argument 'this' is not a generator object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_NUMBER = "Argument 'this' is not a number or a Number object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_STRING_OBJECT = "Argument 'this' is not a string or a String object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP = "Argument 'this' is not a valid RegExp"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP_OBJECT = "Argument 'this' is not a valid RegExp object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER_OBJECT = "Argument 'this' is not an SharedArrayBuffer object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR = "Argument 'this' is not an async generator object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR = "Argument 'this' is not an iterator"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT = "Argument 'this' is not an object"
|
||||
ECMA_ERR_ARGUMENT_THIS_NOT_SYMBOL = "Argument 'this' must be a Symbol"
|
||||
ECMA_ERR_ARGUMENT_CANNOT_CONVERT_TO_OBJECT = "Argument cannot be converted to an object"
|
||||
ECMA_ERR_ARGUMENT_NOT_SHARED_ARRAY_BUFFER = "Argument is not SharedArrayBuffer"
|
||||
ECMA_ERR_ARGUMENT_NOT_ARRAY_BUFFER = "Argument is not an ArrayBuffer"
|
||||
ECMA_ERR_ARGUMENT_NOT_SUPPORTED = "Argument is not supported"
|
||||
ECMA_ERR_ARRAY_BUFFER_DETACHED = "ArrayBuffer has already been detached"
|
||||
ECMA_ERR_ARRAY_BUFFER_RETURNED_THIS_FROM_CONSTRUCTOR = "ArrayBuffer subclass returned this from species constructor"
|
||||
ECMA_ERR_BIGINT_SERIALIZED = "BigInt cannot be serialized"
|
||||
ECMA_ERR_BIGINT_ZERO_DIVISION = "BigInt division by zero"
|
||||
ECMA_ERR_BIGINT_FUNCTION_NOT_CONSTRUCTOR = "BigInt function is not a constructor"
|
||||
ECMA_ERR_BIGINT_VALUE_EXPECTED = "BigInt value expected"
|
||||
ECMA_ERR_BINDING_CANNOT_SET = "Binding cannot be set"
|
||||
ECMA_ERR_BINDING_NOT_EXIST_OR_UNINITIALIZED = "Binding does not exist or is uninitialised"
|
||||
ECMA_ERR_BUILTIN_ROUTINES_HAVE_NO_CONSTRUCTOR = "Built-in routines have no constructor"
|
||||
ECMA_ERR_CALLBACK_RESULT_NOT_MODULE = "Callback result must be a module"
|
||||
ECMA_ERR_ALLOCATE_ARRAY_BUFFER = "Cannot allocate memory for ArrayBuffer"
|
||||
ECMA_ERR_ALLOCATE_BIGINT_VALUE = "Cannot allocate memory for a BigInt value"
|
||||
ECMA_ERR_ALLOCATE_BIGINT_STRING = "Cannot allocate memory for a string representation of a BigInt value"
|
||||
ECMA_ERR_CONVERT_BIGINT_TO_NUMBER = "Cannot convert a BigInt value to a number"
|
||||
ECMA_ERR_CONVERT_SYMBOL_TO_NUMBER = "Cannot convert a Symbol value to a number"
|
||||
ECMA_ERR_CONVERT_SYMBOL_TO_STRING = "Cannot convert a Symbol value to a string"
|
||||
ECMA_ERR_CANNOT_CREATE_PROXY = "Cannot create Proxy with a non-object target or handler"
|
||||
ECMA_ERR_INVOKE_NULLABLE_SUPER_METHOD = "Cannot invoke nullable super method"
|
||||
ECMA_ERR_LINK_TO_MODULE_IN_ERROR_STATE = "Cannot link to a module which is in error state"
|
||||
ECMA_ERR_SET_EXTENSIBLE_PROPERTY = "Cannot set [[Extensible]] property of object"
|
||||
ECMA_ERR_SET_PROTOTYPE = "Cannot set [[Prototype]]"
|
||||
ECMA_ERR_CLASS_CONSTRUCTOR_REQUIRES_NEW = "Class constructor requires 'new'"
|
||||
ECMA_ERR_CLASS_EXTENDS_NOT_CONSTRUCTOR = "Class extends value is not a constructor or null"
|
||||
ECMA_ERR_COMPARE_FUNC_NOT_CALLABLE = "Compare function is not callable"
|
||||
ECMA_ERR_CONSTANT_BINDINGS_CANNOT_BE_REASSIGNED = "Constant bindings cannot be reassigned"
|
||||
ECMA_ERR_TYPEDARRAY_SMALLER_THAN_FILTER_CALL_RESULT = "Constructed TypedArray is smaller than filter call result"
|
||||
ECMA_ERR_CONSTRUCTED_OBJECT_IS_NOT_TYPEDARRAY = "Constructed object is not TypedArray"
|
||||
ECMA_ERR_CONSTRUCTOR_ARRAYBUFFER_REQUIRES_NEW = "Constructor ArrayBuffer requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_BIGINT64_ARRAY_REQUIRES_NEW = "Constructor BigInt64Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_BIG_UINT64_ARRAY_REQUIRES_NEW = "Constructor BigUInt64Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_DATAVIEW_REQUIRES_NEW = "Constructor DataView requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_FLOAT32_ARRAY_REQUIRES_NEW = "Constructor Float32Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_FLOAT64_ARRAY_REQUIRES_NEW = "Constructor Float64Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_INT16_ARRAY_REQUIRES_NEW = "Constructor Int16Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_INT32_ARRAY_REQUIRES_NEW = "Constructor Int32Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_INT8_ARRAY_REQUIRES_NEW = "Constructor Int8Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_MAP_REQUIRES_NEW = "Constructor Map requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_PROMISE_REQUIRES_NEW = "Constructor Promise requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_PROXY_REQUIRES_NEW = "Constructor Proxy requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_SET_REQUIRES_NEW = "Constructor Set requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_SHAREDARRAYBUFFER_REQUIRES_NEW = "Constructor SharedArrayBuffer requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_UINT16_ARRAY_REQUIRES_NEW = "Constructor Uint16Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_UINT32_ARRAY_REQUIRES_NEW = "Constructor Uint32Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_UINT8_ARRAY_REQUIRES_NEW = "Constructor Uint8Array requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_UINT8_CLAMPED_ARRAY_REQUIRES_NEW = "Constructor Uint8ClampedArray requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_WEAKMAP_REQUIRES_NEW = "Constructor WeakMap requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_WEAKREF_REQUIRES_NEW = "Constructor WeakRef requires 'new'."
|
||||
ECMA_ERR_CONSTRUCTOR_WEAKSET_REQUIRES_NEW = "Constructor WeakSet requires 'new'"
|
||||
ECMA_ERR_CONSTRUCTOR_NOT_AN_OBJECT = "Constructor must be an object"
|
||||
ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT = "Container is not a container object."
|
||||
ECMA_ERR_CONTAINER_IS_NOT_AN_OBJECT = "Container is not an object."
|
||||
ECMA_ERR_DATE_MUST_BE_A_FINITE_NUMBER = "Date must be a finite number"
|
||||
ECMA_ERR_DERIVED_ARRAY_BUFFER_CTOR_BUFFER_TOO_SMALL = "Derived ArrayBuffer constructor created a too small buffer"
|
||||
ECMA_ERR_DERIVED_CTOR_RETURN_NOR_OBJECT_OR_UNDEFINED = "Derived constructors may only return object or undefined"
|
||||
ECMA_ERR_INVALID_CODE_POINT_ERROR = "Error: Invalid code point"
|
||||
ECMA_ERR_EXPECTED_A_DATAVIEW_OBJECT = "Expected a DataView object"
|
||||
ECMA_ERR_EXPECTED_A_CONFIGURABLE_PROPERTY = "Expected a configurable property"
|
||||
ECMA_ERR_EXPECTED_A_FUNCTION_OBJECT = "Expected a function object"
|
||||
ECMA_ERR_EXPECTED_AN_ARRAYBUFFER = "Expected an ArrayBuffer"
|
||||
ECMA_ERR_EXPECTED_AN_OBJECT = "Expected an object"
|
||||
ECMA_ERR_FIRST_ARGUMENT_IS_NOT_A_REALM = "First argument is not a realm"
|
||||
ECMA_ERR_FIRST_PARAMETER_MUST_BE_CALLABLE = "First parameter must be callable"
|
||||
ECMA_ERR_FRACTION_DIGITS_OUT_OF_RANGE = "Fraction digits must be between 0 and 100"
|
||||
ECMA_ERR_FUNCTION_ADD_ORSET_IS_NOT_CALLABLE = "Function add/set is not callable"
|
||||
ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM = "Function index is higher than maximum"
|
||||
ECMA_ERR_FUNCTION_PROTOTYPE_NOT_A_CONSTRUCTOR = "Function.prototype is not a constructor"
|
||||
ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION = "Generator is currently under execution"
|
||||
ECMA_ERR_GETTER_IS_NOT_CALLABLE = "Getter is not callable"
|
||||
ECMA_ERR_GIVEN_PROPERTY_IS_A_NON_CONFIGURABLE = "Given property is a non-configurable data property on the proxy target"
|
||||
ECMA_ERR_HANDLER_CANNOT_BE_NULL = "Handler cannot be null"
|
||||
ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE = "Imported binding shadows local variable"
|
||||
ECMA_ERR_INCOMPATIBLE_TYPEDARRAY_TYPES = "Incompatible TypedArray types"
|
||||
ECMA_ERR_INCORRECT_TYPE_FOR_TYPEDARRAY = "Incorrect type for TypedArray"
|
||||
ECMA_ERR_INCORRECT_RETURN_PROXY_GET_TRAP = "Incorrect value is returned by a Proxy 'get' trap"
|
||||
ECMA_ERR_INCORRECT_RETURN_PROXY_SET_TRAP = "Incorrect value is returned by a Proxy 'set' trap"
|
||||
ECMA_ERR_INFINITY_OR_NAN_CANNOT_BE_CONVERTED_TO_BIGINT = "Infinity or NaN cannot be converted to BigInt"
|
||||
ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED = "Initial value cannot be undefined"
|
||||
ECMA_ERR_INVALID_ARRAYBUFFER_LENGTH = "Invalid ArrayBuffer length"
|
||||
ECMA_ERR_INVALID_JSON_FORMAT = "Invalid JSON format"
|
||||
ECMA_ERR_INVALID_REGEXP_FLAGS = "Invalid RegExp flags"
|
||||
ECMA_ERR_INVALID_SHARED_ARRAYBUFFER_LENGTH = "Invalid Shared ArrayBuffer length"
|
||||
ECMA_ERR_INVALID_TYPEDARRAY_LENGTH = "Invalid TypedArray length"
|
||||
ECMA_ERR_INVALID_UTF8_CHARACTER = "Invalid UTF8 character"
|
||||
ECMA_ERR_INVALID_UTF8_CODEPOINT = "Invalid UTF8 codepoint"
|
||||
ECMA_ERR_INVALID_UTF8_STRING = "Invalid UTF8 string"
|
||||
ECMA_ERR_INVALID_ENCODING = "Invalid encoding"
|
||||
ECMA_ERR_INVALID_ARGUMENT = "Invalid argument"
|
||||
ECMA_ERR_INVALID_ARGUMENT_TYPE_IN_TOPRIMITIVE = "Invalid argument type in toPrimitive"
|
||||
ECMA_ERR_INVALID_CAPABILITY = "Invalid capability"
|
||||
ECMA_ERR_INVALID_CHARACTER_CLASS = "Invalid character class"
|
||||
ECMA_ERR_INVALID_CODE_POINT = "Invalid code point"
|
||||
ECMA_ERR_INVALID_CONTAINER_TYPE = "Invalid container type"
|
||||
ECMA_ERR_INVALID_CONTROL_ESCAPE_SEQUENCE = "Invalid control escape sequence"
|
||||
ECMA_ERR_INVALID_COUNT_VALUE = "Invalid count value"
|
||||
ECMA_ERR_INVALID_ESCAPE = "Invalid escape"
|
||||
ECMA_ERR_INVALID_ESCAPE_SEQUENCE = "Invalid escape sequence"
|
||||
ECMA_ERR_INVALID_GROUP = "Invalid group"
|
||||
ECMA_ERR_INVALID_HEX_ESCAPE_SEQUENCE = "Invalid hex escape sequence"
|
||||
ECMA_ERR_INVALID_HEXADECIMAL_VALUE = "Invalid hexadecimal value"
|
||||
ECMA_ERR_INVALID_LENGTH = "Invalid length"
|
||||
ECMA_ERR_INVALID_NEW_ARRAY_LENGTH = "Invalid new Array length"
|
||||
ECMA_ERR_INVALID_OFFSET = "Invalid offset"
|
||||
ECMA_ERR_INVALID_OR_OUT_OF_RANGE_INDEX = "Invalid or out-of-range index"
|
||||
ECMA_ERR_INVALID_QUANTIFIER = "Invalid quantifier"
|
||||
ECMA_ERR_INVALID_RANGE_OF_INDEX = "Invalid range of index"
|
||||
ECMA_ERR_INVALID_SCOPE_CHAIN_INDEX_FOR_EVAL = "Invalid scope chain index for eval"
|
||||
ECMA_ERR_INVALID_SPECIES_CONSTRUCTOR = "Invalid species constructor"
|
||||
ECMA_ERR_INVALID_STRING_ = "Invalid string length"
|
||||
ECMA_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE = "Invalid unicode escape sequence"
|
||||
ECMA_ERR_ITERATOR_NEXT_IS_NOT_CALLABLE = "Iterator 'next' is not callable"
|
||||
ECMA_ERR_ITERATOR_RETURN_RESULT_IS_NOT_OBJECT = "Iterator 'return' result is not object"
|
||||
ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE = "Iterator 'throw' is not available"
|
||||
ECMA_ERR_ITERATOR_IS_NOT_AN_OBJECT = "Iterator is not an object"
|
||||
ECMA_ERR_ITERATOR_IS_NOT_CALLABLE = "Iterator is not callable"
|
||||
ECMA_ERR_ITERATOR_RESULT_IS_NOT_AN_OBJECT = "Iterator result is not an object"
|
||||
ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT = "Iterator value is not an object"
|
||||
ECMA_ERR_JSON_STRING_PARSE_ERROR = "JSON string parse error"
|
||||
ECMA_ERR_JSON_STRINGIFY_ERROR = "JSON stringify error"
|
||||
ECMA_ERR_KEY_MUST_BE_AN_OBJECT = "Key must be an object"
|
||||
ECMA_ERR_LONE_QUANTIFIER_BRACKET = "Lone quantifier bracket"
|
||||
ECMA_ERR_MAXIMUM_TYPEDARRAY_SIZE_IS_REACHED = "Maximum TypedArray size is reached"
|
||||
ECMA_ERR_MAXIMUM_STRING_LENGTH_IS_REACHED = "Maximum string length is reached"
|
||||
ECMA_ERR_MISSING_ARRAY_ELEMENT = "Missing Array element"
|
||||
ECMA_ERR_MODULE_CANNOT_BE_INSTANTIATED = "Module cannot be instantiated"
|
||||
ECMA_ERR_MODULE_EXPORTS_MUST_BE_STRING_VALUES = "Module exports must be string values"
|
||||
ECMA_ERR_MODULE_EXPORTS_MUST_BE_VALID_IDENTIFIERS = "Module exports must be valid identifiers"
|
||||
ECMA_ERR_MODULE_IS_IN_ERROR_STATE = "Module is in error state"
|
||||
ECMA_ERR_MODULE_MUST_BE_IN_LINKED_STATE = "Module must be in linked state"
|
||||
ECMA_ERR_MODULE_MUST_BE_IN_UNLINKED_STATE = "Module must be in unlinked state"
|
||||
ECMA_ERR_CALL_SUPER_CONSTRUCTOR_DERIVED_CLASS_BEFORE_THIS = "Must call super constructor in derived class before accessing 'this' or returning from it"
|
||||
ECMA_ERR_NAMESPACE_OBJECT_IS_NOT_AVAILABLE = "Namespace object is not available"
|
||||
ECMA_ERR_NEGATIVE_EXPONENT_IS_NOT_ALLOWED_FOR_BIGINTS = "Negative exponent is not allowed for BigInts"
|
||||
ECMA_ERR_NO_SOURCE_ARGUMENT = "No source argument"
|
||||
ECMA_ERR_NOTHING_TO_REPEAT = "Nothing to repeat"
|
||||
ECMA_ERR_OBJECT_CANNOT_BE_FROZEN = "Object cannot be frozen"
|
||||
ECMA_ERR_OBJECT_CANNOT_BE_SEALED = "Object cannot be sealed"
|
||||
ECMA_ERR_OBJECT_EXPECTED = "Object expected"
|
||||
ECMA_ERR_OBJECT_IS_NOT_A_TYPEDARRAY = "Object is not a TypedArray"
|
||||
ECMA_ERR_ONLY_INTEGER_NUMBERS_CAN_BE_CONVERTED_TO_BIGINT = "Only integer numbers can be converted to BigInt"
|
||||
ECMA_ERR_OPERATOR_DELETE_RETURNED_FALSE_IN_STRICT_MODE = "Operator delete returned false in strict mode"
|
||||
ECMA_ERR_PASSED_ARGUMENT_IS_NOT_A_REALM = "Passed argument is not a realm"
|
||||
ECMA_ERR_PRECISION_DIGITS_MUST_BE_BETWEEN_IN_RANGE = "Precision digits must be between 1 and 100"
|
||||
ECMA_ERR_PROMISE_ALL_REMAINING_ELEMENTS_LIMIT_REACHED = "Promise.all remaining elements limit reached"
|
||||
ECMA_ERR_PROPERTY_PROTOTYPE_IS_NOT_AN_OBJECT = "Property 'prototype' is not an object or null"
|
||||
ECMA_ERR_PROPERTY_NAME_IS_NEITHER_SYMBOL_NOR_STRING = "Property name is neither Symbol nor string"
|
||||
ECMA_ERR_PROXY_PROPERTY_NOT_CONFIGURABLE_NOT_HAVE_GETTER = "Property of a Proxy is non-configurable and does not have a getter function"
|
||||
ECMA_ERR_PROTOTYPE_FROM_REVOKED_PROXY_IS_INVALID = "Prototype from revoked Proxy is invalid"
|
||||
ECMA_ERR_PROTOTYPE_IS_NEITHER_OBJECT_NOR_NULL = "Prototype is neither object nor null"
|
||||
ECMA_ERR_PROXY_HANDLER_IS_NULL_FOR_ISARRAY_OPERATION = "Proxy handler is null for 'isArray' operation"
|
||||
ECMA_ERR_PROXY_IS_NOT_SUPPORTED = "Proxy is not supported"
|
||||
ECMA_ERR_TARGET_NOT_EXTENSIBLE_NOT_RETURNED_ITS_PROTOTYPE = "Proxy target is non-extensible, but the trap did not return its actual prototype"
|
||||
ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH = "Proxy trap returned falsish"
|
||||
ECMA_ERR_PUSHING_TOO_HIGH_ELEMENT = "Pushing element over 2**53-1 length is disallowed"
|
||||
ECMA_ERR_MIN_GREATER_THAN_MAX = "Quantifier error: min > max"
|
||||
ECMA_ERR_RADIX_IS_OUT_OF_RANGE = "Radix must be between 2 and 36"
|
||||
ECMA_ERR_RANGE_OUT_OF_ORDER_IN_CHARACTER_CLASS = "Range out of order in character class"
|
||||
ECMA_ERR_REALM_IS_NOT_AVAILABLE = "Realm is not available"
|
||||
ECMA_ERR_REALMS_ARE_DISABLED = "Realms are disabled"
|
||||
ECMA_ERR_REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE = "Reduce of empty Array with no initial value"
|
||||
ECMA_ERR_REFLECT_EXPECTS_AN_OBJECT_AS_SECOND_ARGUMENT = "Reflect.construct expects an object as second argument"
|
||||
ECMA_ERR_REGEXP_ARGUMENT_SHOULD_HAVE_GLOBAL_FLAG = "RegExp argument should have global flag"
|
||||
ECMA_ERR_REGEXP_IS_NOT_SUPPORTED = "RegExp is not supported"
|
||||
ECMA_ERR_REJECT_MUST_BE_UNDEFINED = "Reject must be undefined"
|
||||
ECMA_ERR_REQUEST_IS_NOT_AVAILABLE = "Request is not available"
|
||||
ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE = "Resolve method must be callable"
|
||||
ECMA_ERR_RESOLVE_MUST_BE_UNDEFINED = "Resolve must be undefined"
|
||||
ECMA_ERR_RESULT_OF_DEFAULTVALUE_IS_INVALID = "Result of [[DefaultValue]] is invalid"
|
||||
ECMA_ERR_RETURN_VALUE_IS_NOT_AN_ARRAYBUFFER_OBJECT = "Return value is not an ArrayBuffer object"
|
||||
ECMA_ERR_RETURN_VALUE_OF_EXEC_MUST_BE_AN_OBJECT_OR_NULL = "Return value of 'exec' must be an object or null"
|
||||
ECMA_ERR_RIGHT_VALUE_OF_IN_MUST_BE_AN_OBJECT = "Right value of 'in' must be an object"
|
||||
ECMA_ERR_RIGHT_VALUE_OF_INSTANCEOF_MUST_BE_AN_OBJECT = "Right value of 'instanceof' must be an object"
|
||||
ECMA_ERR_SEARCH_STRING_CANNOT_BE_OF_TYPE_REGEXP = "Search string can't be of type: RegExp"
|
||||
ECMA_ERR_SECOND_ARGUMENT_MUST_BE_AN_OBJECT = "Second argument must be an object"
|
||||
ECMA_ERR_SPECIES_MUST_BE_A_CONSTRUCTOR = "Species must be a constructor"
|
||||
ECMA_ERR_STACK_LIMIT_EXCEEDED = "Stack limit exceeded"
|
||||
ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER = "Start offset is outside the bounds of the buffer"
|
||||
ECMA_ERR_STATIC_SNAPSHOTS_ARE_NOT_ENABLED = "Static snapshots are not enabled"
|
||||
ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY = "Static snapshots cannot be copied into memory"
|
||||
ECMA_ERR_STRING_CANNOT_BE_CONVERTED_TO_BIGINT_VALUE = "String cannot be converted to BigInt value"
|
||||
ECMA_ERR_SUPER_BINDING_MUST_BE_A_CONSTRUCTOR = "Super binding must be a constructor"
|
||||
ECMA_ERR_SUPER_CONSTRUCTOR_MAY_ONLY_BE_CALLED_ONCE = "Super constructor may only be called once"
|
||||
ECMA_ERR_SYMBOL_IS_NOT_A_CONSTRUCTOR = "Symbol is not a constructor"
|
||||
ECMA_ERR_TARGET_IS_NOT_OBJECT = "Target is not Object"
|
||||
ECMA_ERR_TARGET_IS_NOT_WEAKREF = "Target is not weakRef"
|
||||
ECMA_ERR_TARGET_NOT_EXTENSIBLE = "Target not extensible"
|
||||
ECMA_ERR_TARGET_NOT_EXTENSIBLE_DIFFERENT_PROTOTYPE_RETURNED = "Target object is non-extensible and trap returned different prototype"
|
||||
ECMA_ERR_THE_MAPFN_ARGUMENT_IS_NOT_CALLABLE = "The 'mapfn' argument is not callable"
|
||||
ECMA_ERR_THE_GIVEN_ARGUMENT_IS_NOT_A_SYMBOL = "The given argument is not a Symbol"
|
||||
ECMA_ERR_TARGET_PROPERTY_CONFIGURE_ACCESSOR_WITHOUT_SETTER = "The property of a Proxy target is a non configurable accessor without a setter"
|
||||
ECMA_ERR_THE_REQUESTED_PROPERTY_UPDATE_CANNOT_BE_PERFORMED = "The requested property update cannot be performed"
|
||||
ECMA_ERR_THE_STRUCTURE_IS_CYCLICAL = "The structure is cyclical"
|
||||
ECMA_ERR_THE_TWO_DESCRIPTORS_ARE_INCOMPATIBLE = "The two descriptors are incompatible"
|
||||
ECMA_ERR_TOO_MANY_ARGUMENTS_DECLARED_FOR_FUNCTION_APPLY = "Too many arguments declared for Function.apply"
|
||||
ECMA_ERR_TRAP_IS_NEITHER_AN_OBJECT_NOR_UNDEFINED = "Trap is neither an object nor undefined"
|
||||
ECMA_ERR_TRAP_MUST_RETURN_WITH_AN_OBJECT = "Trap must return with an object"
|
||||
ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_CONFIGURABLE_KEYS = "Trap result did not include all configurable keys"
|
||||
ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_NON_CONFIGURABLE_KEYS = "Trap result did not include all non-configurable keys"
|
||||
ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_EXTENSIBILITY = "Trap result does not reflect extensibility of Proxy target"
|
||||
ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_INEXTENSIBILITY = "Trap result does not reflect inextensibility of Proxy target"
|
||||
ECMA_ERR_TRAP_EXTRA_KEYS_FOR_A_NON_EXTENSIBLE_TARGET = "Trap returned extra keys for a non-extensible Proxy target"
|
||||
ECMA_ERR_TRAP_FALSISH_PROPERTY_TARGET_NOT_EXTENSIBLE = "Trap returned falsish for property but the proxy target is not extensible"
|
||||
ECMA_ERR_TRAP_FALSISH_PROPERTY_NON_CONFIGURABLE = "Trap returned falsish for property which exists in the proxy target as non-configurable"
|
||||
ECMA_ERR_TRAP_RETURNED_NEITHER_OBJECT_NOR_NULL = "Trap returned neither object nor null"
|
||||
ECMA_ERR_TRAP_TRUISH_ADDING_PROPERTY_NON_EXTENSIBLE_TARGET = "Trap returned truish for adding property to the non-extensible target"
|
||||
ECMA_ERR_TRAP_TRUISH_ADD_PROPERTY_INCOMPATIBLE_OTHER_PROP = "Trap returned truish for adding property that is incompatible with the existing property in the target"
|
||||
ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY = "Trap returned truish for defining non-configurable property which is nonexistent in the target"
|
||||
ECMA_ERR_TRAP_TRUISH_PROPERTY_NON_CONFIGURABLE = "Trap returned truish for property which is non-configurable in the proxy target"
|
||||
ECMA_ERR_TRAP_TRUISH_TARGET_NOT_EXTENSIBLE = "Trap returned truish for target is not extensible"
|
||||
ECMA_ERR_TRAP_WITH_DUPLICATED_ENTRIES = "Trap returned with duplicated entries"
|
||||
ECMA_ERR_TYPEDARRAY_INTRINSIC_CALLED_BY_NEW_EXPRESSION = "TypedArray intrinsic cannot be called by a 'new' expression"
|
||||
ECMA_ERR_TYPEDARRAY_INTRINSIC_DIRECTLY_CALLED = "TypedArray intrinsic cannot be directly called"
|
||||
ECMA_ERR_CONTENTTYPE_RETURNED_TYPEDARRAY_NOT_MATCH_SOURCE = "TypedArray returned by [[ContentType]] does not match source"
|
||||
ECMA_ERR_UNARY_PLUS_IS_NOT_ALLOWED_FOR_BIGINTS = "Unary plus is not allowed for BigInts"
|
||||
ECMA_ERR_UNDEFINED_REFERENCE = "Undefined reference"
|
||||
ECMA_ERR_UNEXPECTED_END_OF_PATTERN = "Unexpected end of pattern"
|
||||
ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING = "Unicode surrogate pair missing"
|
||||
ECMA_ERR_UNMATCHED_CLOSE_BRACKET = "Unmatched close bracket"
|
||||
ECMA_ERR_UNSHIFT_TOO_HIGH = "Unshift elements over 2**53-1 length is disallowed"
|
||||
ECMA_ERR_UNSIGNED_RIGHT_SHIFT_IS_NOT_ALLOWED_FOR_BIGINTS = "Unsigned right shift is not allowed for BigInts"
|
||||
ECMA_ERR_UNSUPPORTED_BINARY_OPERATION = "Unsupported binary operation"
|
||||
ECMA_ERR_UNSUPPORTED_CONTAINER_OPERATION = "Unsupported container operation"
|
||||
ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED = "Unsupported snapshot exec flags are specified"
|
||||
ECMA_ERR_UNTERMINATED_CHARACTER_CLASS = "Unterminated character class"
|
||||
ECMA_ERR_UNTERMINATED_GROUP = "Unterminated group"
|
||||
ECMA_ERR_VALUE_CANNOT_BE_CONVERTED_TO_BIGINT = "Value cannot be converted to BigInt"
|
||||
ECMA_ERR_VALUE_FOR_CLASS_HERITAGE_IS_NOT_A_CONSTRUCTOR = "Value for class heritage is not a constructor"
|
||||
ECMA_ERR_VALUE_RECEIVED_BY_FOR_ASYNC_OF_IS_NOT_OBJECT = "Value received by for-async-of is not object"
|
||||
ECMA_ERR_VALUE_RECEIVED_BY_YIELD_IS_NOT_OBJECT = "Value received by yield* is not object"
|
||||
ECMA_ERR_WEAKREF_TARGET_MUST_BE_AN_OBJECT = "WeakRef target must be an object"
|
||||
ECMA_ERR_METHOD_RETURN_IS_NOT_CALLABLE = "method 'return' is not callable"
|
||||
ECMA_ERR_VALUE_MSG = "Argument cannot be marked as error"
|
||||
ECMA_ERR_WRONG_ARGS_MSG = "This type of argument is not allowed"
|
||||
ECMA_ERR_PARSER_NOT_SUPPORTED = "Source code parsing is disabled"
|
||||
ECMA_ERR_JSON_NOT_SUPPORTED = "JSON support is disabled"
|
||||
ECMA_ERR_TYPED_ARRAY_NOT_SUPPORTED = "TypedArray support is disabled"
|
||||
ECMA_ERR_SHARED_ARRAYBUFFER_NOT_SUPPORTED = "SharedArrayBuffer support is disabled"
|
||||
ECMA_ERR_DATA_VIEW_NOT_SUPPORTED = "DataView support is disabled"
|
||||
ECMA_ERR_BIGINT_NOT_SUPPORTED = "BigInt support is disabled"
|
||||
ECMA_ERR_CONTAINER_NOT_SUPPORTED = "Container support is disabled"
|
||||
ECMA_ERR_NOT_MODULE = "Argument is not a module"
|
||||
ECMA_ERR_UNKNOWN_EXPORT = "Native module export not found"
|
||||
ECMA_ERR_MODULE_NOT_SUPPORTED = "Module support is disabled"
|
||||
ECMA_ERR_CALLBACK_IS_NOT_CALLABLE = "Callback function is not callable"
|
||||
ECMA_ERR_ARRAYBUFFER_IS_DETACHED = "ArrayBuffer has been detached"
|
||||
ECMA_ERR_CANNOT_CONVERT_TO_OBJECT = "Cannot convert undefined or null to object"
|
||||
ECMA_ERR_CLASS_IS_NON_CONFIGURABLE = "Prototype property of a class is non-configurable"
|
||||
ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT = "Argument is not an object"
|
||||
ECMA_ERR_ARGUMENT_IS_NOT_A_PROXY = "Argument is not a Proxy object"
|
||||
ECMA_ERR_TARGET_IS_NOT_A_CONSTRUCTOR = "Target is not a constructor"
|
||||
ECMA_ERR_ARGUMENT_IS_NOT_AN_REGEXP = "Argument 'this' is not a RegExp object"
|
||||
ECMA_ERR_INVALID_ARRAY_LENGTH = "Invalid Array length"
|
||||
ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED = "Local variable is redeclared"
|
||||
ECMA_ERR_EXPECTED_A_FUNCTION = "Expected a function"
|
||||
ECMA_ERR_CLASS_CONSTRUCTOR_NEW = "Class constructor cannot be invoked without 'new'"
|
||||
ECMA_ERR_LET_CONST_NOT_INITIALIZED = "Variables declared by let/const must be initialized before reading their value"
|
||||
ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE = "Maximum snapshot size reached"
|
||||
ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED = "Regular expression literals are not supported"
|
||||
ECMA_ERR_SNAPSHOT_BUFFER_SMALL = "Snapshot buffer too small"
|
||||
ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE = "Unsupported compiled code"
|
||||
ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED = "Unsupported generate snapshot flags specified"
|
||||
ECMA_ERR_SNAPSHOT_SAVE_DISABLED = "Snapshot generation is disabled"
|
||||
ECMA_ERR_SNAPSHOT_EXEC_DISABLED = "Snapshot execution is disabled"
|
||||
ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS = "Cannot allocate memory for literals"
|
||||
ECMA_ERR_TAGGED_TEMPLATE_LITERALS = "Unsupported feature: tagged template literals"
|
||||
ECMA_ERR_CONTAINER_NEEDED = "Value is not a Container or Iterator"
|
||||
ECMA_ERR_INCORRECT_TYPE_CALL = "Operator called on incorrect container type"
|
||||
ECMA_ERR_INVALID_TYPE_FOR_CONSTRUCTOR_CALL = "Invalid type for constructor call"
|
||||
ECMA_ERR_SCRIPT_GLOBAL_FUNCTIONS_INVOKE_WITH_NEW = "Script (global) functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW = "Generator functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_ASYNC_FUNCTIONS_INVOKE_WITH_NEW = "Async functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_ASYNC_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW = "Async generator functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_ACCESSOR_FUNCTIONS_INVOKE_WITH_NEW = "Accessor functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_METHODS_INVOKE_WITH_NEW = "Methods cannot be invoked with 'new'"
|
||||
ECMA_ERR_ARROW_FUNCTIONS_INVOKE_WITH_NEW = "Arrow functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_ASYNC_ARROW_FUNCTIONS_INVOKE_WITH_NEW = "Async arrow functions cannot be invoked with 'new'"
|
||||
ECMA_ERR_PROXY_TARGET_IS_NOT_A_CONSTRUCTOR = "Proxy target is not a constructor"
|
||||
ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED = "Maximum call stack size exceeded"
|
||||
ECMA_ERR_INVALID_SNAPSHOT_FORMAT = "Invalid snapshot format"
|
||||
ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES = "Invalid snapshot version or unsupported features present"
|
||||
ECMA_ERR_RECEIVER_MUST_BE_AN_OBJECT = "Receiver must be an object"
|
||||
ECMA_ERR_CANNOT_DECLARE_SAME_PRIVATE_FIELD_TWICE = "Cannot declare same private field twice"
|
||||
ECMA_ERR_CANNOT_WRITE_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT = "Cannot write private member to an object whose class did not declare it"
|
||||
ECMA_ERR_PRIVATE_METHOD_IS_NOT_WRITABLE = "Private method is not writable"
|
||||
ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_SETTER = "Private field was defined without a setter"
|
||||
ECMA_ERR_CANNOT_READ_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT = "Cannot read private member to an object whose class did not declare it"
|
||||
ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_GETTER = "Private field was defined without a getter"
|
||||
@@ -0,0 +1,71 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-errors.h"
|
||||
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
/**
|
||||
* Struct to store ecma error message with its size.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *text; /* Text of ecma error message. */
|
||||
uint8_t size; /* Size of ecma error message. */
|
||||
} ecma_error_message_t;
|
||||
|
||||
/* Error message texts with size. */
|
||||
static ecma_error_message_t ecma_error_messages[] JERRY_ATTR_CONST_DATA = {
|
||||
{ "", 0 }, /* ECMA_ERR_EMPTY */
|
||||
/** @cond doxygen_suppress */
|
||||
#define ECMA_ERROR_DEF(id, string) { string, sizeof (string) - 1 },
|
||||
#include "ecma-error-messages.inc.h"
|
||||
#undef ECMA_ERROR_DEF
|
||||
/** @endcond */
|
||||
};
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
|
||||
/**
|
||||
* Get specified ecma error as zero-terminated string
|
||||
*
|
||||
* @return pointer to zero-terminated ecma error
|
||||
*/
|
||||
const char *
|
||||
ecma_get_error_msg (ecma_error_msg_t id) /**< ecma error id */
|
||||
{
|
||||
JERRY_ASSERT (id != ECMA_IS_VALID_CONSTRUCTOR);
|
||||
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
return ecma_error_messages[id].text;
|
||||
#else /* !JERRY_ERROR_MESSAGES */
|
||||
return NULL;
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
} /* ecma_get_error_msg */
|
||||
|
||||
/**
|
||||
* Get size of specified ecma error
|
||||
*
|
||||
* @return size in bytes
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_get_error_size (ecma_error_msg_t id) /**< ecma error id */
|
||||
{
|
||||
JERRY_ASSERT (id != ECMA_IS_VALID_CONSTRUCTOR);
|
||||
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
return ecma_error_messages[id].size;
|
||||
#else /* !JERRY_ERROR_MESSAGES */
|
||||
return 0;
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
} /* ecma_get_error_size */
|
||||
@@ -0,0 +1,39 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_ERRORS_H
|
||||
#define ECMA_ERRORS_H
|
||||
|
||||
#include "lit-globals.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ECMA_ERR_EMPTY,
|
||||
/** @cond doxygen_suppress */
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
#define ECMA_ERROR_DEF(id, ascii_zt_string) id,
|
||||
#else /* !JERRY_ERROR_MESSAGES */
|
||||
#define ECMA_ERROR_DEF(id, ascii_zt_string) id = ECMA_ERR_EMPTY,
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
#include "ecma-error-messages.inc.h"
|
||||
#undef ECMA_ERROR_DEF
|
||||
/** @endcond */
|
||||
ECMA_IS_VALID_CONSTRUCTOR /* used as return value when checking constructor */
|
||||
} ecma_error_msg_t;
|
||||
|
||||
const char* ecma_get_error_msg (ecma_error_msg_t id);
|
||||
lit_utf8_size_t ecma_get_error_size (ecma_error_msg_t id);
|
||||
|
||||
#endif /* !ECMA_ERRORS_H */
|
||||
@@ -0,0 +1,137 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-extended-info.h"
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "byte-code.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaextendedinfo Extended info
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Decodes an uint32_t number, and updates the buffer position.
|
||||
*
|
||||
* @return the decoded value
|
||||
*/
|
||||
uint32_t
|
||||
ecma_extended_info_decode_vlq (uint8_t **buffer_p) /**< [in/out] target buffer */
|
||||
{
|
||||
uint8_t *source_p = *buffer_p;
|
||||
uint32_t value = 0;
|
||||
|
||||
do
|
||||
{
|
||||
source_p--;
|
||||
value = (value << ECMA_EXTENDED_INFO_VLQ_SHIFT) | (*source_p & ECMA_EXTENDED_INFO_VLQ_MASK);
|
||||
} while (*source_p & ECMA_EXTENDED_INFO_VLQ_CONTINUE);
|
||||
|
||||
*buffer_p = source_p;
|
||||
return value;
|
||||
} /* ecma_extended_info_decode_vlq */
|
||||
|
||||
/**
|
||||
* Encodes an uint32_t number into a buffer.
|
||||
*/
|
||||
void
|
||||
ecma_extended_info_encode_vlq (uint8_t **buffer_p, /**< target buffer */
|
||||
uint32_t value) /**< encoded value */
|
||||
{
|
||||
uint8_t *destination_p = *buffer_p - 1;
|
||||
|
||||
if (value <= ECMA_EXTENDED_INFO_VLQ_MASK)
|
||||
{
|
||||
*destination_p = (uint8_t) value;
|
||||
*buffer_p = destination_p;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
uint32_t current_value = value >> ECMA_EXTENDED_INFO_VLQ_SHIFT;
|
||||
|
||||
do
|
||||
{
|
||||
current_value >>= ECMA_EXTENDED_INFO_VLQ_SHIFT;
|
||||
length++;
|
||||
} while (current_value > 0);
|
||||
|
||||
destination_p -= length;
|
||||
*buffer_p = destination_p;
|
||||
|
||||
do
|
||||
{
|
||||
*destination_p++ = (uint8_t) (value | ECMA_EXTENDED_INFO_VLQ_CONTINUE);
|
||||
value >>= ECMA_EXTENDED_INFO_VLQ_SHIFT;
|
||||
} while (value > 0);
|
||||
|
||||
**buffer_p &= ECMA_EXTENDED_INFO_VLQ_MASK;
|
||||
} /* ecma_extended_info_encode_vlq */
|
||||
|
||||
/**
|
||||
* Gets the encoded length of a number.
|
||||
*
|
||||
* @return encoded length
|
||||
*/
|
||||
uint32_t
|
||||
ecma_extended_info_get_encoded_length (uint32_t value) /**< encoded value */
|
||||
{
|
||||
uint32_t length = 0;
|
||||
|
||||
do
|
||||
{
|
||||
value >>= ECMA_EXTENDED_INFO_VLQ_SHIFT;
|
||||
length++;
|
||||
} while (value > 0);
|
||||
|
||||
return length;
|
||||
} /* ecma_extended_info_get_encoded_length */
|
||||
|
||||
/**
|
||||
* Get the extended info from a byte code
|
||||
*
|
||||
* @return pointer to the extended info
|
||||
*/
|
||||
uint8_t *
|
||||
ecma_compiled_code_resolve_extended_info (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */
|
||||
{
|
||||
JERRY_ASSERT (bytecode_header_p != NULL);
|
||||
JERRY_ASSERT (bytecode_header_p->status_flags & CBC_CODE_FLAGS_HAS_EXTENDED_INFO);
|
||||
|
||||
ecma_value_t *base_p = ecma_compiled_code_resolve_arguments_start (bytecode_header_p);
|
||||
|
||||
if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR)
|
||||
{
|
||||
base_p--;
|
||||
}
|
||||
|
||||
if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS)
|
||||
{
|
||||
base_p--;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (((uint8_t *) base_p)[-1] != 0);
|
||||
|
||||
return ((uint8_t *) base_p) - 1;
|
||||
} /* ecma_compiled_code_resolve_extended_info */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_EXTENDED_INFO_H
|
||||
#define ECMA_EXTENDED_INFO_H
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaextendedinfo Extended info
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/**
|
||||
* Vlq encoding: flag which is set for all bytes except the last one.
|
||||
*/
|
||||
#define ECMA_EXTENDED_INFO_VLQ_CONTINUE 0x80
|
||||
|
||||
/**
|
||||
* Vlq encoding: mask to decode the number fragment.
|
||||
*/
|
||||
#define ECMA_EXTENDED_INFO_VLQ_MASK 0x7f
|
||||
|
||||
/**
|
||||
* Vlq encoding: number of bits stored in a byte.
|
||||
*/
|
||||
#define ECMA_EXTENDED_INFO_VLQ_SHIFT 7
|
||||
|
||||
uint32_t ecma_extended_info_decode_vlq (uint8_t **buffer_p);
|
||||
void ecma_extended_info_encode_vlq (uint8_t **buffer_p, uint32_t value);
|
||||
uint32_t ecma_extended_info_get_encoded_length (uint32_t value);
|
||||
|
||||
uint8_t *ecma_compiled_code_resolve_extended_info (const ecma_compiled_code_t *bytecode_header_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_EXTENDED_INFO_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_GC_H
|
||||
#define ECMA_GC_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#include "jmem.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmagc Garbage collector
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Free option flags
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_GC_FREE_NO_OPTIONS = 0, /**< no options */
|
||||
ECMA_GC_FREE_SECOND_PROPERTY = (1 << 0), /**< free second property of a property pair */
|
||||
ECMA_GC_FREE_REFERENCES = (1 << 1), /**< free references */
|
||||
} ecma_gc_free_options_t;
|
||||
|
||||
void ecma_init_gc_info (ecma_object_t *object_p);
|
||||
void ecma_ref_object (ecma_object_t *object_p);
|
||||
void ecma_ref_object_inline (ecma_object_t *object_p);
|
||||
void ecma_deref_object (ecma_object_t *object_p);
|
||||
void ecma_gc_free_property (ecma_object_t *object_p, ecma_property_pair_t *prop_pair_p, uint32_t options);
|
||||
void ecma_gc_free_properties (ecma_object_t *object_p, uint32_t options);
|
||||
void ecma_gc_run (void);
|
||||
void ecma_free_unused_memory (jmem_pressure_t pressure);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_GC_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,446 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate a collection of ecma values.
|
||||
*
|
||||
* @return pointer to the collection
|
||||
*/
|
||||
ecma_collection_t *
|
||||
ecma_new_collection (void)
|
||||
{
|
||||
ecma_collection_t *collection_p;
|
||||
collection_p = (ecma_collection_t *) jmem_heap_alloc_block (sizeof (ecma_collection_t));
|
||||
|
||||
collection_p->item_count = 0;
|
||||
collection_p->capacity = ECMA_COLLECTION_INITIAL_CAPACITY;
|
||||
const uint32_t size = ECMA_COLLECTION_ALLOCATED_SIZE (ECMA_COLLECTION_INITIAL_CAPACITY);
|
||||
collection_p->buffer_p = (ecma_value_t *) jmem_heap_alloc_block (size);
|
||||
|
||||
return collection_p;
|
||||
} /* ecma_new_collection */
|
||||
|
||||
/**
|
||||
* Deallocate a collection of ecma values without freeing it's values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_collection_destroy (ecma_collection_t *collection_p) /**< value collection */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
|
||||
jmem_heap_free_block (collection_p->buffer_p, ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity));
|
||||
jmem_heap_free_block (collection_p, sizeof (ecma_collection_t));
|
||||
} /* ecma_collection_destroy */
|
||||
|
||||
/**
|
||||
* Free the object collection elements and deallocate the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_free_objects (ecma_collection_t *collection_p) /**< value collection */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
if (ecma_is_value_object (buffer_p[i]))
|
||||
{
|
||||
ecma_deref_object (ecma_get_object_from_value (buffer_p[i]));
|
||||
}
|
||||
}
|
||||
|
||||
ecma_collection_destroy (collection_p);
|
||||
} /* ecma_collection_free_objects */
|
||||
|
||||
/**
|
||||
* Free the template literal objects and deallocate the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_free_template_literal (ecma_collection_t *collection_p) /**< value collection */
|
||||
{
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (collection_p->buffer_p[i]);
|
||||
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
|
||||
ecma_extended_object_t *array_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
JERRY_ASSERT (array_object_p->u.array.length_prop_and_hole_count & ECMA_ARRAY_TEMPLATE_LITERAL);
|
||||
array_object_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_ARRAY_TEMPLATE_LITERAL;
|
||||
|
||||
ecma_property_value_t *property_value_p;
|
||||
|
||||
property_value_p = ecma_get_named_data_property (object_p, ecma_get_magic_string (LIT_MAGIC_STRING_RAW));
|
||||
ecma_object_t *raw_object_p = ecma_get_object_from_value (property_value_p->value);
|
||||
|
||||
JERRY_ASSERT (ecma_get_object_type (raw_object_p) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
|
||||
array_object_p = (ecma_extended_object_t *) raw_object_p;
|
||||
|
||||
JERRY_ASSERT (array_object_p->u.array.length_prop_and_hole_count & ECMA_ARRAY_TEMPLATE_LITERAL);
|
||||
array_object_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_ARRAY_TEMPLATE_LITERAL;
|
||||
|
||||
ecma_deref_object (raw_object_p);
|
||||
ecma_deref_object (object_p);
|
||||
}
|
||||
|
||||
ecma_collection_destroy (collection_p);
|
||||
} /* ecma_collection_free_template_literal */
|
||||
|
||||
/**
|
||||
* Free the non-object collection elements and deallocate the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_free_if_not_object (ecma_collection_t *collection_p) /**< value collection */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_free_value_if_not_object (buffer_p[i]);
|
||||
}
|
||||
|
||||
ecma_collection_destroy (collection_p);
|
||||
} /* ecma_collection_free_if_not_object */
|
||||
|
||||
/**
|
||||
* Free the collection elements and deallocate the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_free (ecma_collection_t *collection_p) /**< value collection */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_free_value (buffer_p[i]);
|
||||
}
|
||||
|
||||
ecma_collection_destroy (collection_p);
|
||||
} /* ecma_collection_free */
|
||||
|
||||
/**
|
||||
* Append new value to ecma values collection
|
||||
*
|
||||
* Note: The reference count of the values are not increased
|
||||
*/
|
||||
void
|
||||
ecma_collection_push_back (ecma_collection_t *collection_p, /**< value collection */
|
||||
ecma_value_t value) /**< ecma value to append */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
if (JERRY_LIKELY (collection_p->item_count < collection_p->capacity))
|
||||
{
|
||||
buffer_p[collection_p->item_count++] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t new_capacity = collection_p->capacity + ECMA_COLLECTION_GROW_FACTOR;
|
||||
const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity);
|
||||
const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity);
|
||||
|
||||
buffer_p = (ecma_value_t *) jmem_heap_realloc_block (buffer_p, old_size, new_size);
|
||||
buffer_p[collection_p->item_count++] = value;
|
||||
collection_p->capacity = new_capacity;
|
||||
|
||||
collection_p->buffer_p = buffer_p;
|
||||
} /* ecma_collection_push_back */
|
||||
|
||||
/**
|
||||
* Reserve space for the given amount of ecma_values in the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_reserve (ecma_collection_t *collection_p, /**< value collection */
|
||||
uint32_t count) /**< number of ecma values to reserve */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
JERRY_ASSERT (UINT32_MAX - count > collection_p->capacity);
|
||||
|
||||
const uint32_t new_capacity = collection_p->capacity + count;
|
||||
const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity);
|
||||
const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity);
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
buffer_p = (ecma_value_t *) jmem_heap_realloc_block (buffer_p, old_size, new_size);
|
||||
|
||||
collection_p->capacity = new_capacity;
|
||||
collection_p->buffer_p = buffer_p;
|
||||
} /* ecma_collection_reserve */
|
||||
|
||||
/**
|
||||
* Append a list of values to the end of the collection
|
||||
*/
|
||||
void
|
||||
ecma_collection_append (ecma_collection_t *collection_p, /**< value collection */
|
||||
const ecma_value_t *buffer_p, /**< values to append */
|
||||
uint32_t count) /**< number of ecma values to append */
|
||||
{
|
||||
JERRY_ASSERT (collection_p != NULL);
|
||||
JERRY_ASSERT (collection_p->capacity >= collection_p->item_count);
|
||||
|
||||
uint32_t free_count = collection_p->capacity - collection_p->item_count;
|
||||
|
||||
if (free_count < count)
|
||||
{
|
||||
ecma_collection_reserve (collection_p, count - free_count);
|
||||
}
|
||||
|
||||
memcpy (collection_p->buffer_p + collection_p->item_count, buffer_p, count * sizeof (ecma_value_t));
|
||||
collection_p->item_count += count;
|
||||
} /* ecma_collection_append */
|
||||
|
||||
/**
|
||||
* Helper function to check if a given collection have duplicated properties or not
|
||||
*
|
||||
* @return true - if there are duplicated properties in the collection
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_collection_check_duplicated_entries (ecma_collection_t *collection_p) /**< prop name collection */
|
||||
{
|
||||
if (collection_p->item_count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count - 1; i++)
|
||||
{
|
||||
ecma_string_t *current_name_p = ecma_get_prop_name_from_value (buffer_p[i]);
|
||||
|
||||
for (uint32_t j = i + 1; j < collection_p->item_count; j++)
|
||||
{
|
||||
if (ecma_compare_ecma_strings (current_name_p, ecma_get_prop_name_from_value (buffer_p[j])))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_collection_check_duplicated_entries */
|
||||
|
||||
/**
|
||||
* Check the string value existence in the collection.
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_stringify step 4.b.ii.5
|
||||
* - ecma_op_object_enumerate
|
||||
*
|
||||
* @return true, if the string is already in the collection.
|
||||
*/
|
||||
bool
|
||||
ecma_collection_has_string_value (ecma_collection_t *collection_p, /**< collection */
|
||||
ecma_string_t *string_p) /**< string */
|
||||
{
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
if (ecma_compare_ecma_strings (current_p, string_p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_collection_has_string_value */
|
||||
|
||||
/**
|
||||
* Initial capacity of an ecma-collection
|
||||
*/
|
||||
#define ECMA_COMPACT_COLLECTION_GROWTH 8
|
||||
|
||||
/**
|
||||
* Set the size of the compact collection
|
||||
*/
|
||||
#define ECMA_COMPACT_COLLECTION_SET_SIZE(compact_collection_p, item_count, unused_items) \
|
||||
((compact_collection_p)[0] = (((item_count) << ECMA_COMPACT_COLLECTION_SIZE_SHIFT) | (unused_items)))
|
||||
|
||||
/**
|
||||
* Set the size of the compact collection
|
||||
*/
|
||||
#define ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT(compact_collection_p) \
|
||||
((compact_collection_p)[0] & ((1 << ECMA_COMPACT_COLLECTION_SIZE_SHIFT) - 1))
|
||||
|
||||
/**
|
||||
* Allocate a compact collection of ecma values
|
||||
*
|
||||
* @return pointer to the compact collection
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_new_compact_collection (void)
|
||||
{
|
||||
size_t size = (ECMA_COMPACT_COLLECTION_GROWTH / 2) * sizeof (ecma_value_t);
|
||||
ecma_value_t *compact_collection_p = (ecma_value_t *) jmem_heap_alloc_block (size);
|
||||
|
||||
ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p,
|
||||
ECMA_COMPACT_COLLECTION_GROWTH / 2,
|
||||
(ECMA_COMPACT_COLLECTION_GROWTH / 2) - 1);
|
||||
return compact_collection_p;
|
||||
} /* ecma_new_compact_collection */
|
||||
|
||||
/**
|
||||
* Append a value to the compact collection
|
||||
*
|
||||
* @return updated pointer to the compact collection
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_compact_collection_push_back (ecma_value_t *compact_collection_p, /**< compact collection */
|
||||
ecma_value_t value) /**< ecma value to append */
|
||||
{
|
||||
ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p);
|
||||
ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p);
|
||||
|
||||
if (unused_items > 0)
|
||||
{
|
||||
compact_collection_p[size - unused_items] = value;
|
||||
(*compact_collection_p)--;
|
||||
return compact_collection_p;
|
||||
}
|
||||
|
||||
if (size == ECMA_COMPACT_COLLECTION_GROWTH / 2)
|
||||
{
|
||||
size_t old_size = (ECMA_COMPACT_COLLECTION_GROWTH / 2) * sizeof (ecma_value_t);
|
||||
size_t new_size = ECMA_COMPACT_COLLECTION_GROWTH * sizeof (ecma_value_t);
|
||||
compact_collection_p = (ecma_value_t *) jmem_heap_realloc_block (compact_collection_p, old_size, new_size);
|
||||
|
||||
compact_collection_p[ECMA_COMPACT_COLLECTION_GROWTH / 2] = value;
|
||||
|
||||
ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p,
|
||||
ECMA_COMPACT_COLLECTION_GROWTH,
|
||||
(ECMA_COMPACT_COLLECTION_GROWTH / 2) - 1);
|
||||
return compact_collection_p;
|
||||
}
|
||||
|
||||
size_t old_size = size * sizeof (ecma_value_t);
|
||||
size_t new_size = old_size + (ECMA_COMPACT_COLLECTION_GROWTH * sizeof (ecma_value_t));
|
||||
|
||||
compact_collection_p = (ecma_value_t *) jmem_heap_realloc_block (compact_collection_p, old_size, new_size);
|
||||
compact_collection_p[size] = value;
|
||||
|
||||
ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p,
|
||||
size + ECMA_COMPACT_COLLECTION_GROWTH,
|
||||
ECMA_COMPACT_COLLECTION_GROWTH - 1);
|
||||
return compact_collection_p;
|
||||
} /* ecma_compact_collection_push_back */
|
||||
|
||||
/**
|
||||
* Discard the unused elements of a compact collection
|
||||
*
|
||||
* Note:
|
||||
* further items should not be added after this call
|
||||
*
|
||||
* @return updated pointer to the compact collection
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_compact_collection_shrink (ecma_value_t *compact_collection_p) /**< compact collection */
|
||||
{
|
||||
ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p);
|
||||
|
||||
if (unused_items == 0)
|
||||
{
|
||||
return compact_collection_p;
|
||||
}
|
||||
|
||||
ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p);
|
||||
|
||||
size_t old_size = size * sizeof (ecma_value_t);
|
||||
size_t new_size = (size - unused_items) * sizeof (ecma_value_t);
|
||||
|
||||
compact_collection_p = (ecma_value_t *) jmem_heap_realloc_block (compact_collection_p, old_size, new_size);
|
||||
|
||||
ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p, size - unused_items, 0);
|
||||
return compact_collection_p;
|
||||
} /* ecma_compact_collection_shrink */
|
||||
|
||||
/**
|
||||
* Free a compact collection
|
||||
*/
|
||||
void
|
||||
ecma_compact_collection_free (ecma_value_t *compact_collection_p) /**< compact collection */
|
||||
{
|
||||
ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p);
|
||||
ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p);
|
||||
|
||||
ecma_value_t *end_p = compact_collection_p + size - unused_items;
|
||||
ecma_value_t *current_p = compact_collection_p + 1;
|
||||
|
||||
while (current_p < end_p)
|
||||
{
|
||||
ecma_free_value (*current_p++);
|
||||
}
|
||||
|
||||
jmem_heap_free_block (compact_collection_p, size * sizeof (ecma_value_t));
|
||||
} /* ecma_compact_collection_free */
|
||||
|
||||
/**
|
||||
* Get the end of a compact collection
|
||||
*
|
||||
* @return pointer to the compact collection end
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_compact_collection_end (ecma_value_t *compact_collection_p) /**< compact collection */
|
||||
{
|
||||
ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p);
|
||||
ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p);
|
||||
|
||||
return compact_collection_p + size - unused_items;
|
||||
} /* ecma_compact_collection_end */
|
||||
|
||||
/**
|
||||
* Destroy a compact collection
|
||||
*/
|
||||
void
|
||||
ecma_compact_collection_destroy (ecma_value_t *compact_collection_p) /**< compact collection */
|
||||
{
|
||||
ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p);
|
||||
|
||||
jmem_heap_free_block (compact_collection_p, size * sizeof (ecma_value_t));
|
||||
} /* ecma_compact_collection_destroy */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,943 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers-number.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "lit-char-helpers.h"
|
||||
#include "lit-magic-strings.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
|
||||
/**
|
||||
* \addtogroup ecmahelpersbigintegers Helpers for operations intermediate 128-bit integers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 128-bit integer type
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint64_t hi; /**< high 64 bits */
|
||||
uint64_t lo; /**< low 64 bits */
|
||||
} ecma_uint128_t;
|
||||
|
||||
/**
|
||||
* Round high part of 128-bit integer to uint64_t
|
||||
*
|
||||
* @return rounded high to uint64_t
|
||||
*/
|
||||
static uint64_t
|
||||
ecma_round_high_to_uint64 (ecma_uint128_t *num_p)
|
||||
{
|
||||
uint64_t masked_lo = num_p->lo & ~(1ULL << 63u);
|
||||
uint64_t masked_hi = num_p->hi & 0x1;
|
||||
|
||||
if ((num_p->lo >> 63u != 0) && (masked_lo > 0 || masked_hi != 0))
|
||||
{
|
||||
return (num_p->hi + 1);
|
||||
}
|
||||
|
||||
return num_p->hi;
|
||||
} /* ecma_round_high_to_uint64 */
|
||||
|
||||
/**
|
||||
* Left shift 128-bit integer by max 63 bits.
|
||||
*/
|
||||
static void
|
||||
ecma_uint128_shift_left (ecma_uint128_t *num_p, int32_t shift)
|
||||
{
|
||||
num_p->hi = (num_p->hi << shift) | (num_p->lo >> (64 - shift));
|
||||
num_p->lo <<= shift;
|
||||
} /* ecma_uint128_shift_left */
|
||||
|
||||
/**
|
||||
* Right shift 128-bit integer by max 63 bits.
|
||||
*/
|
||||
static void
|
||||
ecma_uint128_shift_right (ecma_uint128_t *num_p, int32_t shift)
|
||||
{
|
||||
num_p->lo = (num_p->lo >> shift) | (num_p->hi << (64 - shift));
|
||||
num_p->hi >>= shift;
|
||||
} /* ecma_uint128_shift_right */
|
||||
|
||||
/**
|
||||
* Add two 128-bit integer values and assign the result to the left one.
|
||||
*/
|
||||
static void
|
||||
ecma_uint128_add (ecma_uint128_t *left_p, ecma_uint128_t *right_p)
|
||||
{
|
||||
left_p->hi += right_p->hi;
|
||||
left_p->lo += right_p->lo;
|
||||
|
||||
if (left_p->lo < right_p->lo)
|
||||
{
|
||||
left_p->hi++;
|
||||
}
|
||||
} /* ecma_uint128_add */
|
||||
|
||||
/**
|
||||
* Multiply 128-bit integer by 10
|
||||
*/
|
||||
static void
|
||||
ecma_uint128_mul10 (ecma_uint128_t *num_p)
|
||||
{
|
||||
ecma_uint128_shift_left (num_p, 1u);
|
||||
|
||||
ecma_uint128_t tmp = { num_p->hi, num_p->lo };
|
||||
ecma_uint128_shift_left (&tmp, 2u);
|
||||
|
||||
ecma_uint128_add (num_p, &tmp);
|
||||
} /* ecma_uint128_mul10 */
|
||||
|
||||
/**
|
||||
* Divide 128-bit integer by 10
|
||||
*
|
||||
* N = N3 *2^96 + N2 *2^64 + N1 *2^32 + N0 *2^0 // 128-bit dividend
|
||||
* T = T3 *2^-32 + T2 *2^-64 + T1 *2^-96 + T0 *2^-128 // 128-bit divisor reciprocal, 1/10 * 2^-128
|
||||
*
|
||||
* N * T = N3*T3 *2^64 + N2*T3 *2^32 + N1*T3 *2^0 + N0*T3 *2^-32
|
||||
* + N3*T2 *2^32 + N2*T2 *2^0 + N1*T2 *2^-32 + N0*T2 *2^-64
|
||||
* + N3*T1 *2^0 + N2*T1 *2^-32 + N1*T1 *2^-64 + N0*T1 *2^-96
|
||||
* + N3*T0 *2^-32 + N2*T0 *2^-64 + N1*T0 *2^-96 + N0*T0 *2^-128
|
||||
*
|
||||
* Q3=carry Q2=^+carry Q1=^+carry Q0=^+carry fraction=^...
|
||||
*
|
||||
* Q = Q3 *2^96 + Q2 *2^64 + Q1 *2^32 + Q0 *2^0 // 128-bit quotient
|
||||
*/
|
||||
static void
|
||||
ecma_uint128_div10 (ecma_uint128_t *num_p)
|
||||
{
|
||||
/* estimation of reciprocal of 10, 128 bits right of the binary point (T1 == T2) */
|
||||
const uint64_t tenth_l = 0x9999999aul;
|
||||
const uint64_t tenth_m = 0x99999999ul;
|
||||
const uint64_t tenth_h = 0x19999999ul;
|
||||
|
||||
const uint64_t l0 = ((uint32_t) num_p->lo) * tenth_l;
|
||||
const uint64_t l1 = (num_p->lo >> 32u) * tenth_l;
|
||||
const uint64_t l2 = ((uint32_t) num_p->hi) * tenth_l;
|
||||
const uint64_t l3 = (num_p->hi >> 32u) * tenth_l;
|
||||
const uint64_t m0 = ((uint32_t) num_p->lo) * tenth_m;
|
||||
const uint64_t m1 = (num_p->lo >> 32u) * tenth_m;
|
||||
const uint64_t m2 = ((uint32_t) num_p->hi) * tenth_m;
|
||||
const uint64_t m3 = (num_p->hi >> 32u) * tenth_m;
|
||||
const uint64_t h0 = ((uint32_t) num_p->lo) * tenth_h;
|
||||
const uint64_t h1 = (num_p->lo >> 32u) * tenth_h;
|
||||
const uint64_t h2 = ((uint32_t) num_p->hi) * tenth_h;
|
||||
const uint64_t h3 = (num_p->hi >> 32u) * tenth_h;
|
||||
|
||||
uint64_t q0 = l0 >> 32u;
|
||||
q0 += (uint32_t) l1;
|
||||
q0 += (uint32_t) m0;
|
||||
|
||||
q0 >>= 32u;
|
||||
q0 += l1 >> 32u;
|
||||
q0 += m0 >> 32u;
|
||||
q0 += (uint32_t) l2;
|
||||
q0 += (uint32_t) m1;
|
||||
q0 += (uint32_t) m0;
|
||||
|
||||
q0 >>= 32u;
|
||||
q0 += l2 >> 32u;
|
||||
q0 += m1 >> 32u;
|
||||
q0 += m0 >> 32u;
|
||||
q0 += (uint32_t) l3;
|
||||
q0 += (uint32_t) m2;
|
||||
q0 += (uint32_t) m1;
|
||||
q0 += (uint32_t) h0;
|
||||
|
||||
q0 >>= 32u;
|
||||
q0 += l3 >> 32u;
|
||||
q0 += m2 >> 32u;
|
||||
q0 += m1 >> 32u;
|
||||
q0 += h0 >> 32u;
|
||||
q0 += (uint32_t) m3;
|
||||
q0 += (uint32_t) m2;
|
||||
q0 += (uint32_t) h1;
|
||||
|
||||
uint64_t q1 = q0 >> 32u;
|
||||
q1 += m3 >> 32u;
|
||||
q1 += m2 >> 32u;
|
||||
q1 += h1 >> 32u;
|
||||
q1 += (uint32_t) m3;
|
||||
q1 += (uint32_t) h2;
|
||||
|
||||
uint64_t q32 = q1 >> 32u;
|
||||
q32 += m3 >> 32u;
|
||||
q32 += h2 >> 32u;
|
||||
q32 += h3;
|
||||
|
||||
num_p->lo = (q1 << 32u) | ((uint32_t) q0);
|
||||
num_p->hi = q32;
|
||||
} /* ecma_uint128_div10 */
|
||||
|
||||
/**
|
||||
* Count leading zeros in a 64-bit integer. The behaviour is undefined for 0.
|
||||
*
|
||||
* @return number of leading zeros.
|
||||
*/
|
||||
inline static int JERRY_ATTR_CONST
|
||||
ecma_uint64_clz (uint64_t n) /**< integer to count leading zeros in */
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_clzll (n);
|
||||
#else /* !defined (__GNUC__) && !defined (__clang__) */
|
||||
JERRY_ASSERT (n != 0);
|
||||
|
||||
int cnt = 0;
|
||||
uint64_t one = 0x8000000000000000ull;
|
||||
|
||||
while ((n & one) == 0)
|
||||
{
|
||||
cnt++;
|
||||
one >>= 1;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
#endif /* !defined (__GNUC__) && !defined (__clang__) */
|
||||
} /* ecma_uint64_clz */
|
||||
|
||||
/**
|
||||
* Count leading zeros in the top 4 bits of a 64-bit integer.
|
||||
*
|
||||
* @return number of leading zeros in top 4 bits.
|
||||
*/
|
||||
inline static int JERRY_ATTR_CONST
|
||||
ecma_uint64_clz_top4 (uint64_t n) /**< integer to count leading zeros in */
|
||||
{
|
||||
static const uint8_t ecma_uint4_clz[] = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
return ecma_uint4_clz[n >> 60];
|
||||
} /* ecma_uint64_clz */
|
||||
|
||||
/**
|
||||
* Shift required to clear 4 bits of a 64-bit integer.
|
||||
*
|
||||
* @return 0-4
|
||||
*/
|
||||
inline static int JERRY_ATTR_CONST
|
||||
ecma_uint64_normalize_shift (uint64_t n) /**< integer to count leading zeros in */
|
||||
{
|
||||
static const uint8_t ecma_uint4_shift[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };
|
||||
|
||||
return ecma_uint4_shift[n >> 60];
|
||||
} /* ecma_uint64_normalize_shift */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Number.MAX_VALUE exponent part when using 64 bit float representation.
|
||||
*/
|
||||
#define NUMBER_MAX_DECIMAL_EXPONENT 308
|
||||
/**
|
||||
* Number.MIN_VALUE exponent part when using 64 bit float representation.
|
||||
*/
|
||||
#define NUMBER_MIN_DECIMAL_EXPONENT -324
|
||||
|
||||
#elif !JERRY_NUMBER_TYPE_FLOAT64
|
||||
|
||||
/**
|
||||
* Number.MAX_VALUE exponent part when using 32 bit float representation.
|
||||
*/
|
||||
#define NUMBER_MAX_DECIMAL_EXPONENT 38
|
||||
/**
|
||||
* Number.MIN_VALUE exponent part when using 32 bit float representation.
|
||||
*/
|
||||
#define NUMBER_MIN_DECIMAL_EXPONENT -45
|
||||
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Value of epsilon
|
||||
*/
|
||||
#define EPSILON 0.0000001
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion from string to number for different radixes (2, 8, 16).
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5 9.3.1
|
||||
* ECMA-262 v6 7.1.3.1
|
||||
*
|
||||
* @return NaN - if the conversion fails
|
||||
* converted number - otherwise
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_utf8_string_to_number_by_radix (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
const lit_utf8_size_t string_size, /**< end of utf-8 string */
|
||||
uint32_t radix, /**< radix */
|
||||
uint32_t options) /**< option flags */
|
||||
{
|
||||
JERRY_ASSERT (radix == 2 || radix == 8 || radix == 16);
|
||||
JERRY_ASSERT (*str_p == LIT_CHAR_0);
|
||||
|
||||
const lit_utf8_byte_t *end_p = str_p + string_size;
|
||||
|
||||
/* Skip leading zero */
|
||||
str_p++;
|
||||
|
||||
if (radix != 8 || LEXER_TO_ASCII_LOWERCASE (*str_p) == LIT_CHAR_LOWERCASE_O)
|
||||
{
|
||||
/* Skip radix specifier */
|
||||
str_p++;
|
||||
}
|
||||
|
||||
ecma_number_t num = ECMA_NUMBER_ZERO;
|
||||
|
||||
while (str_p < end_p)
|
||||
{
|
||||
lit_utf8_byte_t digit = *str_p++;
|
||||
|
||||
if (digit == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!lit_char_is_hex_digit (digit))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
uint32_t value = lit_char_hex_to_int (digit);
|
||||
|
||||
if (value >= radix)
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
num = num * radix + value;
|
||||
}
|
||||
|
||||
return num;
|
||||
} /* ecma_utf8_string_to_number_by_radix */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of string to Number.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.3.1
|
||||
*
|
||||
* @return NaN - if the conversion fails
|
||||
* converted number - otherwise
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
lit_utf8_size_t str_size, /**< string size */
|
||||
uint32_t options) /**< allowing underscore option bit */
|
||||
{
|
||||
ecma_string_trim_helper (&str_p, &str_size);
|
||||
const lit_utf8_byte_t *end_p = str_p + str_size;
|
||||
|
||||
if (str_size == 0)
|
||||
{
|
||||
return ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
bool sign = false;
|
||||
|
||||
if (str_p + 2 < end_p && str_p[0] == LIT_CHAR_0)
|
||||
{
|
||||
uint8_t radix = lit_char_to_radix (str_p[1]);
|
||||
|
||||
if (radix != 10)
|
||||
{
|
||||
return ecma_utf8_string_to_number_by_radix (str_p, str_size, radix, options);
|
||||
}
|
||||
}
|
||||
|
||||
if (*str_p == LIT_CHAR_PLUS)
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
else if (*str_p == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = true;
|
||||
str_p++;
|
||||
}
|
||||
|
||||
/* Check if string is equal to "Infinity". */
|
||||
const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
const lit_utf8_size_t infinity_length = lit_get_magic_string_size (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
|
||||
if ((lit_utf8_size_t) (end_p - str_p) == infinity_length && memcmp (infinity_str_p, str_p, infinity_length) == 0)
|
||||
{
|
||||
return ecma_number_make_infinity (sign);
|
||||
}
|
||||
|
||||
uint64_t significand = 0;
|
||||
uint32_t digit_count = 0;
|
||||
int32_t decimal_exponent = 0;
|
||||
bool has_significand = false;
|
||||
|
||||
/* Parsing integer part */
|
||||
while (str_p < end_p)
|
||||
{
|
||||
if (*str_p == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE))
|
||||
{
|
||||
str_p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
has_significand = true;
|
||||
uint32_t digit_value = (uint32_t) (*str_p++ - LIT_CHAR_0);
|
||||
|
||||
if (digit_count == 0 && digit_value == 0)
|
||||
{
|
||||
/* Leading zeros are omitted. */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (digit_count >= ECMA_NUMBER_MAX_DIGITS)
|
||||
{
|
||||
decimal_exponent++;
|
||||
continue;
|
||||
}
|
||||
|
||||
significand = significand * 10 + digit_value;
|
||||
digit_count++;
|
||||
}
|
||||
|
||||
/* Parse fraction part */
|
||||
if (str_p < end_p && *str_p == LIT_CHAR_DOT)
|
||||
{
|
||||
str_p++;
|
||||
|
||||
while (str_p < end_p)
|
||||
{
|
||||
if (*str_p == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE))
|
||||
{
|
||||
str_p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
has_significand = true;
|
||||
uint32_t digit_value = (uint32_t) (*str_p++ - LIT_CHAR_0);
|
||||
|
||||
if (digit_count == 0 && digit_value == 0)
|
||||
{
|
||||
/* Leading zeros are omitted. */
|
||||
decimal_exponent--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (digit_count < ECMA_NUMBER_MAX_DIGITS)
|
||||
{
|
||||
significand = significand * 10 + digit_value;
|
||||
digit_count++;
|
||||
decimal_exponent--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Parsing exponent */
|
||||
if (str_p < end_p && LEXER_TO_ASCII_LOWERCASE (*str_p) == LIT_CHAR_LOWERCASE_E)
|
||||
{
|
||||
str_p++;
|
||||
|
||||
int32_t exponent = 0;
|
||||
int32_t exponent_sign = 1;
|
||||
|
||||
if (str_p >= end_p)
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
if (*str_p == LIT_CHAR_PLUS)
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
else if (*str_p == LIT_CHAR_MINUS)
|
||||
{
|
||||
exponent_sign = -1;
|
||||
str_p++;
|
||||
}
|
||||
|
||||
if (str_p >= end_p || !lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
while (str_p < end_p)
|
||||
{
|
||||
if (*str_p == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE))
|
||||
{
|
||||
str_p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t digit_value = (*str_p++ - LIT_CHAR_0);
|
||||
exponent = exponent * 10 + digit_value;
|
||||
|
||||
if (exponent_sign * exponent > NUMBER_MAX_DECIMAL_EXPONENT)
|
||||
{
|
||||
return ecma_number_make_infinity (sign);
|
||||
}
|
||||
|
||||
if (exponent_sign * exponent < NUMBER_MIN_DECIMAL_EXPONENT)
|
||||
{
|
||||
return sign ? -ECMA_NUMBER_ZERO : ECMA_NUMBER_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
decimal_exponent += exponent_sign * exponent;
|
||||
}
|
||||
|
||||
if (!has_significand || str_p < end_p)
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
if (significand == 0)
|
||||
{
|
||||
return sign ? -ECMA_NUMBER_ZERO : ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
/*
|
||||
* 128-bit mantissa storage
|
||||
*
|
||||
* Normalized: |4 bits zero|124-bit mantissa with highest bit set to 1|
|
||||
*/
|
||||
ecma_uint128_t significand_uint128 = { significand, 0 };
|
||||
|
||||
/* Normalizing mantissa */
|
||||
int shift = 4 - ecma_uint64_clz (significand_uint128.hi);
|
||||
|
||||
if (shift < 0)
|
||||
{
|
||||
ecma_uint128_shift_left (&significand_uint128, -shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_uint128_shift_right (&significand_uint128, shift);
|
||||
}
|
||||
|
||||
int32_t binary_exponent = ECMA_NUMBER_FRACTION_WIDTH + shift;
|
||||
|
||||
while (decimal_exponent > 0)
|
||||
{
|
||||
JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) == 4);
|
||||
|
||||
ecma_uint128_mul10 (&significand_uint128);
|
||||
decimal_exponent--;
|
||||
|
||||
/* Re-normalizing mantissa */
|
||||
shift = ecma_uint64_normalize_shift (significand_uint128.hi);
|
||||
JERRY_ASSERT (shift >= 0 && shift <= 4);
|
||||
|
||||
ecma_uint128_shift_right (&significand_uint128, shift);
|
||||
binary_exponent += shift;
|
||||
}
|
||||
|
||||
while (decimal_exponent < 0)
|
||||
{
|
||||
/* Denormalizing mantissa, moving highest 1 to bit 127 */
|
||||
JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) <= 4);
|
||||
shift = ecma_uint64_clz_top4 (significand_uint128.hi);
|
||||
JERRY_ASSERT (shift >= 0 && shift <= 4);
|
||||
|
||||
ecma_uint128_shift_left (&significand_uint128, shift);
|
||||
binary_exponent -= shift;
|
||||
|
||||
ecma_uint128_div10 (&significand_uint128);
|
||||
decimal_exponent++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Preparing mantissa for conversion to 52-bit representation, converting it to:
|
||||
*
|
||||
* |11 zero bits|1|116 mantissa bits|
|
||||
*/
|
||||
JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) <= 4);
|
||||
shift = 11 - ecma_uint64_clz_top4 (significand_uint128.hi);
|
||||
ecma_uint128_shift_right (&significand_uint128, shift);
|
||||
binary_exponent += shift;
|
||||
|
||||
JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) == 11);
|
||||
|
||||
binary_exponent += ECMA_NUMBER_EXPONENT_BIAS;
|
||||
|
||||
/* Handle denormal numbers */
|
||||
if (binary_exponent < 1)
|
||||
{
|
||||
ecma_uint128_shift_right (&significand_uint128, -binary_exponent + 1);
|
||||
binary_exponent = 0;
|
||||
}
|
||||
|
||||
significand = ecma_round_high_to_uint64 (&significand_uint128);
|
||||
|
||||
if (significand >= 1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1))
|
||||
{
|
||||
/* Rounding carried over to the most significant bit, re-normalize.
|
||||
* No need to shift mantissa right, as the low 52 bits will be 0 regardless. */
|
||||
binary_exponent++;
|
||||
}
|
||||
|
||||
if (binary_exponent >= ((1 << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1))
|
||||
{
|
||||
return ecma_number_make_infinity (sign);
|
||||
}
|
||||
|
||||
/* Mask low 52 bits. */
|
||||
significand &= ((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1);
|
||||
|
||||
JERRY_ASSERT (binary_exponent < (1 << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1);
|
||||
JERRY_ASSERT (significand < (1ull << ECMA_NUMBER_FRACTION_WIDTH));
|
||||
|
||||
return ecma_number_create (sign, (uint32_t) binary_exponent, significand);
|
||||
#elif !JERRY_NUMBER_TYPE_FLOAT64
|
||||
/* Less precise conversion */
|
||||
ecma_number_t num = (ecma_number_t) (uint32_t) fraction_uint64;
|
||||
|
||||
ecma_number_t m = e_sign ? (ecma_number_t) 0.1 : (ecma_number_t) 10.0;
|
||||
|
||||
while (e)
|
||||
{
|
||||
if (e % 2)
|
||||
{
|
||||
num *= m;
|
||||
}
|
||||
|
||||
m *= m;
|
||||
e /= 2;
|
||||
}
|
||||
|
||||
return num;
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
} /* ecma_utf8_string_to_number */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of UInt32 to String (zero-terminated).
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.8.1
|
||||
*
|
||||
* @return number of bytes copied to buffer
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_uint32_to_utf8_string (uint32_t value, /**< value to convert */
|
||||
lit_utf8_byte_t *out_buffer_p, /**< buffer for string */
|
||||
lit_utf8_size_t buffer_size) /**< size of buffer */
|
||||
{
|
||||
lit_utf8_byte_t *buf_p = out_buffer_p + buffer_size;
|
||||
|
||||
do
|
||||
{
|
||||
JERRY_ASSERT (buf_p >= out_buffer_p);
|
||||
|
||||
buf_p--;
|
||||
*buf_p = (lit_utf8_byte_t) ((value % 10) + LIT_CHAR_0);
|
||||
value /= 10;
|
||||
} while (value != 0);
|
||||
|
||||
JERRY_ASSERT (buf_p >= out_buffer_p);
|
||||
|
||||
lit_utf8_size_t bytes_copied = (lit_utf8_size_t) (out_buffer_p + buffer_size - buf_p);
|
||||
|
||||
if (JERRY_LIKELY (buf_p != out_buffer_p))
|
||||
{
|
||||
memmove (out_buffer_p, buf_p, bytes_copied);
|
||||
}
|
||||
|
||||
return bytes_copied;
|
||||
} /* ecma_uint32_to_utf8_string */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of Number value to UInt32 value
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.6
|
||||
*
|
||||
* @return 32-bit unsigned integer - result of conversion.
|
||||
*/
|
||||
uint32_t
|
||||
ecma_number_to_uint32 (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
if (JERRY_UNLIKELY (ecma_number_is_zero (num) || !ecma_number_is_finite (num)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bool sign = ecma_number_is_negative (num);
|
||||
const ecma_number_t abs_num = sign ? -num : num;
|
||||
|
||||
/* 2 ^ 32 */
|
||||
const uint64_t uint64_2_pow_32 = (1ull << 32);
|
||||
|
||||
const ecma_number_t num_2_pow_32 = uint64_2_pow_32;
|
||||
|
||||
ecma_number_t num_in_uint32_range;
|
||||
|
||||
if (abs_num >= num_2_pow_32)
|
||||
{
|
||||
num_in_uint32_range = ecma_number_remainder (abs_num, num_2_pow_32);
|
||||
}
|
||||
else
|
||||
{
|
||||
num_in_uint32_range = abs_num;
|
||||
}
|
||||
|
||||
/* Check that the floating point value can be represented with uint32_t. */
|
||||
JERRY_ASSERT (num_in_uint32_range < uint64_2_pow_32);
|
||||
uint32_t uint32_num = (uint32_t) num_in_uint32_range;
|
||||
|
||||
const uint32_t ret = sign ? (uint32_t)(-(int32_t)uint32_num) : uint32_num;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
if (sign && uint32_num != 0)
|
||||
{
|
||||
JERRY_ASSERT (ret == uint64_2_pow_32 - uint32_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ret == uint32_num);
|
||||
}
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return ret;
|
||||
} /* ecma_number_to_uint32 */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of Number value to Int32 value
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.5
|
||||
*
|
||||
* @return 32-bit signed integer - result of conversion.
|
||||
*/
|
||||
int32_t
|
||||
ecma_number_to_int32 (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
uint32_t uint32_num = ecma_number_to_uint32 (num);
|
||||
|
||||
/* 2 ^ 32 */
|
||||
const int64_t int64_2_pow_32 = (1ll << 32);
|
||||
|
||||
/* 2 ^ 31 */
|
||||
const uint32_t uint32_2_pow_31 = (1ull << 31);
|
||||
|
||||
int32_t ret;
|
||||
|
||||
if (uint32_num >= uint32_2_pow_31)
|
||||
{
|
||||
ret = (int32_t) (uint32_num - int64_2_pow_32);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (int32_t) uint32_num;
|
||||
}
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
int64_t int64_num = uint32_num;
|
||||
|
||||
JERRY_ASSERT (int64_num >= 0);
|
||||
|
||||
if (int64_num >= uint32_2_pow_31)
|
||||
{
|
||||
JERRY_ASSERT (ret == int64_num - int64_2_pow_32);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ret == int64_num);
|
||||
}
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return ret;
|
||||
} /* ecma_number_to_int32 */
|
||||
|
||||
/**
|
||||
* Perform conversion of ecma-number to decimal representation with decimal exponent.
|
||||
*
|
||||
* Note:
|
||||
* The calculated values correspond to s, n, k parameters in ECMA-262 v5, 9.8.1, item 5:
|
||||
* - parameter out_digits_p corresponds to s, the digits of the number;
|
||||
* - parameter out_decimal_exp_p corresponds to n, the decimal exponent;
|
||||
* - return value corresponds to k, the number of digits.
|
||||
*
|
||||
* @return the number of digits
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_number_to_decimal (ecma_number_t num, /**< ecma-number */
|
||||
lit_utf8_byte_t *out_digits_p, /**< [out] buffer to fill with digits */
|
||||
int32_t *out_decimal_exp_p) /**< [out] decimal exponent */
|
||||
{
|
||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
||||
JERRY_ASSERT (!ecma_number_is_zero (num));
|
||||
JERRY_ASSERT (!ecma_number_is_infinity (num));
|
||||
JERRY_ASSERT (!ecma_number_is_negative (num));
|
||||
|
||||
return ecma_errol0_dtoa ((double) num, out_digits_p, out_decimal_exp_p);
|
||||
} /* ecma_number_to_decimal */
|
||||
|
||||
/**
|
||||
* Convert ecma-number to zero-terminated string
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.8.1
|
||||
*
|
||||
*
|
||||
* @return size of utf-8 string
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_number_to_utf8_string (ecma_number_t num, /**< ecma-number */
|
||||
lit_utf8_byte_t *buffer_p, /**< buffer for utf-8 string */
|
||||
lit_utf8_size_t buffer_size) /**< size of buffer */
|
||||
{
|
||||
lit_utf8_byte_t *dst_p;
|
||||
|
||||
if (ecma_number_is_nan (num))
|
||||
{
|
||||
/* 1. */
|
||||
dst_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_NAN, buffer_p, buffer_size);
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
}
|
||||
|
||||
if (ecma_number_is_zero (num))
|
||||
{
|
||||
/* 2. */
|
||||
*buffer_p = LIT_CHAR_0;
|
||||
JERRY_ASSERT (1 <= buffer_size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dst_p = buffer_p;
|
||||
|
||||
if (ecma_number_is_negative (num))
|
||||
{
|
||||
/* 3. */
|
||||
*dst_p++ = LIT_CHAR_MINUS;
|
||||
num = -num;
|
||||
}
|
||||
|
||||
if (ecma_number_is_infinity (num))
|
||||
{
|
||||
/* 4. */
|
||||
dst_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_INFINITY_UL,
|
||||
dst_p,
|
||||
(lit_utf8_size_t) (buffer_p + buffer_size - dst_p));
|
||||
JERRY_ASSERT (dst_p <= buffer_p + buffer_size);
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
uint32_t num_uint32 = ecma_number_to_uint32 (num);
|
||||
|
||||
if (((ecma_number_t) num_uint32) == num)
|
||||
{
|
||||
dst_p += ecma_uint32_to_utf8_string (num_uint32, dst_p, (lit_utf8_size_t) (buffer_p + buffer_size - dst_p));
|
||||
JERRY_ASSERT (dst_p <= buffer_p + buffer_size);
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
}
|
||||
|
||||
/* decimal exponent */
|
||||
int32_t n;
|
||||
/* number of digits in mantissa */
|
||||
int32_t k;
|
||||
|
||||
k = (int32_t) ecma_number_to_decimal (num, dst_p, &n);
|
||||
|
||||
if (k <= n && n <= 21)
|
||||
{
|
||||
/* 6. */
|
||||
dst_p += k;
|
||||
|
||||
memset (dst_p, LIT_CHAR_0, (size_t) (n - k));
|
||||
dst_p += n - k;
|
||||
|
||||
JERRY_ASSERT (dst_p <= buffer_p + buffer_size);
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
}
|
||||
|
||||
if (0 < n && n <= 21)
|
||||
{
|
||||
/* 7. */
|
||||
memmove (dst_p + n + 1, dst_p + n, (size_t) (k - n));
|
||||
*(dst_p + n) = LIT_CHAR_DOT;
|
||||
dst_p += k + 1;
|
||||
|
||||
JERRY_ASSERT (dst_p <= buffer_p + buffer_size);
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
}
|
||||
|
||||
if (-6 < n && n <= 0)
|
||||
{
|
||||
/* 8. */
|
||||
memmove (dst_p + 2 - n, dst_p, (size_t) k);
|
||||
memset (dst_p + 2, LIT_CHAR_0, (size_t) -n);
|
||||
*dst_p = LIT_CHAR_0;
|
||||
*(dst_p + 1) = LIT_CHAR_DOT;
|
||||
dst_p += k - n + 2;
|
||||
|
||||
JERRY_ASSERT (dst_p <= buffer_p + buffer_size);
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
}
|
||||
|
||||
if (k == 1)
|
||||
{
|
||||
/* 9. */
|
||||
dst_p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 10. */
|
||||
memmove (dst_p + 2, dst_p + 1, (size_t) (k - 1));
|
||||
*(dst_p + 1) = LIT_CHAR_DOT;
|
||||
dst_p += k + 1;
|
||||
}
|
||||
|
||||
/* 9., 10. */
|
||||
*dst_p++ = LIT_CHAR_LOWERCASE_E;
|
||||
*dst_p++ = (n >= 1) ? LIT_CHAR_PLUS : LIT_CHAR_MINUS;
|
||||
uint32_t t = (uint32_t) (n >= 1 ? (n - 1) : -(n - 1));
|
||||
|
||||
dst_p += ecma_uint32_to_utf8_string (t, dst_p, (lit_utf8_size_t) (buffer_p + buffer_size - dst_p));
|
||||
|
||||
JERRY_ASSERT (dst_p <= buffer_p + buffer_size);
|
||||
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
} /* ecma_number_to_utf8_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,245 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is based on work under the following copyright and permission
|
||||
* notice:
|
||||
*
|
||||
* Copyright (c) 2016 Marc Andrysco
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Printing Floating-Point Numbers
|
||||
*
|
||||
* available at http://cseweb.ucsd.edu/~mandrysc/pub/dtoa.pdf
|
||||
*/
|
||||
|
||||
/**
|
||||
* Floating point format definitions (next float value)
|
||||
*/
|
||||
#define ECMA_NEXT_FLOAT(value) (nextafter ((value), INFINITY))
|
||||
/**
|
||||
* Floating point format definitions (previous float value)
|
||||
*/
|
||||
#define ECMA_PREV_FLOAT(value) (nextafter ((value), -INFINITY))
|
||||
|
||||
/**
|
||||
* Value of epsilon
|
||||
*/
|
||||
#define ERROL0_EPSILON 0.0000001
|
||||
|
||||
/**
|
||||
* High-precision data structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
double value; /**< value */
|
||||
double offset; /**< offset */
|
||||
} ecma_high_prec_t;
|
||||
|
||||
/**
|
||||
* Normalize the number by factoring in the error.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static inline void
|
||||
ecma_normalize_high_prec_data (ecma_high_prec_t *hp_data_p) /**< [in, out] float pair */
|
||||
{
|
||||
double val = hp_data_p->value;
|
||||
|
||||
hp_data_p->value += hp_data_p->offset;
|
||||
hp_data_p->offset += val - hp_data_p->value;
|
||||
} /* ecma_normalize_high_prec_data */
|
||||
|
||||
/**
|
||||
* Multiply the high-precision number by ten.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static inline void
|
||||
ecma_multiply_high_prec_by_10 (ecma_high_prec_t *hp_data_p) /**< [in, out] high-precision number */
|
||||
{
|
||||
double value = hp_data_p->value;
|
||||
|
||||
hp_data_p->value *= 10.0;
|
||||
hp_data_p->offset *= 10.0;
|
||||
|
||||
double offset = hp_data_p->value;
|
||||
|
||||
offset -= value * 8.0;
|
||||
offset -= value * 2.0;
|
||||
|
||||
hp_data_p->offset -= offset;
|
||||
|
||||
ecma_normalize_high_prec_data (hp_data_p);
|
||||
} /* ecma_multiply_high_prec_by_10 */
|
||||
|
||||
/**
|
||||
* Divide the high-precision number by ten.
|
||||
*/
|
||||
static void
|
||||
ecma_divide_high_prec_by_10 (ecma_high_prec_t *hp_data_p) /**< [in, out] high-precision number */
|
||||
{
|
||||
double value = hp_data_p->value;
|
||||
|
||||
hp_data_p->value /= 10.0;
|
||||
hp_data_p->offset /= 10.0;
|
||||
|
||||
value -= hp_data_p->value * 8.0;
|
||||
value -= hp_data_p->value * 2.0;
|
||||
|
||||
hp_data_p->offset += value / 10.0;
|
||||
|
||||
ecma_normalize_high_prec_data (hp_data_p);
|
||||
} /* ecma_divide_high_prec_by_10 */
|
||||
|
||||
/**
|
||||
* Errol0 double to ASCII conversion, guaranteed correct but possibly not optimal.
|
||||
*
|
||||
* @return number of generated digits
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_errol0_dtoa (double val, /**< ecma number */
|
||||
lit_utf8_byte_t *buffer_p, /**< buffer to generate digits into */
|
||||
int32_t *exp_p) /**< [out] exponent */
|
||||
{
|
||||
double power_of_10 = 1.0;
|
||||
int32_t exponent = 1;
|
||||
|
||||
/* normalize the midpoint */
|
||||
ecma_high_prec_t mid;
|
||||
|
||||
mid.value = val;
|
||||
mid.offset = 0.0;
|
||||
|
||||
while (((mid.value > 10.0) || ((mid.value == 10.0) && (mid.offset >= 0.0))) && (exponent < 308))
|
||||
{
|
||||
exponent++;
|
||||
ecma_divide_high_prec_by_10 (&mid);
|
||||
power_of_10 /= 10.0;
|
||||
}
|
||||
|
||||
while (((mid.value < 1.0) || ((mid.value == 1.0) && (mid.offset < 0.0))) && (exponent > -307))
|
||||
{
|
||||
exponent--;
|
||||
ecma_multiply_high_prec_by_10 (&mid);
|
||||
power_of_10 *= 10.0;
|
||||
}
|
||||
|
||||
ecma_high_prec_t high_bound, low_bound;
|
||||
|
||||
high_bound.value = mid.value;
|
||||
high_bound.offset = mid.offset;
|
||||
|
||||
if ((float) ECMA_NEXT_FLOAT (val) != (float) INFINITY)
|
||||
{
|
||||
high_bound.offset += (ECMA_NEXT_FLOAT (val) - val) * power_of_10 / (2.0 + ERROL0_EPSILON);
|
||||
}
|
||||
|
||||
low_bound.value = mid.value;
|
||||
low_bound.offset = mid.offset + (ECMA_PREV_FLOAT (val) - val) * power_of_10 / (2.0 + ERROL0_EPSILON);
|
||||
|
||||
ecma_normalize_high_prec_data (&high_bound);
|
||||
ecma_normalize_high_prec_data (&low_bound);
|
||||
|
||||
/* normalized boundaries */
|
||||
|
||||
while (high_bound.value > 10.0 || (high_bound.value == 10.0 && (high_bound.offset >= 0.0)))
|
||||
{
|
||||
exponent++;
|
||||
ecma_divide_high_prec_by_10 (&high_bound);
|
||||
ecma_divide_high_prec_by_10 (&low_bound);
|
||||
}
|
||||
|
||||
while (high_bound.value < 1.0 || (high_bound.value == 1.0 && (high_bound.offset < 0.0)))
|
||||
{
|
||||
exponent--;
|
||||
ecma_multiply_high_prec_by_10 (&high_bound);
|
||||
ecma_multiply_high_prec_by_10 (&low_bound);
|
||||
}
|
||||
|
||||
/* digit generation */
|
||||
|
||||
lit_utf8_byte_t *dst_p = buffer_p;
|
||||
|
||||
while (high_bound.value != 0.0 || high_bound.offset != 0.0)
|
||||
{
|
||||
uint8_t high_digit = (uint8_t) high_bound.value;
|
||||
|
||||
if ((high_bound.value == high_digit) && (high_bound.offset < 0))
|
||||
{
|
||||
high_digit = (uint8_t) (high_digit - 1u);
|
||||
}
|
||||
|
||||
uint8_t low_digit = (uint8_t) low_bound.value;
|
||||
|
||||
if ((low_bound.value == low_digit) && (low_bound.offset < 0))
|
||||
{
|
||||
low_digit = (uint8_t) (low_digit - 1u);
|
||||
}
|
||||
|
||||
if (low_digit != high_digit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
*dst_p++ = (lit_utf8_byte_t) ('0' + high_digit);
|
||||
|
||||
high_bound.value -= high_digit;
|
||||
ecma_multiply_high_prec_by_10 (&high_bound);
|
||||
|
||||
low_bound.value -= low_digit;
|
||||
ecma_multiply_high_prec_by_10 (&low_bound);
|
||||
}
|
||||
|
||||
double mdig = (high_bound.value + low_bound.value) / 2.0 + 0.5;
|
||||
*dst_p++ = (lit_utf8_byte_t) ('0' + (uint8_t) mdig);
|
||||
|
||||
*exp_p = exponent;
|
||||
|
||||
return (lit_utf8_size_t) (dst_p - buffer_p);
|
||||
} /* ecma_errol0_dtoa */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,334 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-objects.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a native pointer property to store the native pointer and its type info.
|
||||
*
|
||||
* @return true - if property was just created with specified value,
|
||||
* false - otherwise, if property existed before the call, it's value was updated
|
||||
*/
|
||||
bool
|
||||
ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create property in */
|
||||
void *native_p, /**< native pointer */
|
||||
const jerry_object_native_info_t *native_info_p) /**< native type info */
|
||||
{
|
||||
ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
|
||||
if (native_info_p != NULL && native_info_p->number_of_references > 0)
|
||||
{
|
||||
name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES);
|
||||
}
|
||||
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
{
|
||||
ecma_fast_array_convert_to_normal (obj_p);
|
||||
}
|
||||
|
||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
||||
|
||||
bool is_new = (property_p == NULL);
|
||||
|
||||
ecma_native_pointer_t *native_pointer_p;
|
||||
|
||||
if (property_p == NULL)
|
||||
{
|
||||
native_pointer_p = (ecma_native_pointer_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
|
||||
|
||||
ecma_property_value_t *value_p;
|
||||
ECMA_CREATE_INTERNAL_PROPERTY (obj_p, name_p, property_p, value_p);
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p);
|
||||
*property_p |= ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL;
|
||||
}
|
||||
else if (*property_p & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL)
|
||||
{
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
|
||||
|
||||
if (native_pointer_p->native_info_p == native_info_p)
|
||||
{
|
||||
native_pointer_p->native_p = native_p;
|
||||
return false;
|
||||
}
|
||||
|
||||
value_p->value = JMEM_CP_NULL;
|
||||
(void) value_p->value; /* Make cppcheck happy. */
|
||||
*property_p &= (ecma_property_t) ~ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL;
|
||||
|
||||
ecma_native_pointer_chain_t *item_p;
|
||||
item_p = (ecma_native_pointer_chain_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_chain_t));
|
||||
item_p->data = *native_pointer_p;
|
||||
|
||||
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
|
||||
|
||||
item_p->next_p = (ecma_native_pointer_chain_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_chain_t));
|
||||
item_p->next_p->next_p = NULL;
|
||||
|
||||
native_pointer_p = &item_p->next_p->data;
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, item_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
if (value_p->value == JMEM_CP_NULL)
|
||||
{
|
||||
native_pointer_p = (ecma_native_pointer_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p);
|
||||
|
||||
*property_p |= ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_native_pointer_chain_t *item_p;
|
||||
item_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value_p->value);
|
||||
|
||||
/* There should be at least 2 native pointers in the chain */
|
||||
JERRY_ASSERT (item_p != NULL && item_p->next_p != NULL);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (item_p->data.native_info_p == native_info_p)
|
||||
{
|
||||
/* The native info already exists -> update the corresponding data */
|
||||
item_p->data.native_p = native_p;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item_p->next_p == NULL)
|
||||
{
|
||||
/* The native info does not exist -> append a new element to the chain */
|
||||
break;
|
||||
}
|
||||
|
||||
item_p = item_p->next_p;
|
||||
}
|
||||
|
||||
ecma_native_pointer_chain_t *new_item_p;
|
||||
|
||||
new_item_p = (ecma_native_pointer_chain_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_chain_t));
|
||||
item_p->next_p = new_item_p;
|
||||
new_item_p->next_p = NULL;
|
||||
|
||||
native_pointer_p = &new_item_p->data;
|
||||
}
|
||||
}
|
||||
|
||||
native_pointer_p->native_p = native_p;
|
||||
native_pointer_p->native_info_p = (jerry_object_native_info_t *) native_info_p;
|
||||
|
||||
return is_new;
|
||||
} /* ecma_create_native_pointer_property */
|
||||
|
||||
/**
|
||||
* Get value of native package stored in the object's property with specified identifier
|
||||
*
|
||||
* Note:
|
||||
* property identifier should be one of the following:
|
||||
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER
|
||||
*
|
||||
* @return native pointer data if property exists
|
||||
* NULL otherwise
|
||||
*/
|
||||
ecma_native_pointer_t *
|
||||
ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
|
||||
const jerry_object_native_info_t *native_info_p) /**< native type info */
|
||||
{
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
{
|
||||
/* Fast access mode array cannot have native pointer properties */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
|
||||
if (native_info_p != NULL && native_info_p->number_of_references > 0)
|
||||
{
|
||||
name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES);
|
||||
}
|
||||
|
||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
||||
|
||||
if (property_p == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
if (JERRY_LIKELY (*property_p & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL))
|
||||
{
|
||||
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
|
||||
|
||||
if (native_pointer_p->native_info_p == native_info_p)
|
||||
{
|
||||
return native_pointer_p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (value_p->value == JMEM_CP_NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_native_pointer_chain_t *item_p;
|
||||
item_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value_p->value);
|
||||
|
||||
/* There should be at least 2 native pointers in the chain */
|
||||
JERRY_ASSERT (item_p != NULL && item_p->next_p != NULL);
|
||||
|
||||
do
|
||||
{
|
||||
if (item_p->data.native_info_p == native_info_p)
|
||||
{
|
||||
return &item_p->data;
|
||||
}
|
||||
|
||||
item_p = item_p->next_p;
|
||||
} while (item_p != NULL);
|
||||
|
||||
return NULL;
|
||||
} /* ecma_get_native_pointer_value */
|
||||
|
||||
/**
|
||||
* Delete the previously set native pointer by the native type info from the specified object.
|
||||
*
|
||||
* Note:
|
||||
* If the specified object has no matching native pointer for the given native type info
|
||||
* the function has no effect.
|
||||
*
|
||||
* @return true - if the native pointer has been deleted successfully
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_delete_native_pointer_property (ecma_object_t *obj_p, /**< object to delete property from */
|
||||
const jerry_object_native_info_t *native_info_p) /**< native type info */
|
||||
{
|
||||
if (ecma_op_object_is_fast_array (obj_p))
|
||||
{
|
||||
/* Fast access mode array cannot have native pointer properties */
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
|
||||
if (native_info_p != NULL && native_info_p->number_of_references > 0)
|
||||
{
|
||||
name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES);
|
||||
}
|
||||
|
||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
|
||||
|
||||
if (property_p == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
if (JERRY_LIKELY (*property_p & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL))
|
||||
{
|
||||
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
|
||||
|
||||
if (native_pointer_p->native_info_p != native_info_p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value_p->value = JMEM_CP_NULL;
|
||||
*property_p &= (ecma_property_t) ~ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL;
|
||||
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value_p->value == JMEM_CP_NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_native_pointer_chain_t *first_p;
|
||||
first_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value_p->value);
|
||||
|
||||
/* There should be at least 2 native pointers in the chain */
|
||||
JERRY_ASSERT (first_p != NULL && first_p->next_p != NULL);
|
||||
|
||||
ecma_native_pointer_chain_t *item_p = first_p;
|
||||
ecma_native_pointer_chain_t *prev_p = NULL;
|
||||
|
||||
do
|
||||
{
|
||||
if (item_p->data.native_info_p == native_info_p)
|
||||
{
|
||||
if (prev_p == NULL)
|
||||
{
|
||||
/* The first element is deleted from the chain: change the property value. */
|
||||
first_p = item_p->next_p;
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, first_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A non-first element is deleted from the chain: update the previous pointer. */
|
||||
prev_p->next_p = item_p->next_p;
|
||||
}
|
||||
|
||||
jmem_heap_free_block (item_p, sizeof (ecma_native_pointer_chain_t));
|
||||
|
||||
if (first_p->next_p != NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Only one item remained. The ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL flag is
|
||||
* set early to avoid using the chain if the allocation below triggers a GC. */
|
||||
*property_p |= ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL;
|
||||
|
||||
ecma_native_pointer_t *native_pointer_p;
|
||||
native_pointer_p = (ecma_native_pointer_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
|
||||
*native_pointer_p = first_p->data;
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p);
|
||||
|
||||
jmem_heap_free_block (first_p, sizeof (ecma_native_pointer_chain_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
prev_p = item_p;
|
||||
item_p = item_p->next_p;
|
||||
} while (item_p != NULL);
|
||||
|
||||
return false;
|
||||
} /* ecma_delete_native_pointer_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,677 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-helpers-number.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "ecma-conversion.h"
|
||||
|
||||
#include "lit-char-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (ecma_value_t) == sizeof (ecma_integer_value_t)),
|
||||
size_of_ecma_value_t_must_be_equal_to_the_size_of_ecma_integer_value_t);
|
||||
|
||||
JERRY_STATIC_ASSERT ((((int)ECMA_DIRECT_SHIFT) == (((int)ECMA_VALUE_SHIFT) + 1)), currently_directly_encoded_values_has_one_extra_flag);
|
||||
|
||||
JERRY_STATIC_ASSERT ((((1 << (ECMA_DIRECT_SHIFT - 1)) | ECMA_TYPE_DIRECT) == ECMA_DIRECT_TYPE_SIMPLE_VALUE),
|
||||
currently_directly_encoded_values_start_after_direct_type_simple_value);
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (ecma_number_t) == sizeof (ecma_binary_num_t)),
|
||||
size_of_ecma_number_t_must_be_equal_to_binary_representation);
|
||||
|
||||
/**
|
||||
* Convert an ecma-number to it's binary representation.
|
||||
*
|
||||
* @return binary representation
|
||||
*/
|
||||
ecma_binary_num_t JERRY_ATTR_CONST
|
||||
ecma_number_to_binary (ecma_number_t number) /**< ecma number */
|
||||
{
|
||||
ecma_number_accessor_t f;
|
||||
f.as_number = number;
|
||||
|
||||
return f.as_binary;
|
||||
} /* ecma_number_to_binary */
|
||||
|
||||
/**
|
||||
* Convert a binary representation to the corresponding ecma-number.
|
||||
*
|
||||
* @return ecma-number
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_from_binary (ecma_binary_num_t binary) /**< binary representation */
|
||||
{
|
||||
ecma_number_accessor_t f;
|
||||
f.as_binary = binary;
|
||||
|
||||
return f.as_number;
|
||||
} /* ecma_number_from_binary */
|
||||
|
||||
/**
|
||||
* Check signedness of the binary number.
|
||||
*
|
||||
* @return true - if sign bit is set
|
||||
* false - otherwise
|
||||
*/
|
||||
bool JERRY_ATTR_CONST
|
||||
ecma_number_sign (ecma_binary_num_t binary) /**< binary representation */
|
||||
{
|
||||
return (binary & ECMA_NUMBER_SIGN_BIT) != 0;
|
||||
} /* ecma_number_sign */
|
||||
|
||||
/**
|
||||
* Get biased exponent field of the binary number.
|
||||
*
|
||||
* @return unsigned integer value of the biased exponent field
|
||||
*/
|
||||
uint32_t JERRY_ATTR_CONST
|
||||
ecma_number_biased_exp (ecma_binary_num_t binary) /**< binary representation */
|
||||
{
|
||||
return (uint32_t) ((binary & ~ECMA_NUMBER_SIGN_BIT) >> ECMA_NUMBER_FRACTION_WIDTH);
|
||||
} /* ecma_number_biased_exp */
|
||||
|
||||
/**
|
||||
* Get fraction field of the binary number.
|
||||
*
|
||||
* @return unsigned integer value of the fraction field
|
||||
*/
|
||||
uint64_t JERRY_ATTR_CONST
|
||||
ecma_number_fraction (ecma_binary_num_t binary) /**< binary representation */
|
||||
{
|
||||
return binary & ((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1);
|
||||
} /* ecma_number_fraction */
|
||||
|
||||
/**
|
||||
* Packing sign, fraction and biased exponent to ecma-number
|
||||
*
|
||||
* @return ecma-number with specified sign, biased_exponent and fraction
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_number_create (bool sign, /**< sign */
|
||||
uint32_t biased_exp, /**< biased exponent */
|
||||
uint64_t fraction) /**< fraction */
|
||||
{
|
||||
JERRY_ASSERT ((biased_exp & ~((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) == 0);
|
||||
JERRY_ASSERT ((fraction & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0);
|
||||
|
||||
ecma_binary_num_t binary = biased_exp;
|
||||
binary <<= ECMA_NUMBER_FRACTION_WIDTH;
|
||||
|
||||
binary |= fraction;
|
||||
|
||||
if (sign)
|
||||
{
|
||||
binary |= ECMA_NUMBER_SIGN_BIT;
|
||||
}
|
||||
|
||||
return ecma_number_from_binary (binary);
|
||||
} /* ecma_number_create */
|
||||
|
||||
/**
|
||||
* Check if ecma-number is NaN
|
||||
*
|
||||
* @return true - if biased exponent is filled with 1 bits and
|
||||
fraction is filled with anything but not all zero bits,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
bool is_nan = (num != num);
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
/* IEEE-754 2008, 3.4, a */
|
||||
ecma_binary_num_t binary = ecma_number_to_binary (num);
|
||||
bool is_nan_exponent = (ecma_number_biased_exp (binary) == (1 << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1);
|
||||
bool is_nan_fraction = (ecma_number_fraction (binary) > 0);
|
||||
|
||||
bool is_nan_ieee754 = is_nan_exponent && is_nan_fraction;
|
||||
JERRY_ASSERT (is_nan == is_nan_ieee754);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return is_nan;
|
||||
} /* ecma_number_is_nan */
|
||||
|
||||
/**
|
||||
* Make a NaN.
|
||||
*
|
||||
* @return NaN value
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_make_nan (void)
|
||||
{
|
||||
ecma_number_accessor_t f;
|
||||
f.as_binary = ECMA_NUMBER_BINARY_QNAN;
|
||||
|
||||
return f.as_number;
|
||||
} /* ecma_number_make_nan */
|
||||
|
||||
/**
|
||||
* Make an Infinity.
|
||||
*
|
||||
* @return if !sign - +Infinity value,
|
||||
* else - -Infinity value.
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_make_infinity (bool sign) /**< sign of the value */
|
||||
{
|
||||
ecma_number_accessor_t f;
|
||||
f.as_binary = ECMA_NUMBER_BINARY_INF;
|
||||
|
||||
if (sign)
|
||||
{
|
||||
f.as_binary |= ECMA_NUMBER_SIGN_BIT;
|
||||
}
|
||||
|
||||
return f.as_number;
|
||||
} /* ecma_number_make_infinity */
|
||||
|
||||
/**
|
||||
* Check if ecma-number is negative
|
||||
*
|
||||
* @return true - if sign bit of ecma-number is set
|
||||
* false - otherwise
|
||||
*/
|
||||
bool JERRY_ATTR_CONST
|
||||
ecma_number_is_negative (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
||||
|
||||
return (ecma_number_to_binary (num) & ECMA_NUMBER_SIGN_BIT) != 0;
|
||||
} /* ecma_number_is_negative */
|
||||
|
||||
/**
|
||||
* Check if ecma-number is zero
|
||||
*
|
||||
* @return true - if fraction is zero and biased exponent is zero,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool JERRY_ATTR_CONST
|
||||
ecma_number_is_zero (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
bool is_zero = (num == ECMA_NUMBER_ZERO);
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
bool is_zero_ieee754 = ((ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == 0);
|
||||
JERRY_ASSERT (is_zero == is_zero_ieee754);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return is_zero;
|
||||
} /* ecma_number_is_zero */
|
||||
|
||||
/**
|
||||
* Check if number is infinity
|
||||
*
|
||||
* @return true - if biased exponent is filled with 1 bits and
|
||||
* fraction is filled with zero bits,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool JERRY_ATTR_CONST
|
||||
ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
return (ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == ECMA_NUMBER_BINARY_INF;
|
||||
} /* ecma_number_is_infinity */
|
||||
|
||||
/**
|
||||
* Check if number is finite
|
||||
*
|
||||
* @return true - if number is finite
|
||||
* false - if number is NaN or infinity
|
||||
*/
|
||||
bool JERRY_ATTR_CONST
|
||||
ecma_number_is_finite (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_isfinite (num);
|
||||
#elif defined(_WIN32)
|
||||
return isfinite (num);
|
||||
#else /* !(defined(__GNUC__) || defined(__clang__) || defined(_WIN32)) */
|
||||
return !ecma_number_is_nan (num) && !ecma_number_is_infinity (num);
|
||||
#endif /* defined (__GNUC__) || defined (__clang__) */
|
||||
} /* ecma_number_is_finite */
|
||||
|
||||
/**
|
||||
* Get previous representable ecma-number
|
||||
*
|
||||
* @return maximum ecma-number that is less compared to passed argument
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_get_prev (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_nextafter ((double)num, (double)-INFINITY);
|
||||
#else /* !defined (__GNUC__) && !defined (__clang__) */
|
||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
||||
ecma_binary_num_t binary = ecma_number_to_binary (num);
|
||||
|
||||
/* If -Infinity, return self */
|
||||
if (binary == (ECMA_NUMBER_SIGN_BIT | ECMA_NUMBER_BINARY_INF))
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
/* If +0.0, return -0.0 */
|
||||
if (binary == ECMA_NUMBER_BINARY_ZERO)
|
||||
{
|
||||
return -num;
|
||||
}
|
||||
|
||||
if (ecma_number_sign (binary))
|
||||
{
|
||||
return ecma_number_from_binary (binary + 1);
|
||||
}
|
||||
|
||||
return ecma_number_from_binary (binary - 1);
|
||||
#endif /* !defined (__GNUC__) && !defined (__clang__) */
|
||||
} /* ecma_number_get_prev */
|
||||
|
||||
/**
|
||||
* Get next representable ecma-number
|
||||
*
|
||||
* @return minimum ecma-number that is greater compared to passed argument
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_get_next (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_nextafter ((double)num, (double)INFINITY);
|
||||
#else /* !defined (__GNUC__) && !defined (__clang__) */
|
||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
||||
ecma_binary_num_t binary = ecma_number_to_binary (num);
|
||||
|
||||
/* If +Infinity, return self */
|
||||
if (binary == ECMA_NUMBER_BINARY_INF)
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
/* If -0.0, return +0.0 */
|
||||
if (binary == (ECMA_NUMBER_SIGN_BIT | ECMA_NUMBER_BINARY_ZERO))
|
||||
{
|
||||
return -num;
|
||||
}
|
||||
|
||||
if (ecma_number_sign (binary))
|
||||
{
|
||||
return ecma_number_from_binary (binary - 1);
|
||||
}
|
||||
|
||||
return ecma_number_from_binary (binary + 1);
|
||||
#endif /* !defined (__GNUC__) && !defined (__clang__) */
|
||||
} /* ecma_number_get_next */
|
||||
|
||||
/**
|
||||
* Truncate fractional part of the number
|
||||
*
|
||||
* @return integer part of the number
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_trunc (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
||||
|
||||
ecma_binary_num_t binary = ecma_number_to_binary (num);
|
||||
uint32_t exponent = ecma_number_biased_exp (binary);
|
||||
|
||||
if (exponent < ECMA_NUMBER_EXPONENT_BIAS)
|
||||
{
|
||||
return ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
uint32_t unbiased_exp = exponent - ECMA_NUMBER_EXPONENT_BIAS;
|
||||
|
||||
if (unbiased_exp >= ECMA_NUMBER_FRACTION_WIDTH)
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
binary &= ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH - unbiased_exp)) - 1);
|
||||
return ecma_number_from_binary (binary);
|
||||
} /* ecma_number_trunc */
|
||||
|
||||
/**
|
||||
* Calculate remainder of division of two numbers,
|
||||
* as specified in ECMA-262 v5, 11.5.3, item 6.
|
||||
*
|
||||
* Note:
|
||||
* operands shouldn't contain NaN, Infinity, or zero.
|
||||
*
|
||||
* @return number - calculated remainder.
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_remainder (ecma_number_t left_num, /**< left operand */
|
||||
ecma_number_t right_num) /**< right operand */
|
||||
{
|
||||
JERRY_ASSERT (ecma_number_is_finite (left_num) && !ecma_number_is_zero (left_num));
|
||||
JERRY_ASSERT (ecma_number_is_finite (right_num) && !ecma_number_is_zero (right_num));
|
||||
|
||||
const ecma_number_t q = ecma_number_trunc (left_num / right_num);
|
||||
ecma_number_t r = left_num - right_num * q;
|
||||
|
||||
if (ecma_number_is_zero (r) && ecma_number_is_negative (left_num))
|
||||
{
|
||||
r = -r;
|
||||
}
|
||||
|
||||
return r;
|
||||
} /* ecma_number_remainder */
|
||||
|
||||
/**
|
||||
* Compute power operation according to the ES standard.
|
||||
*
|
||||
* @return x ** y
|
||||
*/
|
||||
ecma_number_t JERRY_ATTR_CONST
|
||||
ecma_number_pow (ecma_number_t x, /**< left operand */
|
||||
ecma_number_t y) /**< right operand */
|
||||
{
|
||||
if (ecma_number_is_nan (y) || (ecma_number_is_infinity (y) && (x == ECMA_NUMBER_ONE || x == ECMA_NUMBER_MINUS_ONE)))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
if (ecma_number_is_zero (y))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
return ECMA_NUMBER_ONE;
|
||||
}
|
||||
|
||||
return DOUBLE_TO_ECMA_NUMBER_T (pow (x, y));
|
||||
} /* ecma_number_pow */
|
||||
|
||||
/**
|
||||
* ECMA-integer number multiplication.
|
||||
*
|
||||
* @return number - result of multiplication.
|
||||
*/
|
||||
ecma_value_t JERRY_ATTR_CONST
|
||||
ecma_integer_multiply (ecma_integer_value_t left_integer, /**< left operand */
|
||||
ecma_integer_value_t right_integer) /**< right operand */
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
/* Check if either integer is power of 2 */
|
||||
if (JERRY_UNLIKELY ((left_integer & (left_integer - 1)) == 0))
|
||||
{
|
||||
/* Right shift right_integer with log2 (left_integer) */
|
||||
return ecma_make_integer_value (
|
||||
(int32_t) ((uint32_t) right_integer << (__builtin_ctz ((unsigned int) left_integer))));
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY ((right_integer & (right_integer - 1)) == 0))
|
||||
{
|
||||
/* Right shift left_integer with log2 (right_integer) */
|
||||
return ecma_make_integer_value (
|
||||
(int32_t) ((uint32_t) left_integer << (__builtin_ctz ((unsigned int) right_integer))));
|
||||
}
|
||||
#endif /* defined (__GNUC__) || defined (__clang__) */
|
||||
|
||||
return ecma_make_integer_value (left_integer * right_integer);
|
||||
} /* ecma_integer_multiply */
|
||||
|
||||
/**
|
||||
* The Number object's 'parseInt' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_number_parse_int (const lit_utf8_byte_t *str_p, /**< routine's first argument's
|
||||
* string buffer */
|
||||
lit_utf8_size_t str_size, /**< routine's first argument's
|
||||
* string buffer's size */
|
||||
ecma_value_t radix_value) /**< routine's second argument */
|
||||
{
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&str_p, &str_size);
|
||||
|
||||
if (str_size == 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *str_end_p = str_p + str_size;
|
||||
|
||||
/* 3. */
|
||||
bool sign = false;
|
||||
|
||||
/* 4. */
|
||||
if (*str_p == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = true;
|
||||
str_p++;
|
||||
}
|
||||
/* 5. */
|
||||
else if (*str_p == LIT_CHAR_PLUS)
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
ecma_number_t radix_num;
|
||||
radix_value = ecma_op_to_number (radix_value, &radix_num);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (radix_value))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
int32_t radix = ecma_number_to_int32 (radix_num);
|
||||
|
||||
/* 7.*/
|
||||
bool strip_prefix = true;
|
||||
|
||||
/* 8. */
|
||||
if (radix != 0)
|
||||
{
|
||||
/* 8.a */
|
||||
if (radix < 2 || radix > 36)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
/* 8.b */
|
||||
else if (radix != 16)
|
||||
{
|
||||
strip_prefix = false;
|
||||
}
|
||||
}
|
||||
/* 9. */
|
||||
else
|
||||
{
|
||||
radix = 10;
|
||||
}
|
||||
|
||||
/* 10. */
|
||||
if (strip_prefix && ((str_end_p - str_p) >= 2) && (str_p[0] == LIT_CHAR_0)
|
||||
&& (LEXER_TO_ASCII_LOWERCASE (str_p[1]) == LIT_CHAR_LOWERCASE_X))
|
||||
{
|
||||
str_p += 2;
|
||||
radix = 16;
|
||||
}
|
||||
|
||||
ecma_number_t value = ECMA_NUMBER_ZERO;
|
||||
const lit_utf8_byte_t *digit_start_p = str_p;
|
||||
|
||||
/* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */
|
||||
while (str_p < str_end_p)
|
||||
{
|
||||
ecma_char_t ch = *str_p;
|
||||
|
||||
int32_t digit = 0;
|
||||
|
||||
if (lit_char_is_decimal_digit (ch))
|
||||
{
|
||||
digit = ch - LIT_CHAR_0;
|
||||
}
|
||||
else if (LEXER_TO_ASCII_LOWERCASE (ch) >= LIT_CHAR_LOWERCASE_A
|
||||
&& LEXER_TO_ASCII_LOWERCASE (ch) <= LIT_CHAR_LOWERCASE_Z)
|
||||
{
|
||||
digit = LEXER_TO_ASCII_LOWERCASE (ch) - LIT_CHAR_LOWERCASE_A + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not a valid digit char, set to invalid value */
|
||||
digit = radix;
|
||||
}
|
||||
|
||||
if (digit >= radix)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
value *= radix;
|
||||
value += digit;
|
||||
|
||||
str_p++;
|
||||
}
|
||||
|
||||
/* 12. */
|
||||
if (str_p == digit_start_p)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* 15. */
|
||||
if (sign)
|
||||
{
|
||||
value *= ECMA_NUMBER_MINUS_ONE;
|
||||
}
|
||||
|
||||
return ecma_make_number_value (value);
|
||||
} /* ecma_number_parse_int */
|
||||
|
||||
/**
|
||||
* The Number object's 'parseFloat' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_number_parse_float (const lit_utf8_byte_t *str_p, /**< routine's first argument's
|
||||
* string buffer */
|
||||
lit_utf8_size_t str_size) /**< routine's first argument's
|
||||
* string buffer's size */
|
||||
{
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&str_p, &str_size);
|
||||
|
||||
const lit_utf8_byte_t *str_end_p = str_p + str_size;
|
||||
bool sign = false;
|
||||
|
||||
if (str_size == 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
if (*str_p == LIT_CHAR_PLUS)
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
else if (*str_p == LIT_CHAR_MINUS)
|
||||
{
|
||||
sign = true;
|
||||
str_p++;
|
||||
}
|
||||
|
||||
/* Check if string is equal to "Infinity". */
|
||||
const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
const lit_utf8_size_t infinity_length = lit_get_magic_string_size (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
|
||||
/* The input string should be at least the length of "Infinity" to be correctly processed as
|
||||
* the infinity value.
|
||||
*/
|
||||
if ((lit_utf8_size_t) (str_end_p - str_p) >= infinity_length && memcmp (infinity_str_p, str_p, infinity_length) == 0)
|
||||
{
|
||||
return ecma_make_number_value (ecma_number_make_infinity (sign));
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *num_start_p = str_p;
|
||||
const lit_utf8_byte_t *num_end_p = str_p;
|
||||
|
||||
while (str_p < str_end_p && lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
|
||||
if (str_p < str_end_p && *str_p == LIT_CHAR_DOT)
|
||||
{
|
||||
str_p++;
|
||||
|
||||
while (str_p < str_end_p && lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
}
|
||||
|
||||
num_end_p = str_p;
|
||||
|
||||
if (str_p < str_end_p && LEXER_TO_ASCII_LOWERCASE (*str_p) == LIT_CHAR_LOWERCASE_E)
|
||||
{
|
||||
str_p++;
|
||||
|
||||
if (str_p < str_end_p && (*str_p == LIT_CHAR_PLUS || *str_p == LIT_CHAR_MINUS))
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
|
||||
if (str_p < str_end_p && lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
str_p++;
|
||||
|
||||
while (str_p < str_end_p && lit_char_is_decimal_digit (*str_p))
|
||||
{
|
||||
str_p++;
|
||||
}
|
||||
|
||||
num_end_p = str_p;
|
||||
}
|
||||
}
|
||||
|
||||
lit_utf8_size_t num_size = (lit_utf8_size_t) (num_end_p - num_start_p);
|
||||
|
||||
if (num_size == 0)
|
||||
{
|
||||
return ecma_make_nan_value ();
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
ecma_number_t ret_num = ecma_utf8_string_to_number (num_start_p, num_size, 0);
|
||||
|
||||
if (sign)
|
||||
{
|
||||
ret_num *= ECMA_NUMBER_MINUS_ONE;
|
||||
}
|
||||
|
||||
return ecma_make_number_value (ret_num);
|
||||
} /* ecma_number_parse_float */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,245 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_HELPERS_NUMBER_H
|
||||
#define ECMA_HELPERS_NUMBER_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#include "jerry-config.h"
|
||||
|
||||
/**
|
||||
* Binary representation of an ecma-number
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
typedef uint64_t ecma_binary_num_t;
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
typedef uint32_t ecma_binary_num_t;
|
||||
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Makes it possible to read/write the binary representation of an ecma_number_t
|
||||
* without strict aliasing rule violation.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
ecma_number_t as_number; /**< ecma-number */
|
||||
ecma_binary_num_t as_binary; /**< binary representation */
|
||||
} ecma_number_accessor_t;
|
||||
|
||||
ecma_binary_num_t ecma_number_to_binary (ecma_number_t number);
|
||||
ecma_number_t ecma_number_from_binary (ecma_binary_num_t binary);
|
||||
|
||||
bool ecma_number_sign (ecma_binary_num_t binary);
|
||||
uint32_t ecma_number_biased_exp (ecma_binary_num_t binary);
|
||||
uint64_t ecma_number_fraction (ecma_binary_num_t binary);
|
||||
ecma_number_t ecma_number_create (bool sign, uint32_t biased_exp, uint64_t fraction);
|
||||
|
||||
/**
|
||||
* Maximum number of significant decimal digits that an ecma-number can store
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_MAX_DIGITS (19)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_MAX_DIGITS (9)
|
||||
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Width of sign field
|
||||
*
|
||||
* See also:
|
||||
* IEEE-754 2008, 3.6, Table 3.5
|
||||
*/
|
||||
#define ECMA_NUMBER_SIGN_WIDTH (1)
|
||||
|
||||
/**
|
||||
* Width of biased exponent field
|
||||
*
|
||||
* See also:
|
||||
* IEEE-754 2008, 3.6, Table 3.5
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_BIASED_EXP_WIDTH (11)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_BIASED_EXP_WIDTH (8)
|
||||
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Exponent bias
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_EXPONENT_BIAS (1023)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_EXPONENT_BIAS (127)
|
||||
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Width of fraction field
|
||||
*
|
||||
* See also:
|
||||
* IEEE-754 2008, 3.6, Table 3.5
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_FRACTION_WIDTH (52)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_FRACTION_WIDTH (23)
|
||||
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Sign bit in ecma-numbers
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_SIGN_BIT 0x8000000000000000ull
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_SIGN_BIT 0x7f800000u
|
||||
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Binary representation of an IEEE-754 QNaN value.
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_BINARY_QNAN 0x7ff8000000000000ull
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_BINARY_QNAN 0x7fc00000u
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Binary representation of an IEEE-754 Infinity value.
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_BINARY_INF 0x7ff0000000000000ull
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_BINARY_INF 0x7f800000u
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Binary representation of an IEEE-754 zero value.
|
||||
*/
|
||||
#define ECMA_NUMBER_BINARY_ZERO 0x0ull
|
||||
|
||||
/**
|
||||
* Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
|
||||
*
|
||||
* See also: ECMA_262 v5, 15.7.3.3
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_MIN_VALUE ((ecma_number_t) 5e-324)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_MIN_VALUE (FLT_MIN)
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Number.MAX_VALUE (i.e., the maximum value of ecma-number)
|
||||
*
|
||||
* See also: ECMA_262 v5, 15.7.3.2
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_MAX_VALUE ((ecma_number_t) 1.7976931348623157e+308)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_MAX_VALUE (FLT_MAX)
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Number.EPSILON
|
||||
*
|
||||
* See also: ECMA_262 v6, 20.1.2.1
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_EPSILON ((ecma_number_t) 2.2204460492503130808472633361816e-16)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_EPSILON ((ecma_number_t) 1.1920928955078125e-7)
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Number.MAX_SAFE_INTEGER
|
||||
*
|
||||
* See also: ECMA_262 v6, 20.1.2.6
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0x1FFFFFFFFFFFFF)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0xFFFFFF)
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Number.MIN_SAFE_INTEGER
|
||||
*
|
||||
* See also: ECMA_262 v6, 20.1.2.8
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0x1FFFFFFFFFFFFF)
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0xFFFFFF)
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Number.MAX_VALUE exponent part
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define NUMBER_MAX_DECIMAL_EXPONENT 308
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define NUMBER_MAX_DECIMAL_EXPONENT 38
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Number.MIN_VALUE exponent part
|
||||
*/
|
||||
#if JERRY_NUMBER_TYPE_FLOAT64
|
||||
#define NUMBER_MIN_DECIMAL_EXPONENT -324
|
||||
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
#define NUMBER_MIN_DECIMAL_EXPONENT -45
|
||||
#endif /* JERRY_NUMBER_TYPE_FLOAT64 */
|
||||
|
||||
/**
|
||||
* Euler number
|
||||
*/
|
||||
#define ECMA_NUMBER_E ((ecma_number_t) 2.7182818284590452354)
|
||||
|
||||
/**
|
||||
* Natural logarithm of 10
|
||||
*/
|
||||
#define ECMA_NUMBER_LN10 ((ecma_number_t) 2.302585092994046)
|
||||
|
||||
/**
|
||||
* Natural logarithm of 2
|
||||
*/
|
||||
#define ECMA_NUMBER_LN2 ((ecma_number_t) 0.6931471805599453)
|
||||
|
||||
/**
|
||||
* Logarithm base 2 of the Euler number
|
||||
*/
|
||||
#define ECMA_NUMBER_LOG2E ((ecma_number_t) 1.4426950408889634)
|
||||
|
||||
/**
|
||||
* Logarithm base 10 of the Euler number
|
||||
*/
|
||||
#define ECMA_NUMBER_LOG10E ((ecma_number_t) 0.4342944819032518)
|
||||
|
||||
/**
|
||||
* Pi number
|
||||
*/
|
||||
#define ECMA_NUMBER_PI ((ecma_number_t) 3.1415926535897932)
|
||||
|
||||
/**
|
||||
* Square root of 0.5
|
||||
*/
|
||||
#define ECMA_NUMBER_SQRT_1_2 ((ecma_number_t) 0.7071067811865476)
|
||||
|
||||
/**
|
||||
* Square root of 2
|
||||
*/
|
||||
#define ECMA_NUMBER_SQRT2 ((ecma_number_t) 1.4142135623730951)
|
||||
|
||||
#endif /* !ECMA_HELPERS_NUMBER_H */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,520 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_HELPERS_H
|
||||
#define ECMA_HELPERS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#include "jmem.h"
|
||||
#include "lit-strings.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get value of pointer from specified non-null compressed pointer.
|
||||
*/
|
||||
#define ECMA_GET_NON_NULL_POINTER(type, field) JMEM_CP_GET_NON_NULL_POINTER (type, field)
|
||||
|
||||
/**
|
||||
* Extract value of pointer from specified pointer-tag value
|
||||
*/
|
||||
#define ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, field) \
|
||||
JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG (type, field)
|
||||
|
||||
/**
|
||||
* Get value of pointer from specified compressed pointer.
|
||||
*/
|
||||
#define ECMA_GET_POINTER(type, field) JMEM_CP_GET_POINTER (type, field)
|
||||
|
||||
/**
|
||||
* Set value of non-null compressed pointer so that it will correspond
|
||||
* to specified non_compressed_pointer.
|
||||
*/
|
||||
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \
|
||||
JMEM_CP_SET_NON_NULL_POINTER (field, non_compressed_pointer)
|
||||
|
||||
/**
|
||||
* Set value of pointer-tag value so that it will correspond
|
||||
* to specified non_compressed_pointer along with tag
|
||||
*/
|
||||
#define ECMA_SET_NON_NULL_POINTER_TAG(field, non_compressed_pointer, tag) \
|
||||
JMEM_CP_SET_NON_NULL_POINTER_TAG (field, non_compressed_pointer, tag)
|
||||
|
||||
/**
|
||||
* Set value of compressed pointer so that it will correspond
|
||||
* to specified non_compressed_pointer.
|
||||
*/
|
||||
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
|
||||
|
||||
/**
|
||||
* Get value of each tag bit from specified pointer-tag value
|
||||
*/
|
||||
#define ECMA_GET_FIRST_BIT_FROM_POINTER_TAG(field) \
|
||||
JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (field) /**< get first tag bit from jmem_cpointer_tag_t **/
|
||||
#define ECMA_GET_SECOND_BIT_FROM_POINTER_TAG(field) \
|
||||
JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (field) /**< get second tag bit from jmem_cpointer_tag_t **/
|
||||
#define ECMA_GET_THIRD_BIT_FROM_POINTER_TAG(field) \
|
||||
JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (field) /**< get third tag bit from jmem_cpointer_tag_t **/
|
||||
|
||||
/**
|
||||
* Set value of each tag bit to specified pointer-tag value
|
||||
*/
|
||||
#define ECMA_SET_FIRST_BIT_TO_POINTER_TAG(field) \
|
||||
JMEM_CP_SET_FIRST_BIT_TO_POINTER_TAG (field) /**< set first tag bit to jmem_cpointer_tag_t **/
|
||||
#define ECMA_SET_SECOND_BIT_TO_POINTER_TAG(field) \
|
||||
JMEM_CP_SET_SECOND_BIT_TO_POINTER_TAG (field) /**< set second tag bit to jmem_cpointer_tag_t **/
|
||||
#define ECMA_SET_THIRD_BIT_TO_POINTER_TAG(field) \
|
||||
JMEM_CP_SET_THIRD_BIT_TO_POINTER_TAG (field) /**< set third tag bit to jmem_cpointer_tag_t **/
|
||||
|
||||
/**
|
||||
* Status flags for ecma_string_get_chars function
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_STRING_FLAG_EMPTY = 0, /**< No options are provided. */
|
||||
ECMA_STRING_FLAG_IS_ASCII = (1 << 0), /**< The string contains only ASCII characters. */
|
||||
ECMA_STRING_FLAG_REHASH_NEEDED = (1 << 1), /**< The hash of the string must be recalculated.
|
||||
* For more details see ecma_append_chars_to_string */
|
||||
ECMA_STRING_FLAG_IS_UINT32 = (1 << 2), /**< The string represents an UINT32 number */
|
||||
ECMA_STRING_FLAG_MUST_BE_FREED = (1 << 3), /**< The returned buffer must be freed */
|
||||
} ecma_string_flag_t;
|
||||
|
||||
/**
|
||||
* Underscore is ignored when this option is passed.
|
||||
*/
|
||||
#define ECMA_CONVERSION_ALLOW_UNDERSCORE 0x1
|
||||
|
||||
/**
|
||||
* Convert ecma-string's contents to a cesu-8 string and put it into a buffer.
|
||||
*/
|
||||
#define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \
|
||||
utf8_ptr, /**< [out] output buffer pointer */ \
|
||||
utf8_str_size) /**< [out] output buffer size */ \
|
||||
lit_utf8_size_t utf8_str_size; \
|
||||
uint8_t utf8_ptr##flags = ECMA_STRING_FLAG_EMPTY; \
|
||||
const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, NULL, NULL, &utf8_ptr##flags);
|
||||
|
||||
/**
|
||||
* Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING'
|
||||
*/
|
||||
#define ECMA_FINALIZE_UTF8_STRING(utf8_ptr, /**< pointer to character buffer */ \
|
||||
utf8_str_size) /**< buffer size */ \
|
||||
if (utf8_ptr##flags & ECMA_STRING_FLAG_MUST_BE_FREED) \
|
||||
{ \
|
||||
JERRY_ASSERT (utf8_ptr != NULL); \
|
||||
jmem_heap_free_block ((void *) utf8_ptr, utf8_str_size); \
|
||||
}
|
||||
|
||||
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
|
||||
|
||||
/**
|
||||
* Set an internal property value from pointer.
|
||||
*/
|
||||
#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) ((field) = ((ecma_value_t) pointer))
|
||||
|
||||
/**
|
||||
* Set an internal property value from pointer. Pointer can be NULL.
|
||||
*/
|
||||
#define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) ((field) = ((ecma_value_t) pointer))
|
||||
|
||||
/**
|
||||
* Convert an internal property value to pointer.
|
||||
*/
|
||||
#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) ((type *) field)
|
||||
|
||||
/**
|
||||
* Convert an internal property value to pointer. Result can be NULL.
|
||||
*/
|
||||
#define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) ((type *) field)
|
||||
|
||||
/**
|
||||
* Checks whether an internal property is NULL.
|
||||
*/
|
||||
#define ECMA_IS_INTERNAL_VALUE_NULL(field) ((field) == ((ecma_value_t) NULL))
|
||||
|
||||
#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
|
||||
|
||||
/**
|
||||
* Set an internal property value from pointer.
|
||||
*/
|
||||
#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) ECMA_SET_NON_NULL_POINTER (field, pointer)
|
||||
|
||||
/**
|
||||
* Set an internal property value from pointer. Pointer can be NULL.
|
||||
*/
|
||||
#define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) ECMA_SET_POINTER (field, pointer)
|
||||
|
||||
/**
|
||||
* Convert an internal property value to pointer.
|
||||
*/
|
||||
#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) ECMA_GET_NON_NULL_POINTER (type, field)
|
||||
|
||||
/**
|
||||
* Convert an internal property value to pointer. Result can be NULL.
|
||||
*/
|
||||
#define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) ECMA_GET_POINTER (type, field)
|
||||
|
||||
/**
|
||||
* Checks whether an internal property is NULL.
|
||||
*/
|
||||
#define ECMA_IS_INTERNAL_VALUE_NULL(field) ((field) == ((ecma_value_t) JMEM_CP_NULL))
|
||||
|
||||
#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */
|
||||
|
||||
/**
|
||||
* Convert boolean to bitfield value.
|
||||
*/
|
||||
#define ECMA_BOOL_TO_BITFIELD(x) ((x) ? 1 : 0)
|
||||
|
||||
/**
|
||||
* Check whether the given type is ECMA_OBJECT_TYPE_PROXY
|
||||
*
|
||||
* @param type object type
|
||||
*/
|
||||
#define ECMA_OBJECT_TYPE_IS_PROXY(type) (JERRY_UNLIKELY ((type) == ECMA_OBJECT_TYPE_PROXY))
|
||||
|
||||
/**
|
||||
* Check whether the given object has [[ProxyHandler]] and [[ProxyTarger]] internal slots
|
||||
*
|
||||
* @param obj_p ecma-object
|
||||
*/
|
||||
#if JERRY_BUILTIN_PROXY
|
||||
#define ECMA_OBJECT_IS_PROXY(obj_p) (ECMA_OBJECT_TYPE_IS_PROXY (ecma_get_object_type ((obj_p))))
|
||||
#else /* !JERRY_BUILTIN_PROXY */
|
||||
#define ECMA_OBJECT_IS_PROXY(obj_p) (false)
|
||||
#endif /* JERRY_BUILTIN_PROXY */
|
||||
|
||||
/* ecma-helpers-value.c */
|
||||
ecma_type_t JERRY_ATTR_CONST ecma_get_value_type_field (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_direct (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_simple (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_empty (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_undefined (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_null (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_boolean (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_true (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_false (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_found (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_array_hole (ecma_value_t value);
|
||||
|
||||
bool JERRY_ATTR_CONST ecma_is_value_integer_number (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_are_values_integer_numbers (ecma_value_t first_value, ecma_value_t second_value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_magic_string (ecma_value_t value, lit_magic_string_id_t id);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_bigint (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_non_direct_string (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_object (ecma_value_t value);
|
||||
bool JERRY_ATTR_CONST ecma_is_value_exception (ecma_value_t value);
|
||||
ecma_value_t ecma_is_value_array (ecma_value_t arg);
|
||||
|
||||
void ecma_check_value_type_is_spec_defined (ecma_value_t value);
|
||||
|
||||
ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value);
|
||||
ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value);
|
||||
ecma_value_t ecma_make_nan_value (void);
|
||||
ecma_value_t ecma_make_float_value (ecma_number_t *ecma_num_p);
|
||||
ecma_value_t ecma_make_length_value (ecma_length_t length);
|
||||
ecma_value_t ecma_make_number_value (ecma_number_t ecma_number);
|
||||
ecma_value_t ecma_make_int32_value (int32_t int32_number);
|
||||
ecma_value_t ecma_make_uint32_value (uint32_t uint32_number);
|
||||
ecma_value_t JERRY_ATTR_PURE ecma_make_string_value (const ecma_string_t *ecma_string_p);
|
||||
ecma_value_t JERRY_ATTR_PURE ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p);
|
||||
ecma_value_t JERRY_ATTR_PURE ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p);
|
||||
ecma_value_t JERRY_ATTR_PURE ecma_make_magic_string_value (lit_magic_string_id_t id);
|
||||
ecma_value_t JERRY_ATTR_PURE ecma_make_object_value (const ecma_object_t *object_p);
|
||||
ecma_value_t JERRY_ATTR_PURE ecma_make_extended_primitive_value (const ecma_extended_primitive_t *primitive_p,
|
||||
uint32_t type);
|
||||
ecma_integer_value_t JERRY_ATTR_CONST ecma_get_integer_from_value (ecma_value_t value);
|
||||
ecma_number_t JERRY_ATTR_PURE ecma_get_float_from_value (ecma_value_t value);
|
||||
ecma_number_t *ecma_get_pointer_from_float_value (ecma_value_t value);
|
||||
ecma_number_t JERRY_ATTR_PURE ecma_get_number_from_value (ecma_value_t value);
|
||||
ecma_string_t JERRY_ATTR_PURE *ecma_get_string_from_value (ecma_value_t value);
|
||||
ecma_string_t JERRY_ATTR_PURE *ecma_get_symbol_from_value (ecma_value_t value);
|
||||
ecma_string_t JERRY_ATTR_PURE *ecma_get_prop_name_from_value (ecma_value_t value);
|
||||
ecma_object_t JERRY_ATTR_PURE *ecma_get_object_from_value (ecma_value_t value);
|
||||
ecma_extended_primitive_t JERRY_ATTR_PURE *ecma_get_extended_primitive_from_value (ecma_value_t value);
|
||||
ecma_value_t JERRY_ATTR_CONST ecma_invert_boolean_value (ecma_value_t value);
|
||||
ecma_value_t ecma_copy_value (ecma_value_t value);
|
||||
ecma_value_t ecma_fast_copy_value (ecma_value_t value);
|
||||
ecma_value_t ecma_copy_value_if_not_object (ecma_value_t value);
|
||||
void ecma_ref_if_object (ecma_value_t value);
|
||||
void ecma_deref_if_object (ecma_value_t value);
|
||||
ecma_value_t ecma_update_float_number (ecma_value_t float_value, ecma_number_t new_number);
|
||||
void ecma_value_assign_value (ecma_value_t *value_p, ecma_value_t ecma_value);
|
||||
void ecma_value_assign_number (ecma_value_t *value_p, ecma_number_t ecma_number);
|
||||
void ecma_free_value (ecma_value_t value);
|
||||
void ecma_fast_free_value (ecma_value_t value);
|
||||
void ecma_free_value_if_not_object (ecma_value_t value);
|
||||
void ecma_free_object (ecma_value_t value);
|
||||
void ecma_free_number (ecma_value_t value);
|
||||
lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value);
|
||||
|
||||
/* ecma-helpers-string.c */
|
||||
ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc);
|
||||
bool ecma_prop_name_is_symbol (ecma_string_t *string_p);
|
||||
ecma_length_t ecma_op_advance_string_index (ecma_string_t *str_p, ecma_length_t index_num, bool is_unicode);
|
||||
#if JERRY_BUILTIN_CONTAINER
|
||||
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);
|
||||
bool ecma_prop_name_is_map_key (ecma_string_t *string_p);
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
ecma_string_t *ecma_new_ecma_string_from_ascii (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size);
|
||||
ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size);
|
||||
ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p,
|
||||
lit_utf8_size_t string_size);
|
||||
ecma_string_t *
|
||||
ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size, void *user_p);
|
||||
ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
|
||||
ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit);
|
||||
ecma_string_t *ecma_new_ecma_string_from_length (ecma_length_t index);
|
||||
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num);
|
||||
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
|
||||
ecma_string_t *ecma_get_internal_string (lit_magic_string_id_t id);
|
||||
ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p,
|
||||
const lit_utf8_byte_t *cesu8_string2_p,
|
||||
lit_utf8_size_t cesu8_string2_size,
|
||||
lit_utf8_size_t cesu8_string2_length);
|
||||
ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p);
|
||||
void ecma_ref_ecma_string (ecma_string_t *string_p);
|
||||
void ecma_ref_ecma_string_non_direct (ecma_string_t *string_p);
|
||||
void ecma_deref_ecma_string (ecma_string_t *string_p);
|
||||
void ecma_deref_ecma_string_non_direct (ecma_string_t *string_p);
|
||||
void ecma_destroy_ecma_string (ecma_string_t *string_p);
|
||||
ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
|
||||
uint32_t ecma_string_get_array_index (const ecma_string_t *str_p);
|
||||
|
||||
lit_utf8_size_t ecma_string_copy_to_buffer (const ecma_string_t *string_desc_p,
|
||||
lit_utf8_byte_t *buffer_p,
|
||||
lit_utf8_size_t buffer_size,
|
||||
jerry_encoding_t encoding);
|
||||
void ecma_string_to_cesu8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size);
|
||||
const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p,
|
||||
lit_utf8_size_t *size_p,
|
||||
lit_utf8_size_t *length_p,
|
||||
lit_utf8_byte_t *uint32_buff_p,
|
||||
uint8_t *flags_p);
|
||||
bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id);
|
||||
bool ecma_string_is_empty (const ecma_string_t *string_p);
|
||||
bool ecma_string_is_length (const ecma_string_t *string_p);
|
||||
|
||||
jmem_cpointer_t ecma_string_to_property_name (ecma_string_t *prop_name_p, ecma_property_t *name_type_p);
|
||||
ecma_string_t *ecma_string_from_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp);
|
||||
lit_string_hash_t ecma_string_get_property_name_hash (ecma_property_t property, jmem_cpointer_t prop_name_cp);
|
||||
uint32_t ecma_string_get_property_index (ecma_property_t property, jmem_cpointer_t prop_name_cp);
|
||||
bool ecma_string_compare_to_property_name (ecma_property_t property,
|
||||
jmem_cpointer_t prop_name_cp,
|
||||
const ecma_string_t *string_p);
|
||||
|
||||
bool ecma_compare_ecma_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p);
|
||||
bool ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p);
|
||||
bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, const ecma_string_t *string2_p);
|
||||
lit_utf8_size_t ecma_string_get_length (const ecma_string_t *string_p);
|
||||
lit_utf8_size_t ecma_string_get_utf8_length (const ecma_string_t *string_p);
|
||||
lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p);
|
||||
lit_utf8_size_t ecma_string_get_utf8_size (const ecma_string_t *string_p);
|
||||
ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, lit_utf8_size_t index);
|
||||
|
||||
lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p);
|
||||
|
||||
lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
|
||||
ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, lit_utf8_size_t start_pos, lit_utf8_size_t end_pos);
|
||||
const lit_utf8_byte_t *ecma_string_trim_front (const lit_utf8_byte_t *start_p, const lit_utf8_byte_t *end_p);
|
||||
const lit_utf8_byte_t *ecma_string_trim_back (const lit_utf8_byte_t *start_p, const lit_utf8_byte_t *end_p);
|
||||
void ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, lit_utf8_size_t *utf8_str_size);
|
||||
ecma_string_t *ecma_string_trim (const ecma_string_t *string_p);
|
||||
ecma_value_t
|
||||
ecma_string_pad (ecma_value_t original_string_p, ecma_value_t max_length, ecma_value_t fill_string, bool pad_on_start);
|
||||
|
||||
ecma_stringbuilder_t ecma_stringbuilder_create (void);
|
||||
ecma_stringbuilder_t ecma_stringbuilder_create_from (ecma_string_t *string_p);
|
||||
ecma_stringbuilder_t ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p, const lit_utf8_size_t data_size);
|
||||
lit_utf8_size_t ecma_stringbuilder_get_size (ecma_stringbuilder_t *builder_p);
|
||||
lit_utf8_byte_t *ecma_stringbuilder_get_data (ecma_stringbuilder_t *builder_p);
|
||||
void ecma_stringbuilder_revert (ecma_stringbuilder_t *builder_p, const lit_utf8_size_t size);
|
||||
void ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, const ecma_string_t *string_p);
|
||||
void ecma_stringbuilder_append_magic (ecma_stringbuilder_t *builder_p, const lit_magic_string_id_t id);
|
||||
void ecma_stringbuilder_append_raw (ecma_stringbuilder_t *builder_p,
|
||||
const lit_utf8_byte_t *data_p,
|
||||
const lit_utf8_size_t data_size);
|
||||
void ecma_stringbuilder_append_codepoint (ecma_stringbuilder_t *builder_p, lit_code_point_t cp);
|
||||
void ecma_stringbuilder_append_char (ecma_stringbuilder_t *builder_p, const ecma_char_t c);
|
||||
void ecma_stringbuilder_append_byte (ecma_stringbuilder_t *builder_p, const lit_utf8_byte_t);
|
||||
ecma_string_t *ecma_stringbuilder_finalize (ecma_stringbuilder_t *builder_p);
|
||||
void ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p);
|
||||
|
||||
/* ecma-helpers-number.c */
|
||||
ecma_number_t ecma_number_make_nan (void);
|
||||
ecma_number_t ecma_number_make_infinity (bool sign);
|
||||
bool ecma_number_is_nan (ecma_number_t num);
|
||||
bool ecma_number_is_negative (ecma_number_t num);
|
||||
bool ecma_number_is_zero (ecma_number_t num);
|
||||
bool ecma_number_is_infinity (ecma_number_t num);
|
||||
bool ecma_number_is_finite (ecma_number_t num);
|
||||
ecma_number_t ecma_number_get_prev (ecma_number_t num);
|
||||
ecma_number_t ecma_number_get_next (ecma_number_t num);
|
||||
ecma_number_t ecma_number_trunc (ecma_number_t num);
|
||||
ecma_number_t ecma_number_remainder (ecma_number_t left_num, ecma_number_t right_num);
|
||||
ecma_number_t ecma_number_pow (ecma_number_t x, ecma_number_t y);
|
||||
ecma_value_t
|
||||
ecma_number_parse_int (const lit_utf8_byte_t *string_buff, lit_utf8_size_t string_buff_size, ecma_value_t radix);
|
||||
ecma_value_t ecma_number_parse_float (const lit_utf8_byte_t *string_buff, lit_utf8_size_t string_buff_size);
|
||||
ecma_value_t ecma_integer_multiply (ecma_integer_value_t left_integer, ecma_integer_value_t right_integer);
|
||||
lit_utf8_size_t ecma_number_to_decimal (ecma_number_t num, lit_utf8_byte_t *out_digits_p, int32_t *out_decimal_exp_p);
|
||||
|
||||
/* ecma-helpers-collection.c */
|
||||
ecma_collection_t *ecma_new_collection (void);
|
||||
void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value);
|
||||
void ecma_collection_reserve (ecma_collection_t *collection_p, uint32_t count);
|
||||
void ecma_collection_append (ecma_collection_t *collection_p, const ecma_value_t *buffer_p, uint32_t count);
|
||||
void ecma_collection_destroy (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free_if_not_object (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free_objects (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free_template_literal (ecma_collection_t *collection_p);
|
||||
bool ecma_collection_check_duplicated_entries (ecma_collection_t *collection_p);
|
||||
bool ecma_collection_has_string_value (ecma_collection_t *collection_p, ecma_string_t *string_p);
|
||||
|
||||
ecma_value_t *ecma_new_compact_collection (void);
|
||||
ecma_value_t *ecma_compact_collection_push_back (ecma_value_t *compact_collection_p, ecma_value_t value);
|
||||
ecma_value_t *ecma_compact_collection_shrink (ecma_value_t *compact_collection_p);
|
||||
void ecma_compact_collection_free (ecma_value_t *compact_collection_p);
|
||||
ecma_value_t *ecma_compact_collection_end (ecma_value_t *compact_collection_p);
|
||||
void ecma_compact_collection_destroy (ecma_value_t *compact_collection_p);
|
||||
|
||||
/* ecma-helpers.c */
|
||||
ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type);
|
||||
ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p);
|
||||
ecma_object_t *ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p);
|
||||
ecma_object_t *ecma_create_lex_env_class (ecma_object_t *outer_lexical_environment_p, size_t lexical_env_size);
|
||||
bool JERRY_ATTR_PURE ecma_is_lexical_environment (const ecma_object_t *object_p);
|
||||
void ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p);
|
||||
ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p);
|
||||
ecma_object_base_type_t JERRY_ATTR_PURE ecma_get_object_base_type (const ecma_object_t *object_p);
|
||||
bool JERRY_ATTR_PURE ecma_object_class_is (ecma_object_t *object_p, ecma_object_class_type_t class_id);
|
||||
ecma_lexical_environment_type_t JERRY_ATTR_PURE ecma_get_lex_env_type (const ecma_object_t *object_p);
|
||||
ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p);
|
||||
ecma_object_t *ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, bool copy_values);
|
||||
|
||||
ecma_property_value_t *ecma_create_named_data_property (ecma_object_t *object_p,
|
||||
ecma_string_t *name_p,
|
||||
uint8_t prop_attributes,
|
||||
ecma_property_t **out_prop_p);
|
||||
ecma_property_value_t *ecma_create_named_accessor_property (ecma_object_t *object_p,
|
||||
ecma_string_t *name_p,
|
||||
ecma_object_t *get_p,
|
||||
ecma_object_t *set_p,
|
||||
uint8_t prop_attributes,
|
||||
ecma_property_t **out_prop_p);
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
void ecma_create_named_reference_property (ecma_object_t *object_p, ecma_string_t *name_p, ecma_value_t reference);
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
ecma_property_t *ecma_find_named_property (ecma_object_t *obj_p, ecma_string_t *name_p);
|
||||
ecma_property_value_t *ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p);
|
||||
|
||||
void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p);
|
||||
|
||||
void
|
||||
ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p, ecma_value_t value);
|
||||
|
||||
ecma_getter_setter_pointers_t *ecma_get_named_accessor_property (const ecma_property_value_t *prop_value_p);
|
||||
void ecma_set_named_accessor_property_getter (ecma_object_t *object_p,
|
||||
ecma_property_value_t *prop_value_p,
|
||||
ecma_object_t *getter_p);
|
||||
void ecma_set_named_accessor_property_setter (ecma_object_t *object_p,
|
||||
ecma_property_value_t *prop_value_p,
|
||||
ecma_object_t *setter_p);
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ecma_value_t ecma_property_to_reference (ecma_property_t *property_p);
|
||||
ecma_property_value_t *ecma_get_property_value_from_named_reference (ecma_property_value_t *reference_p);
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
bool ecma_is_property_writable (ecma_property_t property);
|
||||
void ecma_set_property_writable_attr (ecma_property_t *property_p, bool is_writable);
|
||||
bool ecma_is_property_enumerable (ecma_property_t property);
|
||||
void ecma_set_property_enumerable_attr (ecma_property_t *property_p, bool is_enumerable);
|
||||
bool ecma_is_property_configurable (ecma_property_t property);
|
||||
void ecma_set_property_configurable_attr (ecma_property_t *property_p, bool is_configurable);
|
||||
|
||||
#if JERRY_LCACHE
|
||||
bool ecma_is_property_lcached (ecma_property_t *property_p);
|
||||
void ecma_set_property_lcached (ecma_property_t *property_p, bool is_lcached);
|
||||
#endif /* JERRY_LCACHE */
|
||||
|
||||
ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
|
||||
void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p);
|
||||
|
||||
void ecma_ref_extended_primitive (ecma_extended_primitive_t *primitive_p);
|
||||
void ecma_deref_exception (ecma_extended_primitive_t *exception_p);
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
void ecma_deref_bigint (ecma_extended_primitive_t *bigint_p);
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
ecma_value_t ecma_create_exception (ecma_value_t value, uint32_t options);
|
||||
ecma_value_t ecma_create_exception_from_context (void);
|
||||
ecma_value_t ecma_create_exception_from_object (ecma_object_t *object_p);
|
||||
void ecma_throw_exception (ecma_value_t value);
|
||||
|
||||
void ecma_script_deref (ecma_value_t script_value);
|
||||
void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
|
||||
void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
|
||||
ecma_value_t ecma_script_get_from_value (ecma_value_t value);
|
||||
ecma_value_t *ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p);
|
||||
ecma_value_t *ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p);
|
||||
ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p);
|
||||
ecma_value_t ecma_get_source_name (const ecma_compiled_code_t *bytecode_p);
|
||||
#if (JERRY_STACK_LIMIT != 0)
|
||||
uintptr_t ecma_get_current_stack_usage (void);
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
|
||||
/* ecma-helpers-external-pointers.c */
|
||||
bool ecma_create_native_pointer_property (ecma_object_t *obj_p,
|
||||
void *native_p,
|
||||
const jerry_object_native_info_t *native_info_p);
|
||||
ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p,
|
||||
const jerry_object_native_info_t *native_info_p);
|
||||
bool ecma_delete_native_pointer_property (ecma_object_t *obj_p, const jerry_object_native_info_t *native_info_p);
|
||||
|
||||
/* ecma-helpers-conversion.c */
|
||||
ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size, uint32_t option);
|
||||
ecma_number_t ecma_utf8_string_to_number_by_radix (const lit_utf8_byte_t *str_p,
|
||||
lit_utf8_size_t str_size,
|
||||
uint32_t radix,
|
||||
uint32_t option);
|
||||
lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t value, lit_utf8_byte_t *out_buffer_p, lit_utf8_size_t buffer_size);
|
||||
uint32_t ecma_number_to_uint32 (ecma_number_t num);
|
||||
int32_t ecma_number_to_int32 (ecma_number_t num);
|
||||
lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t num, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size);
|
||||
|
||||
/* ecma-helpers-errol.c */
|
||||
lit_utf8_size_t ecma_errol0_dtoa (double val, lit_utf8_byte_t *buffer_p, int32_t *exp_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_HELPERS_H */
|
||||
@@ -0,0 +1,106 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-init-finalize.h"
|
||||
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-literal-storage.h"
|
||||
|
||||
#include "jcontext.h"
|
||||
#include "jmem.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmainitfinalize Initialization and finalization of ECMA components
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Maximum number of GC loops on cleanup.
|
||||
*/
|
||||
#define JERRY_GC_LOOP_LIMIT 100
|
||||
|
||||
/**
|
||||
* Initialize ECMA components
|
||||
*/
|
||||
void
|
||||
ecma_init (void)
|
||||
{
|
||||
#if (JERRY_GC_MARK_LIMIT != 0)
|
||||
JERRY_CONTEXT (ecma_gc_mark_recursion_limit) = JERRY_GC_MARK_LIMIT;
|
||||
#endif /* (JERRY_GC_MARK_LIMIT != 0) */
|
||||
|
||||
ecma_init_global_environment ();
|
||||
|
||||
#if JERRY_PROPERTY_HASHMAP
|
||||
JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) = ECMA_PROP_HASHMAP_ALLOC_ON;
|
||||
JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_HIGH_PRESSURE_GC;
|
||||
#endif /* JERRY_PROPERTY_HASHMAP */
|
||||
|
||||
#if (JERRY_STACK_LIMIT != 0)
|
||||
volatile int sp;
|
||||
JERRY_CONTEXT (stack_base) = (uintptr_t) &sp;
|
||||
#endif /* (JERRY_STACK_LIMIT != 0) */
|
||||
|
||||
ecma_job_queue_init ();
|
||||
|
||||
JERRY_CONTEXT (current_new_target_p) = NULL;
|
||||
|
||||
#if JERRY_BUILTIN_TYPEDARRAY
|
||||
JERRY_CONTEXT (arraybuffer_compact_allocation_limit) = 256;
|
||||
#endif /* JERRY_BUILTIN_TYPEDARRAY */
|
||||
} /* ecma_init */
|
||||
|
||||
/**
|
||||
* Finalize ECMA components
|
||||
*/
|
||||
void
|
||||
ecma_finalize (void)
|
||||
{
|
||||
JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p) == NULL);
|
||||
|
||||
ecma_finalize_global_environment ();
|
||||
uint8_t runs = 0;
|
||||
|
||||
do
|
||||
{
|
||||
ecma_gc_run ();
|
||||
if (++runs >= JERRY_GC_LOOP_LIMIT)
|
||||
{
|
||||
jerry_fatal (JERRY_FATAL_UNTERMINATED_GC_LOOPS);
|
||||
}
|
||||
} while (JERRY_CONTEXT (ecma_gc_new_objects) != 0);
|
||||
|
||||
jmem_cpointer_t *global_symbols_cp = JERRY_CONTEXT (global_symbols_cp);
|
||||
|
||||
for (uint32_t i = 0; i < ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT; i++)
|
||||
{
|
||||
if (global_symbols_cp[i] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (ecma_string_t, global_symbols_cp[i]));
|
||||
}
|
||||
}
|
||||
|
||||
ecma_finalize_lit_storage ();
|
||||
} /* ecma_finalize */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_INIT_FINALIZE_H
|
||||
#define ECMA_INIT_FINALIZE_H
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmainitfinalize Initialization and finalization of ECMA components
|
||||
* @{
|
||||
*/
|
||||
|
||||
void ecma_init (void);
|
||||
void ecma_finalize (void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_INIT_FINALIZE_H */
|
||||
@@ -0,0 +1,217 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-lcache.h"
|
||||
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "jcontext.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmalcache Property lookup cache
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if JERRY_LCACHE
|
||||
|
||||
/**
|
||||
* Bitshift index for calculating hash.
|
||||
*/
|
||||
#define ECMA_LCACHE_HASH_BITSHIFT_INDEX 0
|
||||
|
||||
/**
|
||||
* Mask for hash bits
|
||||
*/
|
||||
#define ECMA_LCACHE_HASH_MASK ((ECMA_LCACHE_HASH_ROWS_COUNT - 1) << ECMA_LCACHE_HASH_BITSHIFT_INDEX)
|
||||
|
||||
/**
|
||||
* Bitshift index for creating property identifier
|
||||
*/
|
||||
#define ECMA_LCACHE_HASH_ENTRY_ID_SHIFT (8 * sizeof (jmem_cpointer_t))
|
||||
|
||||
/**
|
||||
* Create property identifier
|
||||
*/
|
||||
#define ECMA_LCACHE_CREATE_ID(object_cp, name_cp) \
|
||||
(((ecma_lcache_hash_entry_id_t) (object_cp) << ECMA_LCACHE_HASH_ENTRY_ID_SHIFT) | (name_cp))
|
||||
|
||||
/**
|
||||
* Invalidate specified LCache entry
|
||||
*/
|
||||
static inline void
|
||||
ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to invalidate */
|
||||
{
|
||||
JERRY_ASSERT (entry_p != NULL);
|
||||
JERRY_ASSERT (entry_p->id != 0);
|
||||
JERRY_ASSERT (entry_p->prop_p != NULL);
|
||||
|
||||
entry_p->id = 0;
|
||||
ecma_set_property_lcached (entry_p->prop_p, false);
|
||||
} /* ecma_lcache_invalidate_entry */
|
||||
|
||||
/**
|
||||
* Compute the row index of object / property name pair
|
||||
*
|
||||
* @return row index
|
||||
*/
|
||||
static inline size_t
|
||||
ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to object */
|
||||
jmem_cpointer_t name_cp) /**< compressed pointer to property name */
|
||||
{
|
||||
/* Randomize the property name with the object pointer using a xor operation,
|
||||
* so properties of different objects with the same name can be cached effectively. */
|
||||
return (size_t) (((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK) >> ECMA_LCACHE_HASH_BITSHIFT_INDEX);
|
||||
} /* ecma_lcache_row_index */
|
||||
|
||||
/**
|
||||
* Insert an entry into LCache
|
||||
*/
|
||||
void
|
||||
ecma_lcache_insert (const ecma_object_t *object_p, /**< object */
|
||||
const jmem_cpointer_t name_cp, /**< property name */
|
||||
ecma_property_t *prop_p) /**< property */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
JERRY_ASSERT (prop_p != NULL && !ecma_is_property_lcached (prop_p));
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*prop_p));
|
||||
|
||||
jmem_cpointer_t object_cp;
|
||||
|
||||
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
||||
|
||||
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
|
||||
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache)[row_index];
|
||||
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
|
||||
|
||||
do
|
||||
{
|
||||
if (entry_p->id == 0)
|
||||
{
|
||||
goto insert;
|
||||
}
|
||||
|
||||
entry_p++;
|
||||
} while (entry_p < entry_end_p);
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
ecma_lcache_invalidate_entry (--entry_p);
|
||||
|
||||
/* Shift other entries towards the end. */
|
||||
for (uint32_t i = 0; i < ECMA_LCACHE_HASH_ROW_LENGTH - 1; i++)
|
||||
{
|
||||
entry_p->id = entry_p[-1].id;
|
||||
entry_p->prop_p = entry_p[-1].prop_p;
|
||||
entry_p--;
|
||||
}
|
||||
|
||||
insert:
|
||||
entry_p->prop_p = prop_p;
|
||||
entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp);
|
||||
|
||||
ecma_set_property_lcached (entry_p->prop_p, true);
|
||||
} /* ecma_lcache_insert */
|
||||
|
||||
/**
|
||||
* Lookup property in the LCache
|
||||
*
|
||||
* @return a pointer to an ecma_property_t if the lookup is successful
|
||||
* NULL otherwise
|
||||
*/
|
||||
ecma_property_t *
|
||||
ecma_lcache_lookup (const ecma_object_t *object_p, /**< object */
|
||||
const ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
JERRY_ASSERT (prop_name_p != NULL);
|
||||
|
||||
jmem_cpointer_t object_cp;
|
||||
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
||||
|
||||
ecma_property_t prop_name_type = ECMA_DIRECT_STRING_PTR;
|
||||
jmem_cpointer_t prop_name_cp;
|
||||
|
||||
if (JERRY_UNLIKELY (ECMA_IS_DIRECT_STRING (prop_name_p)))
|
||||
{
|
||||
prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p);
|
||||
prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p);
|
||||
}
|
||||
|
||||
size_t row_index = ecma_lcache_row_index (object_cp, prop_name_cp);
|
||||
|
||||
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache)[row_index];
|
||||
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;
|
||||
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp);
|
||||
|
||||
do
|
||||
{
|
||||
if (entry_p->id == id && JERRY_LIKELY (ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type))
|
||||
{
|
||||
JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p));
|
||||
return entry_p->prop_p;
|
||||
}
|
||||
entry_p++;
|
||||
} while (entry_p < entry_end_p);
|
||||
|
||||
return NULL;
|
||||
} /* ecma_lcache_lookup */
|
||||
|
||||
/**
|
||||
* Invalidate LCache entries associated with given object and property name / property
|
||||
*/
|
||||
void
|
||||
ecma_lcache_invalidate (const ecma_object_t *object_p, /**< object */
|
||||
const jmem_cpointer_t name_cp, /**< property name */
|
||||
ecma_property_t *prop_p) /**< property */
|
||||
{
|
||||
JERRY_ASSERT (object_p != NULL);
|
||||
JERRY_ASSERT (prop_p != NULL && ecma_is_property_lcached (prop_p));
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*prop_p));
|
||||
|
||||
jmem_cpointer_t object_cp;
|
||||
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
|
||||
|
||||
size_t row_index = ecma_lcache_row_index (object_cp, name_cp);
|
||||
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache)[row_index];
|
||||
|
||||
while (true)
|
||||
{
|
||||
/* The property must be present. */
|
||||
JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache)[row_index] < ECMA_LCACHE_HASH_ROW_LENGTH);
|
||||
|
||||
if (entry_p->id != 0 && entry_p->prop_p == prop_p)
|
||||
{
|
||||
JERRY_ASSERT (entry_p->id == ECMA_LCACHE_CREATE_ID (object_cp, name_cp));
|
||||
|
||||
ecma_lcache_invalidate_entry (entry_p);
|
||||
return;
|
||||
}
|
||||
entry_p++;
|
||||
}
|
||||
} /* ecma_lcache_invalidate */
|
||||
|
||||
#endif /* JERRY_LCACHE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_LCACHE_H
|
||||
#define ECMA_LCACHE_H
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmalcache Property lookup cache
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#if JERRY_LCACHE
|
||||
void ecma_lcache_insert (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p);
|
||||
ecma_property_t *ecma_lcache_lookup (const ecma_object_t *object_p, const ecma_string_t *prop_name_p);
|
||||
void ecma_lcache_invalidate (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p);
|
||||
|
||||
#endif /* JERRY_LCACHE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_LCACHE_H */
|
||||
@@ -0,0 +1,741 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-literal-storage.h"
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-big-uint.h"
|
||||
#include "ecma-bigint.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "jcontext.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmalitstorage Literal storage
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Free symbol list
|
||||
*/
|
||||
static void
|
||||
ecma_free_symbol_list (jmem_cpointer_t symbol_list_cp) /**< symbol list */
|
||||
{
|
||||
while (symbol_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *symbol_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, symbol_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (symbol_list_p->values[i] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, symbol_list_p->values[i]);
|
||||
|
||||
JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p));
|
||||
ecma_deref_ecma_string (string_p);
|
||||
}
|
||||
}
|
||||
|
||||
jmem_cpointer_t next_item_cp = symbol_list_p->next_cp;
|
||||
jmem_pools_free (symbol_list_p, sizeof (ecma_lit_storage_item_t));
|
||||
symbol_list_cp = next_item_cp;
|
||||
}
|
||||
} /* ecma_free_symbol_list */
|
||||
|
||||
/**
|
||||
* Free string list
|
||||
*/
|
||||
static void
|
||||
ecma_free_string_list (jmem_cpointer_t string_list_cp) /**< string list */
|
||||
{
|
||||
while (string_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, string_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (string_list_p->values[i] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, string_list_p->values[i]);
|
||||
|
||||
JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p));
|
||||
ecma_destroy_ecma_string (string_p);
|
||||
}
|
||||
}
|
||||
|
||||
jmem_cpointer_t next_item_cp = string_list_p->next_cp;
|
||||
jmem_pools_free (string_list_p, sizeof (ecma_lit_storage_item_t));
|
||||
string_list_cp = next_item_cp;
|
||||
}
|
||||
} /* ecma_free_string_list */
|
||||
|
||||
/**
|
||||
* Free number list
|
||||
*/
|
||||
static void
|
||||
ecma_free_number_list (jmem_cpointer_t number_list_cp) /**< number list */
|
||||
{
|
||||
while (number_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *number_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, number_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (number_list_p->values[i] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_dealloc_number (JMEM_CP_GET_NON_NULL_POINTER (ecma_number_t, number_list_p->values[i]));
|
||||
}
|
||||
}
|
||||
|
||||
jmem_cpointer_t next_item_cp = number_list_p->next_cp;
|
||||
jmem_pools_free (number_list_p, sizeof (ecma_lit_storage_item_t));
|
||||
number_list_cp = next_item_cp;
|
||||
}
|
||||
} /* ecma_free_number_list */
|
||||
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
|
||||
/**
|
||||
* Free bigint list
|
||||
*/
|
||||
static void
|
||||
ecma_free_bigint_list (jmem_cpointer_t bigint_list_cp) /**< bigint list */
|
||||
{
|
||||
while (bigint_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *bigint_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, bigint_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (bigint_list_p->values[i] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_extended_primitive_t *bigint_p =
|
||||
JMEM_CP_GET_NON_NULL_POINTER (ecma_extended_primitive_t, bigint_list_p->values[i]);
|
||||
JERRY_ASSERT (ECMA_EXTENDED_PRIMITIVE_IS_REF_EQUALS_TO_ONE (bigint_p));
|
||||
ecma_deref_bigint (bigint_p);
|
||||
}
|
||||
}
|
||||
|
||||
jmem_cpointer_t next_item_cp = bigint_list_p->next_cp;
|
||||
jmem_pools_free (bigint_list_p, sizeof (ecma_lit_storage_item_t));
|
||||
bigint_list_cp = next_item_cp;
|
||||
}
|
||||
} /* ecma_free_bigint_list */
|
||||
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
/**
|
||||
* Finalize literal storage
|
||||
*/
|
||||
void
|
||||
ecma_finalize_lit_storage (void)
|
||||
{
|
||||
ecma_free_symbol_list (JERRY_CONTEXT (symbol_list_first_cp));
|
||||
ecma_free_string_list (JERRY_CONTEXT (string_list_first_cp));
|
||||
ecma_free_number_list (JERRY_CONTEXT (number_list_first_cp));
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ecma_free_bigint_list (JERRY_CONTEXT (bigint_list_first_cp));
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
} /* ecma_finalize_lit_storage */
|
||||
|
||||
/**
|
||||
* Find or create a literal string.
|
||||
*
|
||||
* @return ecma_string_t compressed pointer
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string to be searched */
|
||||
lit_utf8_size_t size, /**< size of the string */
|
||||
bool is_ascii) /**< encode of the string */
|
||||
{
|
||||
ecma_string_t *string_p =
|
||||
(is_ascii ? ecma_new_ecma_string_from_ascii (chars_p, size) : ecma_new_ecma_string_from_utf8 (chars_p, size));
|
||||
|
||||
if (ECMA_IS_DIRECT_STRING (string_p))
|
||||
{
|
||||
return ecma_make_string_value (string_p);
|
||||
}
|
||||
|
||||
jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp);
|
||||
jmem_cpointer_t *empty_cpointer_p = NULL;
|
||||
|
||||
while (string_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, string_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (string_list_p->values[i] == JMEM_CP_NULL)
|
||||
{
|
||||
if (empty_cpointer_p == NULL)
|
||||
{
|
||||
empty_cpointer_p = string_list_p->values + i;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, string_list_p->values[i]);
|
||||
|
||||
if (ecma_compare_ecma_strings (string_p, value_p))
|
||||
{
|
||||
/* Return with string if found in the list. */
|
||||
ecma_deref_ecma_string (string_p);
|
||||
return ecma_make_string_value (value_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_list_cp = string_list_p->next_cp;
|
||||
}
|
||||
|
||||
ECMA_SET_STRING_AS_STATIC (string_p);
|
||||
jmem_cpointer_t result;
|
||||
JMEM_CP_SET_NON_NULL_POINTER (result, string_p);
|
||||
|
||||
if (empty_cpointer_p != NULL)
|
||||
{
|
||||
*empty_cpointer_p = result;
|
||||
return ecma_make_string_value (string_p);
|
||||
}
|
||||
|
||||
ecma_lit_storage_item_t *new_item_p;
|
||||
new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t));
|
||||
|
||||
new_item_p->values[0] = result;
|
||||
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
new_item_p->values[i] = JMEM_CP_NULL;
|
||||
}
|
||||
|
||||
new_item_p->next_cp = JERRY_CONTEXT (string_list_first_cp);
|
||||
JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (string_list_first_cp), new_item_p);
|
||||
|
||||
return ecma_make_string_value (string_p);
|
||||
} /* ecma_find_or_create_literal_string */
|
||||
|
||||
/**
|
||||
* Find or create a literal number.
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be searched */
|
||||
{
|
||||
ecma_value_t num = ecma_make_number_value (number_arg);
|
||||
|
||||
if (ecma_is_value_integer_number (num))
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_float_number (num));
|
||||
|
||||
jmem_cpointer_t number_list_cp = JERRY_CONTEXT (number_list_first_cp);
|
||||
jmem_cpointer_t *empty_cpointer_p = NULL;
|
||||
|
||||
while (number_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *number_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, number_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (number_list_p->values[i] == JMEM_CP_NULL)
|
||||
{
|
||||
if (empty_cpointer_p == NULL)
|
||||
{
|
||||
empty_cpointer_p = number_list_p->values + i;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_number_t *number_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_number_t, number_list_p->values[i]);
|
||||
|
||||
if (*number_p == number_arg)
|
||||
{
|
||||
ecma_free_value (num);
|
||||
return ecma_make_float_value (number_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
number_list_cp = number_list_p->next_cp;
|
||||
}
|
||||
|
||||
jmem_cpointer_t result;
|
||||
JMEM_CP_SET_NON_NULL_POINTER (result, ecma_get_pointer_from_float_value (num));
|
||||
|
||||
if (empty_cpointer_p != NULL)
|
||||
{
|
||||
*empty_cpointer_p = result;
|
||||
return num;
|
||||
}
|
||||
|
||||
ecma_lit_storage_item_t *new_item_p;
|
||||
new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t));
|
||||
|
||||
new_item_p->values[0] = result;
|
||||
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
new_item_p->values[i] = JMEM_CP_NULL;
|
||||
}
|
||||
|
||||
new_item_p->next_cp = JERRY_CONTEXT (number_list_first_cp);
|
||||
JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (number_list_first_cp), new_item_p);
|
||||
|
||||
return num;
|
||||
} /* ecma_find_or_create_literal_number */
|
||||
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
|
||||
/**
|
||||
* Find or create a literal BigInt.
|
||||
*
|
||||
* @return BigInt value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_find_or_create_literal_bigint (ecma_value_t bigint) /**< bigint to be searched */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_bigint (bigint));
|
||||
|
||||
if (bigint == ECMA_BIGINT_ZERO)
|
||||
{
|
||||
return bigint;
|
||||
}
|
||||
|
||||
jmem_cpointer_t bigint_list_cp = JERRY_CONTEXT (bigint_list_first_cp);
|
||||
jmem_cpointer_t *empty_cpointer_p = NULL;
|
||||
|
||||
while (bigint_list_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_lit_storage_item_t *bigint_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, bigint_list_cp);
|
||||
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
if (bigint_list_p->values[i] == JMEM_CP_NULL)
|
||||
{
|
||||
if (empty_cpointer_p == NULL)
|
||||
{
|
||||
empty_cpointer_p = bigint_list_p->values + i;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_extended_primitive_t *other_bigint_p =
|
||||
JMEM_CP_GET_NON_NULL_POINTER (ecma_extended_primitive_t, bigint_list_p->values[i]);
|
||||
ecma_value_t other_bigint = ecma_make_extended_primitive_value (other_bigint_p, ECMA_TYPE_BIGINT);
|
||||
|
||||
if (ecma_bigint_is_equal_to_bigint (bigint, other_bigint))
|
||||
{
|
||||
ecma_free_value (bigint);
|
||||
return other_bigint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bigint_list_cp = bigint_list_p->next_cp;
|
||||
}
|
||||
|
||||
jmem_cpointer_t result;
|
||||
JMEM_CP_SET_NON_NULL_POINTER (result, ecma_get_extended_primitive_from_value (bigint));
|
||||
|
||||
if (empty_cpointer_p != NULL)
|
||||
{
|
||||
*empty_cpointer_p = result;
|
||||
return bigint;
|
||||
}
|
||||
|
||||
ecma_lit_storage_item_t *new_item_p;
|
||||
new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t));
|
||||
|
||||
new_item_p->values[0] = result;
|
||||
for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
{
|
||||
new_item_p->values[i] = JMEM_CP_NULL;
|
||||
}
|
||||
|
||||
new_item_p->next_cp = JERRY_CONTEXT (bigint_list_first_cp);
|
||||
JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (bigint_list_first_cp), new_item_p);
|
||||
|
||||
return bigint;
|
||||
} /* ecma_find_or_create_literal_bigint */
|
||||
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
/**
|
||||
* Log2 of snapshot literal alignment.
|
||||
*/
|
||||
#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG 1
|
||||
|
||||
/**
|
||||
* Snapshot literal alignment.
|
||||
*/
|
||||
#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT (1u << JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG)
|
||||
|
||||
/**
|
||||
* Literal offset shift.
|
||||
*/
|
||||
#define JERRY_SNAPSHOT_LITERAL_SHIFT (ECMA_VALUE_SHIFT + 2)
|
||||
|
||||
/**
|
||||
* Literal value is number.
|
||||
*/
|
||||
#define JERRY_SNAPSHOT_LITERAL_IS_NUMBER (1u << ECMA_VALUE_SHIFT)
|
||||
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
/**
|
||||
* Literal value is BigInt.
|
||||
*/
|
||||
#define JERRY_SNAPSHOT_LITERAL_IS_BIGINT (2u << ECMA_VALUE_SHIFT)
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
|
||||
/**
|
||||
* Append the value at the end of the appropriate list if it is not present there.
|
||||
*/
|
||||
void
|
||||
ecma_save_literals_append_value (ecma_value_t value, /**< value to be appended */
|
||||
ecma_collection_t *lit_pool_p) /**< list of known values */
|
||||
{
|
||||
/* Unlike direct numbers, direct strings are converted to character literals. */
|
||||
if (!ecma_is_value_string (value)
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
&& (!ecma_is_value_bigint (value) || value == ECMA_BIGINT_ZERO)
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
&& !ecma_is_value_float_number (value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ecma_value_t *buffer_p = lit_pool_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||
{
|
||||
/* Strings / numbers are direct strings or stored in the literal storage.
|
||||
* Therefore direct comparison is enough to find the same strings / numbers. */
|
||||
if (buffer_p[i] == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_collection_push_back (lit_pool_p, value);
|
||||
} /* ecma_save_literals_append_value */
|
||||
|
||||
/**
|
||||
* Add names from a byte-code data to a list.
|
||||
*/
|
||||
void
|
||||
ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< byte-code data */
|
||||
ecma_collection_t *lit_pool_p) /**< list of known values */
|
||||
{
|
||||
ecma_value_t *literal_p;
|
||||
uint32_t argument_end;
|
||||
uint32_t register_end;
|
||||
uint32_t const_literal_end;
|
||||
uint32_t literal_end;
|
||||
|
||||
JERRY_ASSERT (CBC_IS_FUNCTION (compiled_code_p->status_flags));
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
{
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p;
|
||||
uint8_t *byte_p = (uint8_t *) compiled_code_p;
|
||||
|
||||
literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint16_arguments_t));
|
||||
register_end = args_p->register_end;
|
||||
const_literal_end = args_p->const_literal_end - register_end;
|
||||
literal_end = args_p->literal_end - register_end;
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p;
|
||||
uint8_t *byte_p = (uint8_t *) compiled_code_p;
|
||||
|
||||
literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint8_arguments_t));
|
||||
register_end = args_p->register_end;
|
||||
const_literal_end = args_p->const_literal_end - register_end;
|
||||
literal_end = args_p->literal_end - register_end;
|
||||
argument_end = args_p->argument_end;
|
||||
}
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
for (uint32_t i = 0; i < argument_end; i++)
|
||||
{
|
||||
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < const_literal_end; i++)
|
||||
{
|
||||
ecma_save_literals_append_value (literal_p[i], lit_pool_p);
|
||||
}
|
||||
|
||||
for (uint32_t i = const_literal_end; i < literal_end; i++)
|
||||
{
|
||||
ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, literal_p[i]);
|
||||
|
||||
if (CBC_IS_FUNCTION (bytecode_p->status_flags) && bytecode_p != compiled_code_p)
|
||||
{
|
||||
ecma_save_literals_add_compiled_code (bytecode_p, lit_pool_p);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *byte_p = ((uint8_t *) compiled_code_p) + (((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG);
|
||||
literal_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) compiled_code_p, byte_p);
|
||||
|
||||
while (literal_p < (ecma_value_t *) byte_p)
|
||||
{
|
||||
ecma_save_literals_append_value (*literal_p, lit_pool_p);
|
||||
literal_p++;
|
||||
}
|
||||
} /* ecma_save_literals_add_compiled_code */
|
||||
|
||||
/**
|
||||
* Save literals to specified snapshot buffer.
|
||||
*
|
||||
* Note:
|
||||
* Frees 'lit_pool_p' regardless of success.
|
||||
*
|
||||
* @return true - if save was performed successfully (i.e. buffer size is sufficient),
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, /**< list of known values */
|
||||
uint32_t *buffer_p, /**< [out] output snapshot buffer */
|
||||
size_t buffer_size, /**< size of the buffer */
|
||||
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
|
||||
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal identifiers
|
||||
* to the literal offsets
|
||||
* in snapshot */
|
||||
uint32_t *out_map_len_p) /**< [out] number of literals */
|
||||
{
|
||||
if (lit_pool_p->item_count == 0)
|
||||
{
|
||||
*out_map_p = NULL;
|
||||
*out_map_len_p = 0;
|
||||
}
|
||||
|
||||
uint32_t lit_table_size = 0;
|
||||
size_t max_lit_table_size = buffer_size - *in_out_buffer_offset_p;
|
||||
|
||||
if (max_lit_table_size > (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT))
|
||||
{
|
||||
max_lit_table_size = (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT);
|
||||
}
|
||||
|
||||
ecma_value_t *lit_buffer_p = lit_pool_p->buffer_p;
|
||||
|
||||
/* Compute the size of the literal pool. */
|
||||
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||
{
|
||||
if (ecma_is_value_float_number (lit_buffer_p[i]))
|
||||
{
|
||||
lit_table_size += (uint32_t) sizeof (ecma_number_t);
|
||||
}
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
else if (ecma_is_value_bigint (lit_buffer_p[i]))
|
||||
{
|
||||
ecma_extended_primitive_t *bigint_p = ecma_get_extended_primitive_from_value (lit_buffer_p[i]);
|
||||
|
||||
lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint32_t) + ECMA_BIGINT_GET_SIZE (bigint_p),
|
||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
}
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
else
|
||||
{
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (lit_buffer_p[i]);
|
||||
|
||||
lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint16_t) + ecma_string_get_size (string_p),
|
||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
}
|
||||
|
||||
/* Check whether enough space is available and the maximum size is not reached. */
|
||||
if (lit_table_size > max_lit_table_size)
|
||||
{
|
||||
ecma_collection_destroy (lit_pool_p);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
lit_mem_to_snapshot_id_map_entry_t *map_p;
|
||||
uint32_t total_count = lit_pool_p->item_count;
|
||||
|
||||
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
||||
|
||||
/* Set return values (no error is possible from here). */
|
||||
JERRY_ASSERT ((*in_out_buffer_offset_p % sizeof (uint32_t)) == 0);
|
||||
|
||||
uint8_t *destination_p = (uint8_t *) (buffer_p + (*in_out_buffer_offset_p / sizeof (uint32_t)));
|
||||
uint32_t literal_offset = 0;
|
||||
|
||||
*in_out_buffer_offset_p += lit_table_size;
|
||||
*out_map_p = map_p;
|
||||
*out_map_len_p = total_count;
|
||||
|
||||
lit_buffer_p = lit_pool_p->buffer_p;
|
||||
|
||||
/* Generate literal pool data. */
|
||||
for (uint32_t i = 0; i < lit_pool_p->item_count; i++)
|
||||
{
|
||||
map_p->literal_id = lit_buffer_p[i];
|
||||
map_p->literal_offset = (literal_offset << JERRY_SNAPSHOT_LITERAL_SHIFT) | ECMA_TYPE_SNAPSHOT_OFFSET;
|
||||
|
||||
lit_utf8_size_t length;
|
||||
|
||||
if (ecma_is_value_float_number (lit_buffer_p[i]))
|
||||
{
|
||||
map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_NUMBER;
|
||||
|
||||
ecma_number_t num = ecma_get_float_from_value (lit_buffer_p[i]);
|
||||
memcpy (destination_p, &num, sizeof (ecma_number_t));
|
||||
|
||||
length = JERRY_ALIGNUP (sizeof (ecma_number_t), JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
}
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
else if (ecma_is_value_bigint (lit_buffer_p[i]))
|
||||
{
|
||||
map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_BIGINT;
|
||||
|
||||
ecma_extended_primitive_t *bigint_p = ecma_get_extended_primitive_from_value (lit_buffer_p[i]);
|
||||
uint32_t size = ECMA_BIGINT_GET_SIZE (bigint_p);
|
||||
|
||||
memcpy (destination_p, &bigint_p->u.bigint_sign_and_size, sizeof (uint32_t));
|
||||
memcpy (destination_p + sizeof (uint32_t), ECMA_BIGINT_GET_DIGITS (bigint_p, 0), size);
|
||||
|
||||
length = JERRY_ALIGNUP (sizeof (uint32_t) + size, JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
}
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
else
|
||||
{
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (lit_buffer_p[i]);
|
||||
length = ecma_string_get_size (string_p);
|
||||
|
||||
*(uint16_t *) destination_p = (uint16_t) length;
|
||||
|
||||
ecma_string_to_cesu8_bytes (string_p, destination_p + sizeof (uint16_t), length);
|
||||
|
||||
length = JERRY_ALIGNUP (sizeof (uint16_t) + length, JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
}
|
||||
|
||||
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||
destination_p += length;
|
||||
literal_offset += length;
|
||||
|
||||
map_p++;
|
||||
}
|
||||
|
||||
ecma_collection_destroy (lit_pool_p);
|
||||
return true;
|
||||
} /* ecma_save_literals_for_snapshot */
|
||||
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
|
||||
#if JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE
|
||||
|
||||
/**
|
||||
* Get the compressed pointer of a given literal.
|
||||
*
|
||||
* @return literal compressed pointer
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
|
||||
ecma_value_t literal_value) /**< string / number offset */
|
||||
{
|
||||
JERRY_ASSERT ((literal_value & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET);
|
||||
|
||||
const uint8_t *literal_p = literal_base_p + (literal_value >> JERRY_SNAPSHOT_LITERAL_SHIFT);
|
||||
|
||||
if (literal_value & JERRY_SNAPSHOT_LITERAL_IS_NUMBER)
|
||||
{
|
||||
ecma_number_t num;
|
||||
memcpy (&num, literal_p, sizeof (ecma_number_t));
|
||||
return ecma_find_or_create_literal_number (num);
|
||||
}
|
||||
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
if (literal_value & JERRY_SNAPSHOT_LITERAL_IS_BIGINT)
|
||||
{
|
||||
uint32_t bigint_sign_and_size = *(uint32_t *) literal_p;
|
||||
uint32_t size = bigint_sign_and_size & ~(uint32_t) (sizeof (ecma_bigint_digit_t) - 1);
|
||||
|
||||
ecma_extended_primitive_t *bigint_p = ecma_bigint_create (size);
|
||||
|
||||
if (bigint_p == NULL)
|
||||
{
|
||||
jerry_fatal (JERRY_FATAL_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
/* Only the sign bit can differ. */
|
||||
JERRY_ASSERT (bigint_p->u.bigint_sign_and_size == (bigint_sign_and_size & ~(uint32_t) ECMA_BIGINT_SIGN));
|
||||
|
||||
bigint_p->u.bigint_sign_and_size = bigint_sign_and_size;
|
||||
memcpy (ECMA_BIGINT_GET_DIGITS (bigint_p, 0), literal_p + sizeof (uint32_t), size);
|
||||
return ecma_find_or_create_literal_bigint (ecma_make_extended_primitive_value (bigint_p, ECMA_TYPE_BIGINT));
|
||||
}
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
uint16_t length = *(const uint16_t *) literal_p;
|
||||
|
||||
return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t), length, false);
|
||||
} /* ecma_snapshot_get_literal */
|
||||
|
||||
/**
|
||||
* Compute the start of the serializable ecma-values of the bytecode
|
||||
* Related values:
|
||||
* - function argument names, if CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED is present
|
||||
* - function name, if CBC_CODE_FLAGS_CLASS_CONSTRUCTOR is not present and es.next profile is enabled
|
||||
*
|
||||
* @return pointer to the beginning of the serializable ecma-values
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_snapshot_resolve_serializable_values (const ecma_compiled_code_t *compiled_code_p, /**< compiled code */
|
||||
uint8_t *bytecode_end_p) /**< end of the bytecode */
|
||||
{
|
||||
ecma_value_t *base_p = (ecma_value_t *) bytecode_end_p;
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
|
||||
{
|
||||
uint32_t argument_end;
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
{
|
||||
argument_end = ((cbc_uint16_arguments_t *) compiled_code_p)->argument_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
argument_end = ((cbc_uint8_arguments_t *) compiled_code_p)->argument_end;
|
||||
}
|
||||
|
||||
base_p -= argument_end;
|
||||
}
|
||||
|
||||
/* function name */
|
||||
if (CBC_FUNCTION_GET_TYPE (compiled_code_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR)
|
||||
{
|
||||
base_p--;
|
||||
}
|
||||
|
||||
return base_p;
|
||||
} /* ecma_snapshot_resolve_serializable_values */
|
||||
#endif /* JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_LIT_STORAGE_H
|
||||
#define ECMA_LIT_STORAGE_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#include "jmem.h"
|
||||
#include "lit-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmalitstorage Literal storage
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
/**
|
||||
* Snapshot literal - offset map
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_value_t literal_id; /**< literal id */
|
||||
ecma_value_t literal_offset; /**< literal offset */
|
||||
} lit_mem_to_snapshot_id_map_entry_t;
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
|
||||
void ecma_finalize_lit_storage (void);
|
||||
|
||||
ecma_value_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, lit_utf8_size_t size, bool is_ascii);
|
||||
ecma_value_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ecma_value_t ecma_find_or_create_literal_bigint (ecma_value_t bigint);
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
void ecma_save_literals_append_value (ecma_value_t value, ecma_collection_t *lit_pool_p);
|
||||
void ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, ecma_collection_t *lit_pool_p);
|
||||
bool ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p,
|
||||
uint32_t *buffer_p,
|
||||
size_t buffer_size,
|
||||
size_t *in_out_buffer_offset_p,
|
||||
lit_mem_to_snapshot_id_map_entry_t **out_map_p,
|
||||
uint32_t *out_map_len_p);
|
||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||
|
||||
#if JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE
|
||||
ecma_value_t ecma_snapshot_get_literal (const uint8_t *literal_base_p, ecma_value_t literal_value);
|
||||
ecma_value_t *ecma_snapshot_resolve_serializable_values (const ecma_compiled_code_t *compiled_code_p,
|
||||
uint8_t *byte_code_end_p);
|
||||
#endif /* JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_LIT_STORAGE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,132 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_MODULE_H
|
||||
#define ECMA_MODULE_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
|
||||
#define ECMA_MODULE_MAX_PATH 255u
|
||||
|
||||
/**
|
||||
* Module status flags.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_MODULE_IS_NATIVE = (1 << 0), /**< native module */
|
||||
ECMA_MODULE_HAS_NAMESPACE = (1 << 1), /**< namespace object has been initialized */
|
||||
} ecma_module_flags_t;
|
||||
|
||||
/**
|
||||
* Imported or exported names, such as "a as b"
|
||||
* Note: See https://www.ecma-international.org/ecma-262/6.0/#table-39
|
||||
* and https://www.ecma-international.org/ecma-262/6.0/#table-41
|
||||
*/
|
||||
typedef struct ecma_module_names
|
||||
{
|
||||
struct ecma_module_names *next_p; /**< next linked list node */
|
||||
ecma_string_t *imex_name_p; /**< Import/export name of the item */
|
||||
ecma_string_t *local_name_p; /**< Local name of the item */
|
||||
} ecma_module_names_t;
|
||||
|
||||
/**
|
||||
* Module structure storing an instance of a module
|
||||
*
|
||||
* Note:
|
||||
* The imports_p list follows the order of import-from/export-from statements in the source
|
||||
* code of a module, even if a given module specifier is only used by export-from statements.
|
||||
*/
|
||||
typedef struct ecma_module
|
||||
{
|
||||
/* Note: state is stored in header.u.class_prop.extra_info */
|
||||
ecma_extended_object_t header; /**< header part */
|
||||
/* TODO(dbatyai): These could be compressed pointers */
|
||||
ecma_object_t *scope_p; /**< lexical environment of the module */
|
||||
ecma_object_t *namespace_object_p; /**< namespace object of the module */
|
||||
struct ecma_module_node *imports_p; /**< import requests of the module */
|
||||
ecma_module_names_t *local_exports_p; /**< local exports of the module */
|
||||
struct ecma_module_node *indirect_exports_p; /**< indirect exports of the module */
|
||||
struct ecma_module_node *star_exports_p; /**< star exports of the module */
|
||||
|
||||
/* Code used for evaluating a module */
|
||||
union
|
||||
{
|
||||
ecma_compiled_code_t *compiled_code_p; /**< compiled code for the module */
|
||||
jerry_native_module_evaluate_cb_t callback; /**< callback for evaluating native modules */
|
||||
} u;
|
||||
} ecma_module_t;
|
||||
|
||||
/**
|
||||
* Module node to store imports / exports.
|
||||
*
|
||||
* Note:
|
||||
* Only one module node is created for each module specifier: the names are
|
||||
* concatenated if the same specifier is used multiple times in the source code.
|
||||
* However, multiple nodes are created for modules with multiple alias
|
||||
* (for example ./a.mjs and ././a.mjs can refer to the same module).
|
||||
*/
|
||||
typedef struct ecma_module_node
|
||||
{
|
||||
struct ecma_module_node *next_p; /**< next linked list node */
|
||||
ecma_module_names_t *module_names_p; /**< names of the requested import/export node */
|
||||
|
||||
union
|
||||
{
|
||||
ecma_value_t path_or_module; /**< imports: module specifier (if string) or module reference (if object) */
|
||||
ecma_value_t *module_object_p; /**< non-imports: reference to a path_or_module field in the imports */
|
||||
} u;
|
||||
} ecma_module_node_t;
|
||||
|
||||
/**
|
||||
* A list of module records that can be used to identify circular imports during resolution
|
||||
*/
|
||||
typedef struct ecma_module_resolve_set
|
||||
{
|
||||
struct ecma_module_resolve_set *next_p; /**< next in linked list */
|
||||
ecma_module_t *module_p; /**< module */
|
||||
ecma_string_t *name_p; /**< identifier name */
|
||||
} ecma_module_resolve_set_t;
|
||||
|
||||
/**
|
||||
* A list that is used like a stack to drive the resolution process, instead of recursion.
|
||||
*/
|
||||
typedef struct ecma_module_resolve_stack
|
||||
{
|
||||
struct ecma_module_resolve_stack *next_p; /**< next in linked list */
|
||||
ecma_module_t *module_p; /**< module request */
|
||||
ecma_string_t *export_name_p; /**< export identifier name */
|
||||
bool resolving; /**< flag storing whether the current frame started resolving */
|
||||
} ecma_module_resolve_stack_t;
|
||||
|
||||
ecma_value_t ecma_module_initialize (ecma_module_t *module_p);
|
||||
ecma_module_t *ecma_module_get_resolved_module (ecma_value_t module_val);
|
||||
|
||||
ecma_value_t ecma_module_link (ecma_module_t *module_p, jerry_module_resolve_cb_t callback_p, void *user_p);
|
||||
ecma_value_t ecma_module_evaluate (ecma_module_t *module_p);
|
||||
ecma_value_t ecma_module_import (ecma_value_t specifier, ecma_value_t user_value);
|
||||
|
||||
ecma_module_t *ecma_module_create (void);
|
||||
void ecma_module_cleanup_context (void);
|
||||
|
||||
void ecma_module_release_module_names (ecma_module_names_t *module_name_p);
|
||||
void ecma_module_release_module (ecma_module_t *module_p);
|
||||
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
|
||||
#endif /* !ECMA_MODULE_H */
|
||||
@@ -0,0 +1,532 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-property-hashmap.h"
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "jcontext.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmapropertyhashmap Property hashmap
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if JERRY_PROPERTY_HASHMAP
|
||||
|
||||
/**
|
||||
* Compute the total size of the property hashmap.
|
||||
*/
|
||||
#define ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE(max_property_count) \
|
||||
(sizeof (ecma_property_hashmap_t) + (max_property_count * sizeof (jmem_cpointer_t)) + (max_property_count >> 3))
|
||||
|
||||
/**
|
||||
* Number of items in the stepping table.
|
||||
*/
|
||||
#define ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS 8
|
||||
|
||||
/**
|
||||
* Stepping values for searching items in the hashmap.
|
||||
*/
|
||||
static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS] JERRY_ATTR_CONST_DATA = {
|
||||
3, 5, 7, 11, 13, 17, 19, 23
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the value of a bit in a bitmap.
|
||||
*/
|
||||
#define ECMA_PROPERTY_HASHMAP_GET_BIT(byte_p, index) ((byte_p)[(index) >> 3] & (1 << ((index) &0x7)))
|
||||
|
||||
/**
|
||||
* Clear the value of a bit in a bitmap.
|
||||
*/
|
||||
#define ECMA_PROPERTY_HASHMAP_CLEAR_BIT(byte_p, index) \
|
||||
((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] & ~(1 << ((index) &0x7))))
|
||||
|
||||
/**
|
||||
* Set the value of a bit in a bitmap.
|
||||
*/
|
||||
#define ECMA_PROPERTY_HASHMAP_SET_BIT(byte_p, index) \
|
||||
((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] | (1 << ((index) &0x7))))
|
||||
|
||||
/**
|
||||
* Create a new property hashmap for the object.
|
||||
* The object must not have a property hashmap.
|
||||
*/
|
||||
void
|
||||
ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) != ECMA_PROP_HASHMAP_ALLOC_ON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp;
|
||||
|
||||
if (prop_iter_cp == JMEM_CP_NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t named_property_count = 0;
|
||||
|
||||
while (prop_iter_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||
|
||||
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||
{
|
||||
if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
|
||||
{
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i]));
|
||||
named_property_count++;
|
||||
}
|
||||
}
|
||||
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||
}
|
||||
|
||||
if (named_property_count < (ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE / 2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* The max_property_count must be power of 2. */
|
||||
uint32_t max_property_count = ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE;
|
||||
|
||||
/* At least 1/3 items must be NULL. */
|
||||
while (max_property_count < (named_property_count + (named_property_count >> 1)))
|
||||
{
|
||||
max_property_count <<= 1;
|
||||
}
|
||||
|
||||
size_t total_size = ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (max_property_count);
|
||||
|
||||
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) jmem_heap_alloc_block_null_on_error (total_size);
|
||||
|
||||
if (hashmap_p == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset (hashmap_p, 0, total_size);
|
||||
|
||||
hashmap_p->header.types[0] = ECMA_PROPERTY_TYPE_HASHMAP;
|
||||
hashmap_p->header.next_property_cp = object_p->u1.property_list_cp;
|
||||
hashmap_p->max_property_count = max_property_count;
|
||||
hashmap_p->null_count = max_property_count - named_property_count;
|
||||
hashmap_p->unused_count = max_property_count - named_property_count;
|
||||
|
||||
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + max_property_count);
|
||||
uint32_t mask = max_property_count - 1;
|
||||
|
||||
prop_iter_cp = object_p->u1.property_list_cp;
|
||||
ECMA_SET_NON_NULL_POINTER (object_p->u1.property_list_cp, hashmap_p);
|
||||
|
||||
while (prop_iter_cp != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||
|
||||
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||
{
|
||||
if (prop_iter_p->types[i] == ECMA_PROPERTY_TYPE_DELETED)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i]));
|
||||
|
||||
ecma_property_pair_t *property_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
||||
|
||||
uint32_t entry_index = ecma_string_get_property_name_hash (prop_iter_p->types[i], property_pair_p->names_cp[i]);
|
||||
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
||||
|
||||
entry_index &= mask;
|
||||
#ifndef JERRY_NDEBUG
|
||||
/* Because max_property_count (power of 2) and step (a prime
|
||||
* number) are relative primes, all entries of the hashmap are
|
||||
* visited exactly once before the start entry index is reached
|
||||
* again. Furthermore because at least one NULL is present in
|
||||
* the hashmap, the while loop must be terminated before the
|
||||
* the starting index is reached again. */
|
||||
uint32_t start_entry_index = entry_index;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
while (pair_list_p[entry_index] != ECMA_NULL_POINTER)
|
||||
{
|
||||
entry_index = (entry_index + step) & mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (entry_index != start_entry_index);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
}
|
||||
|
||||
ECMA_SET_NON_NULL_POINTER (pair_list_p[entry_index], property_pair_p);
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
ECMA_PROPERTY_HASHMAP_SET_BIT (bits_p, entry_index);
|
||||
}
|
||||
}
|
||||
|
||||
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||
}
|
||||
} /* ecma_property_hashmap_create */
|
||||
|
||||
/**
|
||||
* Free the hashmap of the object.
|
||||
* The object must have a property hashmap.
|
||||
*/
|
||||
void
|
||||
ecma_property_hashmap_free (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
/* Property hash must be exists and must be the first property. */
|
||||
JERRY_ASSERT (object_p->u1.property_list_cp != JMEM_CP_NULL);
|
||||
|
||||
ecma_property_header_t *property_p =
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, object_p->u1.property_list_cp);
|
||||
|
||||
JERRY_ASSERT (property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
||||
|
||||
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) property_p;
|
||||
|
||||
object_p->u1.property_list_cp = property_p->next_property_cp;
|
||||
|
||||
jmem_heap_free_block (hashmap_p, ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (hashmap_p->max_property_count));
|
||||
} /* ecma_property_hashmap_free */
|
||||
|
||||
/**
|
||||
* Insert named property into the hashmap.
|
||||
*/
|
||||
void
|
||||
ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
|
||||
ecma_string_t *name_p, /**< name of the property */
|
||||
ecma_property_pair_t *property_pair_p, /**< property pair */
|
||||
int property_index) /**< property index in the pair (0 or 1) */
|
||||
{
|
||||
JERRY_ASSERT (property_pair_p != NULL);
|
||||
|
||||
ecma_property_hashmap_t *hashmap_p =
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t, object_p->u1.property_list_cp);
|
||||
|
||||
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
||||
|
||||
/* The NULLs are reduced below 1/8 of the hashmap. */
|
||||
if (hashmap_p->null_count < (hashmap_p->max_property_count >> 3))
|
||||
{
|
||||
ecma_property_hashmap_free (object_p);
|
||||
ecma_property_hashmap_create (object_p);
|
||||
return;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (property_index < ECMA_PROPERTY_PAIR_ITEM_COUNT);
|
||||
|
||||
uint32_t entry_index = ecma_string_hash (name_p);
|
||||
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
||||
uint32_t mask = hashmap_p->max_property_count - 1;
|
||||
entry_index &= mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
/* See the comment for this variable in ecma_property_hashmap_create. */
|
||||
uint32_t start_entry_index = entry_index;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
||||
|
||||
while (pair_list_p[entry_index] != ECMA_NULL_POINTER)
|
||||
{
|
||||
entry_index = (entry_index + step) & mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (entry_index != start_entry_index);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
}
|
||||
|
||||
ECMA_SET_NON_NULL_POINTER (pair_list_p[entry_index], property_pair_p);
|
||||
|
||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
||||
bits_p += (entry_index >> 3);
|
||||
mask = (uint32_t) (1 << (entry_index & 0x7));
|
||||
|
||||
if (!(*bits_p & mask))
|
||||
{
|
||||
/* Deleted entries also has ECMA_NULL_POINTER
|
||||
* value, but they are not NULL values. */
|
||||
hashmap_p->null_count--;
|
||||
JERRY_ASSERT (hashmap_p->null_count > 0);
|
||||
}
|
||||
|
||||
hashmap_p->unused_count--;
|
||||
JERRY_ASSERT (hashmap_p->unused_count > 0);
|
||||
|
||||
if (property_index == 0)
|
||||
{
|
||||
*bits_p = (uint8_t) ((*bits_p) & ~mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
*bits_p = (uint8_t) ((*bits_p) | mask);
|
||||
}
|
||||
} /* ecma_property_hashmap_insert */
|
||||
|
||||
/**
|
||||
* Delete named property from the hashmap.
|
||||
*
|
||||
* @return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP if hashmap should be recreated
|
||||
* ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP otherwise
|
||||
*/
|
||||
ecma_property_hashmap_delete_status
|
||||
ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
|
||||
jmem_cpointer_t name_cp, /**< property name */
|
||||
ecma_property_t *property_p) /**< property */
|
||||
{
|
||||
ecma_property_hashmap_t *hashmap_p =
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t, object_p->u1.property_list_cp);
|
||||
|
||||
JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP);
|
||||
|
||||
hashmap_p->unused_count++;
|
||||
|
||||
/* The NULLs are above 3/4 of the hashmap. */
|
||||
if (hashmap_p->unused_count > ((hashmap_p->max_property_count * 3) >> 2))
|
||||
{
|
||||
return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP;
|
||||
}
|
||||
|
||||
uint32_t entry_index = ecma_string_get_property_name_hash (*property_p, name_cp);
|
||||
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
||||
uint32_t mask = hashmap_p->max_property_count - 1;
|
||||
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
||||
|
||||
entry_index &= mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
/* See the comment for this variable in ecma_property_hashmap_create. */
|
||||
uint32_t start_entry_index = entry_index;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (pair_list_p[entry_index] != ECMA_NULL_POINTER)
|
||||
{
|
||||
size_t offset = 0;
|
||||
|
||||
if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
|
||||
{
|
||||
offset = 1;
|
||||
}
|
||||
|
||||
ecma_property_pair_t *property_pair_p =
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t, pair_list_p[entry_index]);
|
||||
|
||||
if ((property_pair_p->header.types + offset) == property_p)
|
||||
{
|
||||
JERRY_ASSERT (property_pair_p->names_cp[offset] == name_cp);
|
||||
|
||||
pair_list_p[entry_index] = ECMA_NULL_POINTER;
|
||||
ECMA_PROPERTY_HASHMAP_SET_BIT (bits_p, entry_index);
|
||||
return ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Must be a deleted entry. */
|
||||
JERRY_ASSERT (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index));
|
||||
}
|
||||
|
||||
entry_index = (entry_index + step) & mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (entry_index != start_entry_index);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
}
|
||||
} /* ecma_property_hashmap_delete */
|
||||
|
||||
/**
|
||||
* Find a named property.
|
||||
*
|
||||
* @return pointer to the property if found or NULL otherwise
|
||||
*/
|
||||
ecma_property_t *
|
||||
ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
|
||||
ecma_string_t *name_p, /**< property name */
|
||||
jmem_cpointer_t *property_real_name_cp) /**< [out] property real name */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
/* A sanity check in debug mode: a named property must be present
|
||||
* in both the property hashmap and in the property chain, or missing
|
||||
* from both data collection. The following code checks the property
|
||||
* chain, and sets the property_found variable. */
|
||||
bool property_found = false;
|
||||
|
||||
jmem_cpointer_t prop_iter_cp = hashmap_p->header.next_property_cp;
|
||||
|
||||
while (prop_iter_cp != JMEM_CP_NULL && !property_found)
|
||||
{
|
||||
ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
|
||||
|
||||
ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
|
||||
|
||||
for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++)
|
||||
{
|
||||
if (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i]))
|
||||
{
|
||||
if (ecma_string_compare_to_property_name (prop_iter_p->types[i], prop_pair_p->names_cp[i], name_p))
|
||||
{
|
||||
/* Property is found */
|
||||
property_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prop_iter_cp = prop_iter_p->next_property_cp;
|
||||
}
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
uint32_t entry_index = ecma_string_hash (name_p);
|
||||
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
|
||||
uint32_t mask = hashmap_p->max_property_count - 1;
|
||||
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
|
||||
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);
|
||||
entry_index &= mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
/* See the comment for this variable in ecma_property_hashmap_create. */
|
||||
uint32_t start_entry_index = entry_index;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
if (ECMA_IS_DIRECT_STRING (name_p))
|
||||
{
|
||||
ecma_property_t prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (name_p);
|
||||
jmem_cpointer_t property_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (name_p);
|
||||
|
||||
JERRY_ASSERT (prop_name_type > 0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (pair_list_p[entry_index] != ECMA_NULL_POINTER)
|
||||
{
|
||||
size_t offset = 0;
|
||||
if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
|
||||
{
|
||||
offset = 1;
|
||||
}
|
||||
|
||||
ecma_property_pair_t *property_pair_p =
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t, pair_list_p[entry_index]);
|
||||
|
||||
ecma_property_t *property_p = property_pair_p->header.types + offset;
|
||||
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p));
|
||||
|
||||
if (property_pair_p->names_cp[offset] == property_name_cp
|
||||
&& ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == prop_name_type)
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (property_found);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
*property_real_name_cp = property_name_cp;
|
||||
return property_p;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (!property_found);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* Otherwise it is a deleted entry. */
|
||||
}
|
||||
|
||||
entry_index = (entry_index + step) & mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (entry_index != start_entry_index);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
}
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (pair_list_p[entry_index] != ECMA_NULL_POINTER)
|
||||
{
|
||||
size_t offset = 0;
|
||||
if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
|
||||
{
|
||||
offset = 1;
|
||||
}
|
||||
|
||||
ecma_property_pair_t *property_pair_p =
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t, pair_list_p[entry_index]);
|
||||
|
||||
ecma_property_t *property_p = property_pair_p->header.types + offset;
|
||||
|
||||
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p));
|
||||
|
||||
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_PTR)
|
||||
{
|
||||
ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, property_pair_p->names_cp[offset]);
|
||||
|
||||
if (ecma_compare_ecma_non_direct_strings (prop_name_p, name_p))
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (property_found);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
*property_real_name_cp = property_pair_p->names_cp[offset];
|
||||
return property_p;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index))
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (!property_found);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* Otherwise it is a deleted entry. */
|
||||
}
|
||||
|
||||
entry_index = (entry_index + step) & mask;
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
JERRY_ASSERT (entry_index != start_entry_index);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
}
|
||||
} /* ecma_property_hashmap_find */
|
||||
#endif /* JERRY_PROPERTY_HASHMAP */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,89 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_PROPERTY_HASHMAP_H
|
||||
#define ECMA_PROPERTY_HASHMAP_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmapropertyhashmap Property hashmap
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Recommended minimum number of items in a property cache.
|
||||
*/
|
||||
#define ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE 32
|
||||
|
||||
/**
|
||||
* Property hash.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_property_header_t header; /**< header of the property */
|
||||
uint32_t max_property_count; /**< maximum property count (power of 2) */
|
||||
uint32_t null_count; /**< number of NULLs in the map */
|
||||
uint32_t unused_count; /**< number of unused entries in the map */
|
||||
|
||||
/*
|
||||
* The hash is followed by max_property_count ecma_cpointer_t
|
||||
* compressed pointers and (max_property_count + 7) / 8 bytes
|
||||
* which stores a flag for each compressed pointer.
|
||||
*
|
||||
* If the compressed pointer is equal to ECMA_NULL_POINTER
|
||||
* - flag is cleared if the entry is NULL
|
||||
* - flag is set if the entry is deleted
|
||||
*
|
||||
* If the compressed pointer is not equal to ECMA_NULL_POINTER
|
||||
* - flag is cleared if the first entry of a property pair is referenced
|
||||
* - flag is set if the second entry of a property pair is referenced
|
||||
*/
|
||||
} ecma_property_hashmap_t;
|
||||
|
||||
#if JERRY_PROPERTY_HASHMAP
|
||||
|
||||
/**
|
||||
* Simple ecma values
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP, /**< object has no hashmap */
|
||||
ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP, /**< object has hashmap */
|
||||
ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP, /**< hashmap should be recreated */
|
||||
} ecma_property_hashmap_delete_status;
|
||||
|
||||
void ecma_property_hashmap_create (ecma_object_t *object_p);
|
||||
void ecma_property_hashmap_free (ecma_object_t *object_p);
|
||||
void ecma_property_hashmap_insert (ecma_object_t *object_p,
|
||||
ecma_string_t *name_p,
|
||||
ecma_property_pair_t *property_pair_p,
|
||||
int property_index);
|
||||
ecma_property_hashmap_delete_status
|
||||
ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p);
|
||||
|
||||
ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p,
|
||||
ecma_string_t *name_p,
|
||||
jmem_cpointer_t *property_real_name_cp);
|
||||
#endif /* JERRY_PROPERTY_HASHMAP */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_PROPERTY_HASHMAP_H */
|
||||
@@ -0,0 +1,37 @@
|
||||
source_file = [
|
||||
'ecma-alloc.h',
|
||||
'ecma-error-messages.inc.h',
|
||||
'ecma-errors.h',
|
||||
'ecma-extended-info.h',
|
||||
'ecma-gc.h',
|
||||
'ecma-globals.h',
|
||||
'ecma-helpers-number.h',
|
||||
'ecma-helpers.h',
|
||||
'ecma-init-finalize.h',
|
||||
'ecma-lcache.h',
|
||||
'ecma-literal-storage.h',
|
||||
'ecma-module.h',
|
||||
'ecma-property-hashmap.h',
|
||||
'ecma-alloc.cpp',
|
||||
'ecma-errors.cpp',
|
||||
'ecma-extended-info.cpp',
|
||||
'ecma-gc.cpp',
|
||||
'ecma-helpers-collection.cpp',
|
||||
'ecma-helpers-conversion.cpp',
|
||||
'ecma-helpers-errol.cpp',
|
||||
'ecma-helpers-external-pointers.cpp',
|
||||
'ecma-helpers-number.cpp',
|
||||
'ecma-helpers-string.cpp',
|
||||
'ecma-helpers-value.cpp',
|
||||
'ecma-helpers.cpp',
|
||||
'ecma-init-finalize.cpp',
|
||||
'ecma-lcache.cpp',
|
||||
'ecma-literal-storage.cpp',
|
||||
'ecma-module.cpp',
|
||||
'ecma-property-hashmap.cpp'
|
||||
]
|
||||
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
sources : source_file
|
||||
)]
|
||||
@@ -0,0 +1,33 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-aggregateerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID aggregate_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
@@ -0,0 +1,31 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* AggregateError.prototype built-in description
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.7.9 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* ECMA-262 v5, 15.11.7.10 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
@@ -0,0 +1,80 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-iterator-object.h"
|
||||
#include "ecma-objects.h"
|
||||
|
||||
#include "jcontext.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-aggregateerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID aggregate_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup aggregateerror ECMA AggregateError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in AggregateError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_aggregate_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
uint32_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
ecma_value_t message_val = ECMA_VALUE_UNDEFINED;
|
||||
ecma_value_t error_val = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
if (arguments_list_len > 0)
|
||||
{
|
||||
error_val = arguments_list_p[0];
|
||||
|
||||
if (arguments_list_len > 1)
|
||||
{
|
||||
message_val = arguments_list_p[1];
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_new_aggregate_error (error_val, message_val);
|
||||
} /* ecma_builtin_aggregate_error_dispatch_call */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* AggregateError built-in description
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers-macro-defines.inc.h"
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 2, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
/* ECMA-262 v5, 15.11.3.1 */
|
||||
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||
|
||||
#include "ecma-builtin-helpers-macro-undefs.inc.h"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user