mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-27 13:27:24 +00:00
android support
This commit is contained in:
19
.idea/libraries/Dart_SDK.xml
generated
19
.idea/libraries/Dart_SDK.xml
generated
@@ -1,19 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Dart SDK">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/async" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/collection" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/convert" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/core" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/developer" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/html" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/io" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/isolate" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/math" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/mirrors" />
|
|
||||||
<root url="file://D:\flutter/bin/cache/dart-sdk/lib/typed_data" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</component>
|
|
10
.idea/modules.xml
generated
10
.idea/modules.xml
generated
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/flutter_qjs.iml" filepath="$PROJECT_DIR$/flutter_qjs.iml" />
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/android/flutter_qjs_android.iml" filepath="$PROJECT_DIR$/android/flutter_qjs_android.iml" />
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/example/android/flutter_qjs_example_android.iml" filepath="$PROJECT_DIR$/example/android/flutter_qjs_example_android.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@@ -1,6 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="example/lib/main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
|
|
||||||
<option name="filePath" value="$PROJECT_DIR$/example/lib/main.dart" />
|
|
||||||
<method />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
45
.idea/workspace.xml
generated
45
.idea/workspace.xml
generated
@@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="FileEditorManager">
|
|
||||||
<leaf>
|
|
||||||
<file leaf-file-name="flutter_qjs.dart" pinned="false" current-in-tab="true">
|
|
||||||
<entry file="file://$PROJECT_DIR$/lib/flutter_qjs.dart">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="0">
|
|
||||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
</file>
|
|
||||||
<file leaf-file-name="main.dart" pinned="false" current-in-tab="false">
|
|
||||||
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="0">
|
|
||||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
</file>
|
|
||||||
</leaf>
|
|
||||||
</component>
|
|
||||||
<component name="ToolWindowManager">
|
|
||||||
<editor active="true" />
|
|
||||||
<layout>
|
|
||||||
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
|
||||||
</layout>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectView">
|
|
||||||
<navigator currentView="ProjectPane" proportions="" version="1">
|
|
||||||
</navigator>
|
|
||||||
<panes>
|
|
||||||
<pane id="ProjectPane">
|
|
||||||
<option name="show-excluded-files" value="false" />
|
|
||||||
</pane>
|
|
||||||
</panes>
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent">
|
|
||||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
|
||||||
<property name="dart.analysis.tool.window.force.activate" value="true" />
|
|
||||||
<property name="show.migrate.to.gradle.popup" value="false" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
22
.vscode/c_cpp_properties.json
vendored
Normal file
22
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"C:\\Users\\ekibun\\AppData\\Local\\Android\\Sdk\\ndk\\21.3.6528147\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\include"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"_DEBUG",
|
||||||
|
"UNICODE",
|
||||||
|
"_UNICODE"
|
||||||
|
],
|
||||||
|
"windowsSdkVersion": "10.0.18362.0",
|
||||||
|
"compilerPath": "C:\\Users\\ekibun\\AppData\\Local\\Android\\Sdk\\cmake\\3.10.2.4988404\\bin\\cmake.exe",
|
||||||
|
"cStandard": "c11",
|
||||||
|
"cppStandard": "c++17",
|
||||||
|
"intelliSenseMode": "gcc-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
46
.vscode/settings.json
vendored
46
.vscode/settings.json
vendored
@@ -57,6 +57,48 @@
|
|||||||
"xstring": "cpp",
|
"xstring": "cpp",
|
||||||
"xtr1common": "cpp",
|
"xtr1common": "cpp",
|
||||||
"xtree": "cpp",
|
"xtree": "cpp",
|
||||||
"xutility": "cpp"
|
"xutility": "cpp",
|
||||||
}
|
"array": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"variant": "cpp",
|
||||||
|
"xlocbuf": "cpp",
|
||||||
|
"xlocmes": "cpp",
|
||||||
|
"xlocmon": "cpp",
|
||||||
|
"xloctime": "cpp",
|
||||||
|
"cerrno": "cpp",
|
||||||
|
"__bit_reference": "cpp",
|
||||||
|
"__config": "cpp",
|
||||||
|
"__debug": "cpp",
|
||||||
|
"__errc": "cpp",
|
||||||
|
"__functional_base": "cpp",
|
||||||
|
"__hash_table": "cpp",
|
||||||
|
"__locale": "cpp",
|
||||||
|
"__mutex_base": "cpp",
|
||||||
|
"__node_handle": "cpp",
|
||||||
|
"__nullptr": "cpp",
|
||||||
|
"__split_buffer": "cpp",
|
||||||
|
"__string": "cpp",
|
||||||
|
"__threading_support": "cpp",
|
||||||
|
"__tree": "cpp",
|
||||||
|
"__tuple": "cpp",
|
||||||
|
"complex": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"strstream": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"cfenv": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"typeindex": "cpp"
|
||||||
|
},
|
||||||
|
"java.configuration.updateBuildConfiguration": "interactive"
|
||||||
}
|
}
|
6
android/.classpath
Normal file
6
android/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||||
|
<classpathentry kind="output" path="bin/default"/>
|
||||||
|
</classpath>
|
9
android/.gitignore
vendored
Normal file
9
android/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
/local.properties
|
||||||
|
/.idea/workspace.xml
|
||||||
|
/.idea/libraries
|
||||||
|
.DS_Store
|
||||||
|
/build
|
||||||
|
/captures
|
||||||
|
/.cxx
|
3
android/.idea/.gitignore
generated
vendored
Normal file
3
android/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
1
android/.idea/.name
generated
Normal file
1
android/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
|||||||
|
flutter_qjs
|
BIN
android/.idea/caches/build_file_checksums.ser
generated
Normal file
BIN
android/.idea/caches/build_file_checksums.ser
generated
Normal file
Binary file not shown.
6
android/.idea/compiler.xml
generated
Normal file
6
android/.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="11" />
|
||||||
|
</component>
|
||||||
|
</project>
|
17
android/.idea/gradle.xml
generated
Normal file
17
android/.idea/gradle.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
|
<component name="GradleSettings">
|
||||||
|
<option name="linkedExternalProjectsSettings">
|
||||||
|
<GradleProjectSettings>
|
||||||
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
30
android/.idea/jarRepositories.xml
generated
Normal file
30
android/.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="BintrayJCenter" />
|
||||||
|
<option name="name" value="BintrayJCenter" />
|
||||||
|
<option name="url" value="https://jcenter.bintray.com/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="Google" />
|
||||||
|
<option name="name" value="Google" />
|
||||||
|
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="https://jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
5
android/.idea/misc.xml
generated
Normal file
5
android/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
6
android/.idea/vcs.xml
generated
Normal file
6
android/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
23
android/.project
Normal file
23
android/.project
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>flutter_qjs</name>
|
||||||
|
<comment>Project android created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
13
android/.settings/org.eclipse.buildship.core.prefs
Normal file
13
android/.settings/org.eclipse.buildship.core.prefs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
arguments=
|
||||||
|
auto.sync=false
|
||||||
|
build.scans.enabled=false
|
||||||
|
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
|
||||||
|
connection.project.dir=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
gradle.user.home=
|
||||||
|
java.home=C\:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2019.3.2/jbr
|
||||||
|
jvm.arguments=
|
||||||
|
offline.mode=false
|
||||||
|
override.workspace.settings=true
|
||||||
|
show.console.view=true
|
||||||
|
show.executions.view=true
|
59
android/build.gradle
Normal file
59
android/build.gradle
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
group 'soko.ekibun.flutter_qjs'
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.3.50'
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.allprojects {
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 28
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
}
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 21
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
cppFlags "-std=c++17"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lintOptions {
|
||||||
|
disable 'InvalidPackage'
|
||||||
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
path "src/main/jni/CMakeLists.txt"
|
||||||
|
version "3.10.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
// implementation 'com.github.abner.oasis-jsbridge-android:oasis-jsbridge-quickjs:0.11.0'
|
||||||
|
}
|
4
android/gradle.properties
Normal file
4
android/gradle.properties
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
org.gradle.jvmargs=-Xmx1536M
|
||||||
|
android.enableR8=true
|
||||||
|
android.useAndroidX=true
|
||||||
|
android.enableJetifier=true
|
5
android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
1
android/settings.gradle
Normal file
1
android/settings.gradle
Normal file
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'flutter_qjs'
|
3
android/src/main/AndroidManifest.xml
Normal file
3
android/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="soko.ekibun.flutter_qjs">
|
||||||
|
</manifest>
|
56
android/src/main/jni/CMakeLists.txt
Normal file
56
android/src/main/jni/CMakeLists.txt
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# For more information about using CMake with Android Studio, read the
|
||||||
|
# documentation: https://d.android.com/studio/projects/add-native-code.html
|
||||||
|
|
||||||
|
# Sets the minimum version of CMake required to build the native library.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.4.1)
|
||||||
|
set(JNI_LIB_NAME libjsengine)
|
||||||
|
|
||||||
|
|
||||||
|
# Creates and names a library, sets it as either STATIC
|
||||||
|
# or SHARED, and provides the relative paths to its source code.
|
||||||
|
# You can define multiple libraries, and CMake builds them for you.
|
||||||
|
# Gradle automatically packages shared libraries with your APK.
|
||||||
|
|
||||||
|
add_library( # Sets the name of the library.
|
||||||
|
${JNI_LIB_NAME}
|
||||||
|
|
||||||
|
# Sets the library as a shared library.
|
||||||
|
SHARED
|
||||||
|
|
||||||
|
# Provides a relative path to your source file(s).
|
||||||
|
native-lib.cpp )
|
||||||
|
|
||||||
|
# quickjs
|
||||||
|
file (STRINGS "quickjs/VERSION" QUICKJS_VERSION)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCONFIG_VERSION=\\\"${QUICKJS_VERSION}\\\"")
|
||||||
|
target_sources(${JNI_LIB_NAME} PUBLIC
|
||||||
|
quickjs/cutils.c
|
||||||
|
quickjs/libregexp.c
|
||||||
|
quickjs/libunicode.c
|
||||||
|
quickjs/quickjs.c
|
||||||
|
)
|
||||||
|
|
||||||
|
# Searches for a specified prebuilt library and stores the path as a
|
||||||
|
# variable. Because CMake includes system libraries in the search path by
|
||||||
|
# default, you only need to specify the name of the public NDK library
|
||||||
|
# you want to add. CMake verifies that the library exists before
|
||||||
|
# completing its build.
|
||||||
|
|
||||||
|
find_library( # Sets the name of the path variable.
|
||||||
|
log-lib
|
||||||
|
|
||||||
|
# Specifies the name of the NDK library that
|
||||||
|
# you want CMake to locate.
|
||||||
|
log )
|
||||||
|
|
||||||
|
# Specifies libraries CMake should link to your target library. You
|
||||||
|
# can link multiple libraries, such as libraries you define in this
|
||||||
|
# build script, prebuilt third-party libraries, or system libraries.
|
||||||
|
|
||||||
|
target_link_libraries( # Specifies the target library.
|
||||||
|
${JNI_LIB_NAME}
|
||||||
|
|
||||||
|
# Links the target library to the log library
|
||||||
|
# included in the NDK.
|
||||||
|
${log-lib} )
|
182
android/src/main/jni/js_dart_promise.hpp
Normal file
182
android/src/main/jni/js_dart_promise.hpp
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
/*
|
||||||
|
* @Description:
|
||||||
|
* @Author: ekibun
|
||||||
|
* @Date: 2020-08-07 13:55:52
|
||||||
|
* @LastEditors: ekibun
|
||||||
|
* @LastEditTime: 2020-08-12 14:24:42
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "quickjs/quickjspp.hpp"
|
||||||
|
#include "quickjs/list.h"
|
||||||
|
#include <future>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
namespace qjs
|
||||||
|
{
|
||||||
|
static JSClassID js_dart_promise_class_id;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
JSValue *argv;
|
||||||
|
} JSOSFutureArgv;
|
||||||
|
|
||||||
|
using JSFutureReturn = std::function<JSOSFutureArgv(JSContext *)>;
|
||||||
|
using DartChannel = std::function<std::future<JSFutureReturn>(std::string, std::string)>;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
struct list_head link;
|
||||||
|
std::shared_future<JSFutureReturn> future;
|
||||||
|
JSValue resolve;
|
||||||
|
JSValue reject;
|
||||||
|
} JSOSFuture;
|
||||||
|
|
||||||
|
typedef struct JSThreadState
|
||||||
|
{
|
||||||
|
struct list_head os_future; /* list of JSOSFuture.link */
|
||||||
|
std::function<std::future<JSFutureReturn>(std::string, std::string)> channel;
|
||||||
|
} JSThreadState;
|
||||||
|
|
||||||
|
static JSValue js_add_future(Value resolve, Value reject, std::shared_future<JSFutureReturn> future)
|
||||||
|
{
|
||||||
|
JSRuntime *rt = JS_GetRuntime(resolve.ctx);
|
||||||
|
JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt);
|
||||||
|
JSValueConst jsResolve, jsReject;
|
||||||
|
JSOSFuture *th;
|
||||||
|
JSValue obj;
|
||||||
|
|
||||||
|
jsResolve = resolve.v;
|
||||||
|
if (!JS_IsFunction(resolve.ctx, jsResolve))
|
||||||
|
return JS_ThrowTypeError(resolve.ctx, "resolve not a function");
|
||||||
|
jsReject = reject.v;
|
||||||
|
if (!JS_IsFunction(reject.ctx, jsReject))
|
||||||
|
return JS_ThrowTypeError(reject.ctx, "reject not a function");
|
||||||
|
obj = JS_NewObjectClass(resolve.ctx, js_dart_promise_class_id);
|
||||||
|
if (JS_IsException(obj))
|
||||||
|
return obj;
|
||||||
|
th = (JSOSFuture *)js_mallocz(resolve.ctx, sizeof(*th));
|
||||||
|
if (!th)
|
||||||
|
{
|
||||||
|
JS_FreeValue(resolve.ctx, obj);
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
th->future = future;
|
||||||
|
th->resolve = JS_DupValue(resolve.ctx, jsResolve);
|
||||||
|
th->reject = JS_DupValue(reject.ctx, jsReject);
|
||||||
|
list_add_tail(&th->link, &ts->os_future);
|
||||||
|
JS_SetOpaque(obj, th);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSValue js_dart_future(Value resolve, Value reject, std::string name, std::string args)
|
||||||
|
{
|
||||||
|
JSRuntime *rt = JS_GetRuntime(resolve.ctx);
|
||||||
|
JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt);
|
||||||
|
return js_add_future(resolve, reject, ts->channel(name, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unlink_future(JSRuntime *rt, JSOSFuture *th)
|
||||||
|
{
|
||||||
|
if (th->link.prev)
|
||||||
|
{
|
||||||
|
list_del(&th->link);
|
||||||
|
th->link.prev = th->link.next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_future(JSRuntime *rt, JSOSFuture *th)
|
||||||
|
{
|
||||||
|
JS_FreeValueRT(rt, th->resolve);
|
||||||
|
JS_FreeValueRT(rt, th->reject);
|
||||||
|
js_free_rt(rt, th);
|
||||||
|
}
|
||||||
|
|
||||||
|
void js_init_handlers(JSRuntime *rt, DartChannel channel)
|
||||||
|
{
|
||||||
|
JSThreadState *ts = (JSThreadState *)malloc(sizeof(*ts));
|
||||||
|
if (!ts)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Could not allocate memory for the worker");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
memset(ts, 0, sizeof(*ts));
|
||||||
|
init_list_head(&ts->os_future);
|
||||||
|
ts->channel = channel;
|
||||||
|
|
||||||
|
JS_SetRuntimeOpaque(rt, ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void js_free_handlers(JSRuntime *rt)
|
||||||
|
{
|
||||||
|
JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt);
|
||||||
|
struct list_head *el, *el1;
|
||||||
|
|
||||||
|
list_for_each_safe(el, el1, &ts->os_future)
|
||||||
|
{
|
||||||
|
JSOSFuture *th = list_entry(el, JSOSFuture, link);
|
||||||
|
th->future.get();
|
||||||
|
unlink_future(rt, th);
|
||||||
|
free_future(rt, th);
|
||||||
|
}
|
||||||
|
ts->channel = nullptr;
|
||||||
|
free(ts);
|
||||||
|
JS_SetRuntimeOpaque(rt, NULL); /* fail safe */
|
||||||
|
}
|
||||||
|
|
||||||
|
static void call_handler(JSContext *ctx, JSValueConst func, int count, JSValue *argv)
|
||||||
|
{
|
||||||
|
JSValue ret, func1;
|
||||||
|
/* 'func' might be destroyed when calling itself (if it frees the
|
||||||
|
handler), so must take extra care */
|
||||||
|
func1 = JS_DupValue(ctx, func);
|
||||||
|
ret = JS_Call(ctx, func1, JS_UNDEFINED, count, argv);
|
||||||
|
JS_FreeValue(ctx, func1);
|
||||||
|
if (JS_IsException(ret))
|
||||||
|
throw exception{};
|
||||||
|
JS_FreeValue(ctx, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int js_dart_poll(JSContext *ctx)
|
||||||
|
{
|
||||||
|
JSRuntime *rt = JS_GetRuntime(ctx);
|
||||||
|
JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt);
|
||||||
|
struct list_head *el;
|
||||||
|
|
||||||
|
/* XXX: handle signals if useful */
|
||||||
|
|
||||||
|
if (list_empty(&ts->os_future))
|
||||||
|
return -1; /* no more events */
|
||||||
|
|
||||||
|
/* XXX: only timers and basic console input are supported */
|
||||||
|
if (!list_empty(&ts->os_future))
|
||||||
|
{
|
||||||
|
list_for_each(el, &ts->os_future)
|
||||||
|
{
|
||||||
|
JSOSFuture *th = list_entry(el, JSOSFuture, link);
|
||||||
|
auto status = th->future.wait_for(std::chrono::seconds(0));
|
||||||
|
if (status == std::future_status::ready)
|
||||||
|
{
|
||||||
|
JSOSFutureArgv argv = th->future.get()(ctx);
|
||||||
|
JSValue resolve, reject;
|
||||||
|
int64_t delay;
|
||||||
|
/* the timer expired */
|
||||||
|
resolve = th->resolve;
|
||||||
|
th->resolve = JS_UNDEFINED;
|
||||||
|
reject = th->reject;
|
||||||
|
th->reject = JS_UNDEFINED;
|
||||||
|
unlink_future(rt, th);
|
||||||
|
free_future(rt, th);
|
||||||
|
call_handler(ctx, argv.count < 0 ? reject : resolve, abs(argv.count), argv.argv);
|
||||||
|
for (int i = 0; i < abs(argv.count); ++i)
|
||||||
|
JS_FreeValue(ctx, argv.argv[i]);
|
||||||
|
JS_FreeValue(ctx, resolve);
|
||||||
|
JS_FreeValue(ctx, reject);
|
||||||
|
delete argv.argv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace qjs
|
192
android/src/main/jni/js_engine.hpp
Normal file
192
android/src/main/jni/js_engine.hpp
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* @Description:
|
||||||
|
* @Author: ekibun
|
||||||
|
* @Date: 2020-08-08 10:30:59
|
||||||
|
* @LastEditors: ekibun
|
||||||
|
* @LastEditTime: 2020-08-12 13:53:59
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <future>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "js_dart_promise.hpp"
|
||||||
|
#include "quickjs/quickjspp.hpp"
|
||||||
|
|
||||||
|
namespace qjs
|
||||||
|
{
|
||||||
|
struct EngineTask
|
||||||
|
{
|
||||||
|
std::string command;
|
||||||
|
std::string name;
|
||||||
|
std::function<void(std::string)> resolve;
|
||||||
|
std::function<void(std::string)> reject;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EngineTaskResolver
|
||||||
|
{
|
||||||
|
Value result;
|
||||||
|
std::function<void(std::string)> resolve;
|
||||||
|
std::function<void(std::string)> reject;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string getStackTrack(Value exc)
|
||||||
|
{
|
||||||
|
std::string err = (std::string)exc;
|
||||||
|
if ((bool)exc["stack"])
|
||||||
|
err += "\n" + (std::string)exc["stack"];
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Engine
|
||||||
|
{
|
||||||
|
// 引擎线程
|
||||||
|
std::thread thread;
|
||||||
|
// 任务队列
|
||||||
|
std::queue<EngineTask> tasks;
|
||||||
|
// 同步
|
||||||
|
std::mutex m_lock;
|
||||||
|
// 是否关闭提交
|
||||||
|
std::atomic<bool> stoped;
|
||||||
|
|
||||||
|
void handleException(qjs::Value exc)
|
||||||
|
{
|
||||||
|
std::cout << getStackTrack(exc) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline Engine(DartChannel channel) : stoped{false}
|
||||||
|
{
|
||||||
|
thread = std::thread([this, channel] { // 工作线程函数
|
||||||
|
// 创建运行环境
|
||||||
|
Runtime rt;
|
||||||
|
js_init_handlers(rt.rt, channel);
|
||||||
|
Context ctx(rt);
|
||||||
|
auto &module = ctx.addModule("__DartImpl");
|
||||||
|
module.function<&js_dart_future>("__invoke");
|
||||||
|
ctx.eval(
|
||||||
|
R"xxx(
|
||||||
|
import * as __DartImpl from "__DartImpl";
|
||||||
|
globalThis.dart = (method, ...args) => new Promise((res, rej) =>
|
||||||
|
__DartImpl.__invoke((v) => res(JSON.parse(v)), rej, method, JSON.stringify(args)));
|
||||||
|
)xxx",
|
||||||
|
"<dart>", JS_EVAL_TYPE_MODULE);
|
||||||
|
std::vector<EngineTaskResolver> unresolvedTask;
|
||||||
|
// 循环
|
||||||
|
while (!this->stoped)
|
||||||
|
{
|
||||||
|
// 获取待执行的task
|
||||||
|
EngineTask task;
|
||||||
|
{ // 获取一个待执行的 task
|
||||||
|
std::unique_lock<std::mutex> lock{this->m_lock}; // unique_lock 相比 lock_guard 的好处是:可以随时 unlock() 和 lock()
|
||||||
|
if (!this->tasks.empty())
|
||||||
|
{
|
||||||
|
task = this->tasks.front(); // 取一个 task
|
||||||
|
this->tasks.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 执行task
|
||||||
|
if (task.resolve)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ctx.global()["__evalstr"] = JS_NewString(ctx.ctx, task.command.c_str());
|
||||||
|
Value ret = ctx.eval(
|
||||||
|
R"xxx(
|
||||||
|
(() => {
|
||||||
|
const __ret = Promise.resolve(eval(__evalstr))
|
||||||
|
.then(v => {
|
||||||
|
__ret.__value = v;
|
||||||
|
__ret.__resolved = true;
|
||||||
|
}).catch(e => {
|
||||||
|
__ret.__error = e;
|
||||||
|
__ret.__rejected = true;
|
||||||
|
});
|
||||||
|
return __ret;
|
||||||
|
})()
|
||||||
|
)xxx",
|
||||||
|
task.name.c_str());
|
||||||
|
unresolvedTask.emplace_back(EngineTaskResolver{ret, std::move(task.resolve), std::move(task.reject)});
|
||||||
|
}
|
||||||
|
catch (exception e)
|
||||||
|
{
|
||||||
|
task.reject(getStackTrack(ctx.getException()));
|
||||||
|
}
|
||||||
|
// 执行microtask
|
||||||
|
JSContext *pctx;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int err = JS_ExecutePendingJob(rt.rt, &pctx);
|
||||||
|
if (err <= 0)
|
||||||
|
{
|
||||||
|
if (err < 0)
|
||||||
|
std::cout << getStackTrack(ctx.getException()) << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO 检查promise状态
|
||||||
|
for (auto it = unresolvedTask.begin(); it != unresolvedTask.end();)
|
||||||
|
{
|
||||||
|
bool finished = false;
|
||||||
|
if (it->result["__resolved"])
|
||||||
|
{
|
||||||
|
it->resolve((std::string)it->result["__value"]);
|
||||||
|
finished = true;
|
||||||
|
};
|
||||||
|
if (it->result["__rejected"])
|
||||||
|
{
|
||||||
|
it->reject(getStackTrack(it->result["__error"]));
|
||||||
|
finished = true;
|
||||||
|
};
|
||||||
|
if (finished)
|
||||||
|
it = unresolvedTask.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
// 检查dart交互
|
||||||
|
bool idle = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
idle = js_dart_poll(ctx.ctx);
|
||||||
|
}
|
||||||
|
catch (exception e)
|
||||||
|
{
|
||||||
|
handleException(ctx.getException());
|
||||||
|
}
|
||||||
|
// 空闲时reject所有task
|
||||||
|
if (idle && !JS_IsJobPending(rt.rt) && !unresolvedTask.empty())
|
||||||
|
{
|
||||||
|
for (EngineTaskResolver &task : unresolvedTask)
|
||||||
|
{
|
||||||
|
task.reject("Promise cannot resolve");
|
||||||
|
}
|
||||||
|
unresolvedTask.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
js_free_handlers(rt.rt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
inline ~Engine()
|
||||||
|
{
|
||||||
|
stoped.store(true);
|
||||||
|
if (thread.joinable())
|
||||||
|
thread.join(); // 等待任务结束, 前提:线程一定会执行完
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// 提交一个任务
|
||||||
|
void commit(EngineTask task)
|
||||||
|
{
|
||||||
|
if (stoped.load()) // stop == true ??
|
||||||
|
throw std::runtime_error("commit on stopped engine.");
|
||||||
|
{ // 添加任务到队列
|
||||||
|
std::lock_guard<std::mutex> lock{m_lock}; //对当前块的语句加锁 lock_guard 是 mutex 的 stack 封装类,构造的时候 lock(),析构的时候 unlock()
|
||||||
|
tasks.emplace(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace qjs
|
164
android/src/main/jni/native-lib.cpp
Normal file
164
android/src/main/jni/native-lib.cpp
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
* @Description:
|
||||||
|
* @Author: ekibun
|
||||||
|
* @Date: 2020-08-09 18:16:11
|
||||||
|
* @LastEditors: ekibun
|
||||||
|
* @LastEditTime: 2020-08-12 23:11:35
|
||||||
|
*/
|
||||||
|
#include <jni.h>
|
||||||
|
#include <string>
|
||||||
|
#include "js_engine.hpp"
|
||||||
|
|
||||||
|
qjs::Engine *engine = nullptr;
|
||||||
|
|
||||||
|
// static jobject gClassLoader;
|
||||||
|
// static jmethodID gFindClassMethod;
|
||||||
|
|
||||||
|
JNIEnv *getEnv(JavaVM *gJvm)
|
||||||
|
{
|
||||||
|
JNIEnv *env;
|
||||||
|
int status = gJvm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
||||||
|
if (status < 0)
|
||||||
|
{
|
||||||
|
status = gJvm->AttachCurrentThread(&env, NULL);
|
||||||
|
if (status < 0)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
// JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved)
|
||||||
|
// {
|
||||||
|
// JNIEnv *env = getEnv(pjvm);
|
||||||
|
// auto randomClass = env->FindClass("soko/ekibun/flutter_qjs/ResultWrapper");
|
||||||
|
// jclass classClass = env->GetObjectClass(randomClass);
|
||||||
|
// auto classLoaderClass = env->FindClass("java/lang/ClassLoader");
|
||||||
|
// auto getClassLoaderMethod = env->GetMethodID(classClass, "getClassLoader",
|
||||||
|
// "()Ljava/lang/ClassLoader;");
|
||||||
|
// gClassLoader = env->NewGlobalRef(env->CallObjectMethod(randomClass, getClassLoaderMethod));
|
||||||
|
// gFindClassMethod = env->GetMethodID(classLoaderClass, "findClass",
|
||||||
|
// "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||||
|
|
||||||
|
// return JNI_VERSION_1_6;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// jclass findClass(JNIEnv *env, const char *name)
|
||||||
|
// {
|
||||||
|
// return static_cast<jclass>(env->CallObjectMethod(gClassLoader, gFindClassMethod, env->NewStringUTF(name)));
|
||||||
|
// }
|
||||||
|
|
||||||
|
void jniResultResolve(JavaVM *jvm, jobject result, std::string data)
|
||||||
|
{
|
||||||
|
JNIEnv *env = getEnv(jvm);
|
||||||
|
jclass jclazz = env->GetObjectClass(result);
|
||||||
|
jmethodID jmethod = env->GetMethodID(jclazz, "success", "(Ljava/lang/String;)V");
|
||||||
|
jstring jdata = env->NewStringUTF(data.c_str());
|
||||||
|
env->CallVoidMethod(result, jmethod, jdata);
|
||||||
|
env->DeleteLocalRef(jdata);
|
||||||
|
env->DeleteGlobalRef(result);
|
||||||
|
jvm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jniResultReject(JavaVM *jvm, jobject result, std::string reason)
|
||||||
|
{
|
||||||
|
JNIEnv *env = getEnv(jvm);
|
||||||
|
jclass jclazz = env->GetObjectClass(result);
|
||||||
|
jmethodID jmethod = env->GetMethodID(jclazz, "error", "(Ljava/lang/String;)V");
|
||||||
|
jstring jreason = env->NewStringUTF(reason.c_str());
|
||||||
|
env->CallVoidMethod(result, jmethod, jreason);
|
||||||
|
env->DeleteLocalRef(jreason);
|
||||||
|
env->DeleteGlobalRef(result);
|
||||||
|
jvm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jniChannelInvoke(JavaVM *jvm, jobject channel, std::promise<qjs::JSFutureReturn> *promise, std::string method, std::string argv)
|
||||||
|
{
|
||||||
|
JNIEnv *env = nullptr;
|
||||||
|
jvm->GetEnv((void **)&env, JNI_VERSION_1_2);
|
||||||
|
jvm->AttachCurrentThread(&env, NULL);
|
||||||
|
jclass jclazz = env->GetObjectClass(channel);
|
||||||
|
jmethodID jmethod = env->GetMethodID(jclazz, "invokeMethod", "(Ljava/lang/String;Ljava/lang/String;J)V");
|
||||||
|
jstring jstrmethod = env->NewStringUTF(method.c_str());
|
||||||
|
jstring jstrargv = env->NewStringUTF(argv.c_str());
|
||||||
|
|
||||||
|
env->CallVoidMethod(channel, jmethod, jstrmethod, jstrargv, (jlong)promise);
|
||||||
|
env->DeleteLocalRef(jstrmethod);
|
||||||
|
env->DeleteLocalRef(jstrargv);
|
||||||
|
jvm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
|
Java_soko_ekibun_flutter_1qjs_JniBridge_initEngine(
|
||||||
|
JNIEnv *env,
|
||||||
|
jobject thiz,
|
||||||
|
jobject channel)
|
||||||
|
{
|
||||||
|
JavaVM *jvm = nullptr;
|
||||||
|
env->GetJavaVM(&jvm);
|
||||||
|
jobject gchannel = env->NewGlobalRef(channel);
|
||||||
|
engine = new qjs::Engine([jvm, gchannel](std::string name, std::string args) {
|
||||||
|
auto promise = new std::promise<qjs::JSFutureReturn>();
|
||||||
|
jniChannelInvoke(jvm, gchannel, promise, name, args);
|
||||||
|
return promise->get_future();
|
||||||
|
});
|
||||||
|
return (jlong)engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Java_soko_ekibun_flutter_1qjs_JniBridge_evaluate(
|
||||||
|
JNIEnv *env,
|
||||||
|
jobject thiz,
|
||||||
|
jstring script,
|
||||||
|
jstring name,
|
||||||
|
jobject result)
|
||||||
|
{
|
||||||
|
JavaVM *jvm = nullptr;
|
||||||
|
env->GetJavaVM(&jvm);
|
||||||
|
jobject gresult = env->NewGlobalRef(result);
|
||||||
|
engine->commit(qjs::EngineTask{
|
||||||
|
env->GetStringUTFChars(script, 0),
|
||||||
|
env->GetStringUTFChars(name, 0),
|
||||||
|
[jvm, gresult](std::string resolve) {
|
||||||
|
jniResultResolve(jvm, gresult, resolve);
|
||||||
|
// flutter::EncodableValue response(resolve);
|
||||||
|
// presult->Success(&response);
|
||||||
|
},
|
||||||
|
[jvm, gresult](std::string reject) {
|
||||||
|
jniResultReject(jvm, gresult, reject);
|
||||||
|
// presult->Error("FlutterJSException", reject);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Java_soko_ekibun_flutter_1qjs_JniBridge_close(
|
||||||
|
JNIEnv *env,
|
||||||
|
jobject /* this */)
|
||||||
|
{
|
||||||
|
delete engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Java_soko_ekibun_flutter_1qjs_JniBridge_resolve(
|
||||||
|
JNIEnv *env,
|
||||||
|
jobject clazz,
|
||||||
|
jlong promise, jstring data)
|
||||||
|
{
|
||||||
|
((std::promise<qjs::JSFutureReturn> *)promise)->set_value((qjs::JSFutureReturn)[data = std::string(env->GetStringUTFChars(data, 0))](qjs::JSContext * ctx) {
|
||||||
|
qjs::JSValue *ret = new qjs::JSValue{JS_NewString(ctx, data.c_str())};
|
||||||
|
return qjs::JSOSFutureArgv{1, ret};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Java_soko_ekibun_flutter_1qjs_JniBridge_reject(
|
||||||
|
JNIEnv *env,
|
||||||
|
jobject clazz,
|
||||||
|
jlong promise, jstring data)
|
||||||
|
{
|
||||||
|
((std::promise<qjs::JSFutureReturn> *)promise)->set_value((qjs::JSFutureReturn)[data = std::string(env->GetStringUTFChars(data, 0))](qjs::JSContext * ctx) {
|
||||||
|
qjs::JSValue *ret = new qjs::JSValue{JS_NewString(ctx, data.c_str())};
|
||||||
|
return qjs::JSOSFutureArgv{-1, ret};
|
||||||
|
});
|
||||||
|
}
|
1
android/src/main/jni/quickjs/VERSION
Normal file
1
android/src/main/jni/quickjs/VERSION
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2020-07-05
|
620
android/src/main/jni/quickjs/cutils.c
Normal file
620
android/src/main/jni/quickjs/cutils.c
Normal file
@@ -0,0 +1,620 @@
|
|||||||
|
/*
|
||||||
|
* C utilities
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 Fabrice Bellard
|
||||||
|
* Copyright (c) 2018 Charlie Gordon
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "cutils.h"
|
||||||
|
|
||||||
|
void pstrcpy(char *buf, int buf_size, const char *str)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
char *q = buf;
|
||||||
|
|
||||||
|
if (buf_size <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
c = *str++;
|
||||||
|
if (c == 0 || q >= buf + buf_size - 1)
|
||||||
|
break;
|
||||||
|
*q++ = c;
|
||||||
|
}
|
||||||
|
*q = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* strcat and truncate. */
|
||||||
|
char *pstrcat(char *buf, int buf_size, const char *s)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
len = strlen(buf);
|
||||||
|
if (len < buf_size)
|
||||||
|
pstrcpy(buf + len, buf_size - len, s);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int strstart(const char *str, const char *val, const char **ptr)
|
||||||
|
{
|
||||||
|
const char *p, *q;
|
||||||
|
p = str;
|
||||||
|
q = val;
|
||||||
|
while (*q != '\0') {
|
||||||
|
if (*p != *q)
|
||||||
|
return 0;
|
||||||
|
p++;
|
||||||
|
q++;
|
||||||
|
}
|
||||||
|
if (ptr)
|
||||||
|
*ptr = p;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int has_suffix(const char *str, const char *suffix)
|
||||||
|
{
|
||||||
|
size_t len = strlen(str);
|
||||||
|
size_t slen = strlen(suffix);
|
||||||
|
return (len >= slen && !memcmp(str + len - slen, suffix, slen));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dynamic buffer package */
|
||||||
|
|
||||||
|
static void *dbuf_default_realloc(void *opaque, void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
return realloc(ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func)
|
||||||
|
{
|
||||||
|
memset(s, 0, sizeof(*s));
|
||||||
|
if (!realloc_func)
|
||||||
|
realloc_func = dbuf_default_realloc;
|
||||||
|
s->opaque = opaque;
|
||||||
|
s->realloc_func = realloc_func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbuf_init(DynBuf *s)
|
||||||
|
{
|
||||||
|
dbuf_init2(s, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* return < 0 if error */
|
||||||
|
int dbuf_realloc(DynBuf *s, size_t new_size)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
uint8_t *new_buf;
|
||||||
|
if (new_size > s->allocated_size) {
|
||||||
|
if (s->error)
|
||||||
|
return -1;
|
||||||
|
size = s->allocated_size * 3 / 2;
|
||||||
|
if (size > new_size)
|
||||||
|
new_size = size;
|
||||||
|
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
|
||||||
|
if (!new_buf) {
|
||||||
|
s->error = TRUE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
s->buf = new_buf;
|
||||||
|
s->allocated_size = new_size;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len)
|
||||||
|
{
|
||||||
|
size_t end;
|
||||||
|
end = offset + len;
|
||||||
|
if (dbuf_realloc(s, end))
|
||||||
|
return -1;
|
||||||
|
memcpy(s->buf + offset, data, len);
|
||||||
|
if (end > s->size)
|
||||||
|
s->size = end;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dbuf_put(DynBuf *s, const uint8_t *data, size_t len)
|
||||||
|
{
|
||||||
|
if (unlikely((s->size + len) > s->allocated_size)) {
|
||||||
|
if (dbuf_realloc(s, s->size + len))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(s->buf + s->size, data, len);
|
||||||
|
s->size += len;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dbuf_put_self(DynBuf *s, size_t offset, size_t len)
|
||||||
|
{
|
||||||
|
if (unlikely((s->size + len) > s->allocated_size)) {
|
||||||
|
if (dbuf_realloc(s, s->size + len))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(s->buf + s->size, s->buf + offset, len);
|
||||||
|
s->size += len;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dbuf_putc(DynBuf *s, uint8_t c)
|
||||||
|
{
|
||||||
|
return dbuf_put(s, &c, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int dbuf_putstr(DynBuf *s, const char *str)
|
||||||
|
{
|
||||||
|
return dbuf_put(s, (const uint8_t *)str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
|
||||||
|
const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char buf[128];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (len < sizeof(buf)) {
|
||||||
|
/* fast case */
|
||||||
|
return dbuf_put(s, (uint8_t *)buf, len);
|
||||||
|
} else {
|
||||||
|
if (dbuf_realloc(s, s->size + len + 1))
|
||||||
|
return -1;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf((char *)(s->buf + s->size), s->allocated_size - s->size,
|
||||||
|
fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
s->size += len;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbuf_free(DynBuf *s)
|
||||||
|
{
|
||||||
|
/* we test s->buf as a fail safe to avoid crashing if dbuf_free()
|
||||||
|
is called twice */
|
||||||
|
if (s->buf) {
|
||||||
|
s->realloc_func(s->opaque, s->buf, 0);
|
||||||
|
}
|
||||||
|
memset(s, 0, sizeof(*s));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Note: at most 31 bits are encoded. At most UTF8_CHAR_LEN_MAX bytes
|
||||||
|
are output. */
|
||||||
|
int unicode_to_utf8(uint8_t *buf, unsigned int c)
|
||||||
|
{
|
||||||
|
uint8_t *q = buf;
|
||||||
|
|
||||||
|
if (c < 0x80) {
|
||||||
|
*q++ = c;
|
||||||
|
} else {
|
||||||
|
if (c < 0x800) {
|
||||||
|
*q++ = (c >> 6) | 0xc0;
|
||||||
|
} else {
|
||||||
|
if (c < 0x10000) {
|
||||||
|
*q++ = (c >> 12) | 0xe0;
|
||||||
|
} else {
|
||||||
|
if (c < 0x00200000) {
|
||||||
|
*q++ = (c >> 18) | 0xf0;
|
||||||
|
} else {
|
||||||
|
if (c < 0x04000000) {
|
||||||
|
*q++ = (c >> 24) | 0xf8;
|
||||||
|
} else if (c < 0x80000000) {
|
||||||
|
*q++ = (c >> 30) | 0xfc;
|
||||||
|
*q++ = ((c >> 24) & 0x3f) | 0x80;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*q++ = ((c >> 18) & 0x3f) | 0x80;
|
||||||
|
}
|
||||||
|
*q++ = ((c >> 12) & 0x3f) | 0x80;
|
||||||
|
}
|
||||||
|
*q++ = ((c >> 6) & 0x3f) | 0x80;
|
||||||
|
}
|
||||||
|
*q++ = (c & 0x3f) | 0x80;
|
||||||
|
}
|
||||||
|
return q - buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const unsigned int utf8_min_code[5] = {
|
||||||
|
0x80, 0x800, 0x10000, 0x00200000, 0x04000000,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const unsigned char utf8_first_code_mask[5] = {
|
||||||
|
0x1f, 0xf, 0x7, 0x3, 0x1,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* return -1 if error. *pp is not updated in this case. max_len must
|
||||||
|
be >= 1. The maximum length for a UTF8 byte sequence is 6 bytes. */
|
||||||
|
int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp)
|
||||||
|
{
|
||||||
|
int l, c, b, i;
|
||||||
|
|
||||||
|
c = *p++;
|
||||||
|
if (c < 0x80) {
|
||||||
|
*pp = p;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
switch(c) {
|
||||||
|
case 0xc0 ... 0xdf:
|
||||||
|
l = 1;
|
||||||
|
break;
|
||||||
|
case 0xe0 ... 0xef:
|
||||||
|
l = 2;
|
||||||
|
break;
|
||||||
|
case 0xf0 ... 0xf7:
|
||||||
|
l = 3;
|
||||||
|
break;
|
||||||
|
case 0xf8 ... 0xfb:
|
||||||
|
l = 4;
|
||||||
|
break;
|
||||||
|
case 0xfc ... 0xfd:
|
||||||
|
l = 5;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* check that we have enough characters */
|
||||||
|
if (l > (max_len - 1))
|
||||||
|
return -1;
|
||||||
|
c &= utf8_first_code_mask[l - 1];
|
||||||
|
for(i = 0; i < l; i++) {
|
||||||
|
b = *p++;
|
||||||
|
if (b < 0x80 || b >= 0xc0)
|
||||||
|
return -1;
|
||||||
|
c = (c << 6) | (b & 0x3f);
|
||||||
|
}
|
||||||
|
if (c < utf8_min_code[l - 1])
|
||||||
|
return -1;
|
||||||
|
*pp = p;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
#if defined(EMSCRIPTEN) || defined(__ANDROID__)
|
||||||
|
|
||||||
|
static void *rqsort_arg;
|
||||||
|
static int (*rqsort_cmp)(const void *, const void *, void *);
|
||||||
|
|
||||||
|
static int rqsort_cmp2(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
return rqsort_cmp(p1, p2, rqsort_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* not reentrant, but not needed with emscripten */
|
||||||
|
void rqsort(void *base, size_t nmemb, size_t size,
|
||||||
|
int (*cmp)(const void *, const void *, void *),
|
||||||
|
void *arg)
|
||||||
|
{
|
||||||
|
rqsort_arg = arg;
|
||||||
|
rqsort_cmp = cmp;
|
||||||
|
qsort(base, nmemb, size, rqsort_cmp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
typedef void (*exchange_f)(void *a, void *b, size_t size);
|
||||||
|
typedef int (*cmp_f)(const void *, const void *, void *opaque);
|
||||||
|
|
||||||
|
static void exchange_bytes(void *a, void *b, size_t size) {
|
||||||
|
uint8_t *ap = (uint8_t *)a;
|
||||||
|
uint8_t *bp = (uint8_t *)b;
|
||||||
|
|
||||||
|
while (size-- != 0) {
|
||||||
|
uint8_t t = *ap;
|
||||||
|
*ap++ = *bp;
|
||||||
|
*bp++ = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_one_byte(void *a, void *b, size_t size) {
|
||||||
|
uint8_t *ap = (uint8_t *)a;
|
||||||
|
uint8_t *bp = (uint8_t *)b;
|
||||||
|
uint8_t t = *ap;
|
||||||
|
*ap = *bp;
|
||||||
|
*bp = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_int16s(void *a, void *b, size_t size) {
|
||||||
|
uint16_t *ap = (uint16_t *)a;
|
||||||
|
uint16_t *bp = (uint16_t *)b;
|
||||||
|
|
||||||
|
for (size /= sizeof(uint16_t); size-- != 0;) {
|
||||||
|
uint16_t t = *ap;
|
||||||
|
*ap++ = *bp;
|
||||||
|
*bp++ = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_one_int16(void *a, void *b, size_t size) {
|
||||||
|
uint16_t *ap = (uint16_t *)a;
|
||||||
|
uint16_t *bp = (uint16_t *)b;
|
||||||
|
uint16_t t = *ap;
|
||||||
|
*ap = *bp;
|
||||||
|
*bp = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_int32s(void *a, void *b, size_t size) {
|
||||||
|
uint32_t *ap = (uint32_t *)a;
|
||||||
|
uint32_t *bp = (uint32_t *)b;
|
||||||
|
|
||||||
|
for (size /= sizeof(uint32_t); size-- != 0;) {
|
||||||
|
uint32_t t = *ap;
|
||||||
|
*ap++ = *bp;
|
||||||
|
*bp++ = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_one_int32(void *a, void *b, size_t size) {
|
||||||
|
uint32_t *ap = (uint32_t *)a;
|
||||||
|
uint32_t *bp = (uint32_t *)b;
|
||||||
|
uint32_t t = *ap;
|
||||||
|
*ap = *bp;
|
||||||
|
*bp = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_int64s(void *a, void *b, size_t size) {
|
||||||
|
uint64_t *ap = (uint64_t *)a;
|
||||||
|
uint64_t *bp = (uint64_t *)b;
|
||||||
|
|
||||||
|
for (size /= sizeof(uint64_t); size-- != 0;) {
|
||||||
|
uint64_t t = *ap;
|
||||||
|
*ap++ = *bp;
|
||||||
|
*bp++ = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_one_int64(void *a, void *b, size_t size) {
|
||||||
|
uint64_t *ap = (uint64_t *)a;
|
||||||
|
uint64_t *bp = (uint64_t *)b;
|
||||||
|
uint64_t t = *ap;
|
||||||
|
*ap = *bp;
|
||||||
|
*bp = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_int128s(void *a, void *b, size_t size) {
|
||||||
|
uint64_t *ap = (uint64_t *)a;
|
||||||
|
uint64_t *bp = (uint64_t *)b;
|
||||||
|
|
||||||
|
for (size /= sizeof(uint64_t) * 2; size-- != 0; ap += 2, bp += 2) {
|
||||||
|
uint64_t t = ap[0];
|
||||||
|
uint64_t u = ap[1];
|
||||||
|
ap[0] = bp[0];
|
||||||
|
ap[1] = bp[1];
|
||||||
|
bp[0] = t;
|
||||||
|
bp[1] = u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exchange_one_int128(void *a, void *b, size_t size) {
|
||||||
|
uint64_t *ap = (uint64_t *)a;
|
||||||
|
uint64_t *bp = (uint64_t *)b;
|
||||||
|
uint64_t t = ap[0];
|
||||||
|
uint64_t u = ap[1];
|
||||||
|
ap[0] = bp[0];
|
||||||
|
ap[1] = bp[1];
|
||||||
|
bp[0] = t;
|
||||||
|
bp[1] = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline exchange_f exchange_func(const void *base, size_t size) {
|
||||||
|
switch (((uintptr_t)base | (uintptr_t)size) & 15) {
|
||||||
|
case 0:
|
||||||
|
if (size == sizeof(uint64_t) * 2)
|
||||||
|
return exchange_one_int128;
|
||||||
|
else
|
||||||
|
return exchange_int128s;
|
||||||
|
case 8:
|
||||||
|
if (size == sizeof(uint64_t))
|
||||||
|
return exchange_one_int64;
|
||||||
|
else
|
||||||
|
return exchange_int64s;
|
||||||
|
case 4:
|
||||||
|
case 12:
|
||||||
|
if (size == sizeof(uint32_t))
|
||||||
|
return exchange_one_int32;
|
||||||
|
else
|
||||||
|
return exchange_int32s;
|
||||||
|
case 2:
|
||||||
|
case 6:
|
||||||
|
case 10:
|
||||||
|
case 14:
|
||||||
|
if (size == sizeof(uint16_t))
|
||||||
|
return exchange_one_int16;
|
||||||
|
else
|
||||||
|
return exchange_int16s;
|
||||||
|
default:
|
||||||
|
if (size == 1)
|
||||||
|
return exchange_one_byte;
|
||||||
|
else
|
||||||
|
return exchange_bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void heapsortx(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
|
||||||
|
{
|
||||||
|
uint8_t *basep = (uint8_t *)base;
|
||||||
|
size_t i, n, c, r;
|
||||||
|
exchange_f swap = exchange_func(base, size);
|
||||||
|
|
||||||
|
if (nmemb > 1) {
|
||||||
|
i = (nmemb / 2) * size;
|
||||||
|
n = nmemb * size;
|
||||||
|
|
||||||
|
while (i > 0) {
|
||||||
|
i -= size;
|
||||||
|
for (r = i; (c = r * 2 + size) < n; r = c) {
|
||||||
|
if (c < n - size && cmp(basep + c, basep + c + size, opaque) <= 0)
|
||||||
|
c += size;
|
||||||
|
if (cmp(basep + r, basep + c, opaque) > 0)
|
||||||
|
break;
|
||||||
|
swap(basep + r, basep + c, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = n - size; i > 0; i -= size) {
|
||||||
|
swap(basep, basep + i, size);
|
||||||
|
|
||||||
|
for (r = 0; (c = r * 2 + size) < i; r = c) {
|
||||||
|
if (c < i - size && cmp(basep + c, basep + c + size, opaque) <= 0)
|
||||||
|
c += size;
|
||||||
|
if (cmp(basep + r, basep + c, opaque) > 0)
|
||||||
|
break;
|
||||||
|
swap(basep + r, basep + c, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *med3(void *a, void *b, void *c, cmp_f cmp, void *opaque)
|
||||||
|
{
|
||||||
|
return cmp(a, b, opaque) < 0 ?
|
||||||
|
(cmp(b, c, opaque) < 0 ? b : (cmp(a, c, opaque) < 0 ? c : a )) :
|
||||||
|
(cmp(b, c, opaque) > 0 ? b : (cmp(a, c, opaque) < 0 ? a : c ));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pointer based version with local stack and insertion sort threshhold */
|
||||||
|
void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
|
||||||
|
{
|
||||||
|
struct { uint8_t *base; size_t count; int depth; } stack[50], *sp = stack;
|
||||||
|
uint8_t *ptr, *pi, *pj, *plt, *pgt, *top, *m;
|
||||||
|
size_t m4, i, lt, gt, span, span2;
|
||||||
|
int c, depth;
|
||||||
|
exchange_f swap = exchange_func(base, size);
|
||||||
|
exchange_f swap_block = exchange_func(base, size | 128);
|
||||||
|
|
||||||
|
if (nmemb < 2 || size <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sp->base = (uint8_t *)base;
|
||||||
|
sp->count = nmemb;
|
||||||
|
sp->depth = 0;
|
||||||
|
sp++;
|
||||||
|
|
||||||
|
while (sp > stack) {
|
||||||
|
sp--;
|
||||||
|
ptr = sp->base;
|
||||||
|
nmemb = sp->count;
|
||||||
|
depth = sp->depth;
|
||||||
|
|
||||||
|
while (nmemb > 6) {
|
||||||
|
if (++depth > 50) {
|
||||||
|
/* depth check to ensure worst case logarithmic time */
|
||||||
|
heapsortx(ptr, nmemb, size, cmp, opaque);
|
||||||
|
nmemb = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* select median of 3 from 1/4, 1/2, 3/4 positions */
|
||||||
|
/* should use median of 5 or 9? */
|
||||||
|
m4 = (nmemb >> 2) * size;
|
||||||
|
m = med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque);
|
||||||
|
swap(ptr, m, size); /* move the pivot to the start or the array */
|
||||||
|
i = lt = 1;
|
||||||
|
pi = plt = ptr + size;
|
||||||
|
gt = nmemb;
|
||||||
|
pj = pgt = top = ptr + nmemb * size;
|
||||||
|
for (;;) {
|
||||||
|
while (pi < pj && (c = cmp(ptr, pi, opaque)) >= 0) {
|
||||||
|
if (c == 0) {
|
||||||
|
swap(plt, pi, size);
|
||||||
|
lt++;
|
||||||
|
plt += size;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
pi += size;
|
||||||
|
}
|
||||||
|
while (pi < (pj -= size) && (c = cmp(ptr, pj, opaque)) <= 0) {
|
||||||
|
if (c == 0) {
|
||||||
|
gt--;
|
||||||
|
pgt -= size;
|
||||||
|
swap(pgt, pj, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pi >= pj)
|
||||||
|
break;
|
||||||
|
swap(pi, pj, size);
|
||||||
|
i++;
|
||||||
|
pi += size;
|
||||||
|
}
|
||||||
|
/* array has 4 parts:
|
||||||
|
* from 0 to lt excluded: elements identical to pivot
|
||||||
|
* from lt to pi excluded: elements smaller than pivot
|
||||||
|
* from pi to gt excluded: elements greater than pivot
|
||||||
|
* from gt to n excluded: elements identical to pivot
|
||||||
|
*/
|
||||||
|
/* move elements identical to pivot in the middle of the array: */
|
||||||
|
/* swap values in ranges [0..lt[ and [i-lt..i[
|
||||||
|
swapping the smallest span between lt and i-lt is sufficient
|
||||||
|
*/
|
||||||
|
span = plt - ptr;
|
||||||
|
span2 = pi - plt;
|
||||||
|
lt = i - lt;
|
||||||
|
if (span > span2)
|
||||||
|
span = span2;
|
||||||
|
swap_block(ptr, pi - span, span);
|
||||||
|
/* swap values in ranges [gt..top[ and [i..top-(top-gt)[
|
||||||
|
swapping the smallest span between top-gt and gt-i is sufficient
|
||||||
|
*/
|
||||||
|
span = top - pgt;
|
||||||
|
span2 = pgt - pi;
|
||||||
|
pgt = top - span2;
|
||||||
|
gt = nmemb - (gt - i);
|
||||||
|
if (span > span2)
|
||||||
|
span = span2;
|
||||||
|
swap_block(pi, top - span, span);
|
||||||
|
|
||||||
|
/* now array has 3 parts:
|
||||||
|
* from 0 to lt excluded: elements smaller than pivot
|
||||||
|
* from lt to gt excluded: elements identical to pivot
|
||||||
|
* from gt to n excluded: elements greater than pivot
|
||||||
|
*/
|
||||||
|
/* stack the larger segment and keep processing the smaller one
|
||||||
|
to minimize stack use for pathological distributions */
|
||||||
|
if (lt > nmemb - gt) {
|
||||||
|
sp->base = ptr;
|
||||||
|
sp->count = lt;
|
||||||
|
sp->depth = depth;
|
||||||
|
sp++;
|
||||||
|
ptr = pgt;
|
||||||
|
nmemb -= gt;
|
||||||
|
} else {
|
||||||
|
sp->base = pgt;
|
||||||
|
sp->count = nmemb - gt;
|
||||||
|
sp->depth = depth;
|
||||||
|
sp++;
|
||||||
|
nmemb = lt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Use insertion sort for small fragments */
|
||||||
|
for (pi = ptr + size, top = ptr + nmemb * size; pi < top; pi += size) {
|
||||||
|
for (pj = pi; pj > ptr && cmp(pj - size, pj, opaque) > 0; pj -= size)
|
||||||
|
swap(pj, pj - size, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
297
android/src/main/jni/quickjs/cutils.h
Normal file
297
android/src/main/jni/quickjs/cutils.h
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
/*
|
||||||
|
* C utilities
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 Fabrice Bellard
|
||||||
|
* Copyright (c) 2018 Charlie Gordon
|
||||||
|
*
|
||||||
|
* 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 CUTILS_H
|
||||||
|
#define CUTILS_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
/* set if CPU is big endian */
|
||||||
|
#undef WORDS_BIGENDIAN
|
||||||
|
|
||||||
|
#define likely(x) __builtin_expect(!!(x), 1)
|
||||||
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
|
#define force_inline inline __attribute__((always_inline))
|
||||||
|
#define no_inline __attribute__((noinline))
|
||||||
|
#define __maybe_unused __attribute__((unused))
|
||||||
|
|
||||||
|
#define xglue(x, y) x ## y
|
||||||
|
#define glue(x, y) xglue(x, y)
|
||||||
|
#define stringify(s) tostring(s)
|
||||||
|
#define tostring(s) #s
|
||||||
|
|
||||||
|
#ifndef offsetof
|
||||||
|
#define offsetof(type, field) ((size_t) &((type *)0)->field)
|
||||||
|
#endif
|
||||||
|
#ifndef countof
|
||||||
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int BOOL;
|
||||||
|
|
||||||
|
#ifndef FALSE
|
||||||
|
enum {
|
||||||
|
FALSE = 0,
|
||||||
|
TRUE = 1,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void pstrcpy(char *buf, int buf_size, const char *str);
|
||||||
|
char *pstrcat(char *buf, int buf_size, const char *s);
|
||||||
|
int strstart(const char *str, const char *val, const char **ptr);
|
||||||
|
int has_suffix(const char *str, const char *suffix);
|
||||||
|
|
||||||
|
static inline int max_int(int a, int b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int min_int(int a, int b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t max_uint32(uint32_t a, uint32_t b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t min_uint32(uint32_t a, uint32_t b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int64_t max_int64(int64_t a, int64_t b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int64_t min_int64(int64_t a, int64_t b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WARNING: undefined if a = 0 */
|
||||||
|
static inline int clz32(unsigned int a)
|
||||||
|
{
|
||||||
|
return __builtin_clz(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WARNING: undefined if a = 0 */
|
||||||
|
static inline int clz64(uint64_t a)
|
||||||
|
{
|
||||||
|
return __builtin_clzll(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WARNING: undefined if a = 0 */
|
||||||
|
static inline int ctz32(unsigned int a)
|
||||||
|
{
|
||||||
|
return __builtin_ctz(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WARNING: undefined if a = 0 */
|
||||||
|
static inline int ctz64(uint64_t a)
|
||||||
|
{
|
||||||
|
return __builtin_ctzll(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct __attribute__((packed)) packed_u64 {
|
||||||
|
uint64_t v;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __attribute__((packed)) packed_u32 {
|
||||||
|
uint32_t v;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __attribute__((packed)) packed_u16 {
|
||||||
|
uint16_t v;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline uint64_t get_u64(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return ((const struct packed_u64 *)tab)->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int64_t get_i64(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return (int64_t)((const struct packed_u64 *)tab)->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void put_u64(uint8_t *tab, uint64_t val)
|
||||||
|
{
|
||||||
|
((struct packed_u64 *)tab)->v = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t get_u32(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return ((const struct packed_u32 *)tab)->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int32_t get_i32(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return (int32_t)((const struct packed_u32 *)tab)->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void put_u32(uint8_t *tab, uint32_t val)
|
||||||
|
{
|
||||||
|
((struct packed_u32 *)tab)->v = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t get_u16(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return ((const struct packed_u16 *)tab)->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int32_t get_i16(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return (int16_t)((const struct packed_u16 *)tab)->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void put_u16(uint8_t *tab, uint16_t val)
|
||||||
|
{
|
||||||
|
((struct packed_u16 *)tab)->v = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t get_u8(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return *tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int32_t get_i8(const uint8_t *tab)
|
||||||
|
{
|
||||||
|
return (int8_t)*tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void put_u8(uint8_t *tab, uint8_t val)
|
||||||
|
{
|
||||||
|
*tab = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint16_t bswap16(uint16_t x)
|
||||||
|
{
|
||||||
|
return (x >> 8) | (x << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t bswap32(uint32_t v)
|
||||||
|
{
|
||||||
|
return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
|
||||||
|
((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t bswap64(uint64_t v)
|
||||||
|
{
|
||||||
|
return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) |
|
||||||
|
((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX: should take an extra argument to pass slack information to the caller */
|
||||||
|
typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);
|
||||||
|
|
||||||
|
typedef struct DynBuf {
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t size;
|
||||||
|
size_t allocated_size;
|
||||||
|
BOOL error; /* true if a memory allocation error occurred */
|
||||||
|
DynBufReallocFunc *realloc_func;
|
||||||
|
void *opaque; /* for realloc_func */
|
||||||
|
} DynBuf;
|
||||||
|
|
||||||
|
void dbuf_init(DynBuf *s);
|
||||||
|
void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);
|
||||||
|
int dbuf_realloc(DynBuf *s, size_t new_size);
|
||||||
|
int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len);
|
||||||
|
int dbuf_put(DynBuf *s, const uint8_t *data, size_t len);
|
||||||
|
int dbuf_put_self(DynBuf *s, size_t offset, size_t len);
|
||||||
|
int dbuf_putc(DynBuf *s, uint8_t c);
|
||||||
|
int dbuf_putstr(DynBuf *s, const char *str);
|
||||||
|
static inline int dbuf_put_u16(DynBuf *s, uint16_t val)
|
||||||
|
{
|
||||||
|
return dbuf_put(s, (uint8_t *)&val, 2);
|
||||||
|
}
|
||||||
|
static inline int dbuf_put_u32(DynBuf *s, uint32_t val)
|
||||||
|
{
|
||||||
|
return dbuf_put(s, (uint8_t *)&val, 4);
|
||||||
|
}
|
||||||
|
static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
|
||||||
|
{
|
||||||
|
return dbuf_put(s, (uint8_t *)&val, 8);
|
||||||
|
}
|
||||||
|
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
|
||||||
|
const char *fmt, ...);
|
||||||
|
void dbuf_free(DynBuf *s);
|
||||||
|
static inline BOOL dbuf_error(DynBuf *s) {
|
||||||
|
return s->error;
|
||||||
|
}
|
||||||
|
static inline void dbuf_set_error(DynBuf *s)
|
||||||
|
{
|
||||||
|
s->error = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define UTF8_CHAR_LEN_MAX 6
|
||||||
|
|
||||||
|
int unicode_to_utf8(uint8_t *buf, unsigned int c);
|
||||||
|
int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp);
|
||||||
|
|
||||||
|
static inline int from_hex(int c)
|
||||||
|
{
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
return c - '0';
|
||||||
|
else if (c >= 'A' && c <= 'F')
|
||||||
|
return c - 'A' + 10;
|
||||||
|
else if (c >= 'a' && c <= 'f')
|
||||||
|
return c - 'a' + 10;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rqsort(void *base, size_t nmemb, size_t size,
|
||||||
|
int (*cmp)(const void *, const void *, void *),
|
||||||
|
void *arg);
|
||||||
|
|
||||||
|
#endif /* CUTILS_H */
|
58
android/src/main/jni/quickjs/libregexp-opcode.h
Normal file
58
android/src/main/jni/quickjs/libregexp-opcode.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Regular Expression Engine
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018 Fabrice Bellard
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef DEF
|
||||||
|
|
||||||
|
DEF(invalid, 1) /* never used */
|
||||||
|
DEF(char, 3)
|
||||||
|
DEF(char32, 5)
|
||||||
|
DEF(dot, 1)
|
||||||
|
DEF(any, 1) /* same as dot but match any character including line terminator */
|
||||||
|
DEF(line_start, 1)
|
||||||
|
DEF(line_end, 1)
|
||||||
|
DEF(goto, 5)
|
||||||
|
DEF(split_goto_first, 5)
|
||||||
|
DEF(split_next_first, 5)
|
||||||
|
DEF(match, 1)
|
||||||
|
DEF(save_start, 2) /* save start position */
|
||||||
|
DEF(save_end, 2) /* save end position, must come after saved_start */
|
||||||
|
DEF(save_reset, 3) /* reset save positions */
|
||||||
|
DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
|
||||||
|
DEF(push_i32, 5) /* push integer on the stack */
|
||||||
|
DEF(drop, 1)
|
||||||
|
DEF(word_boundary, 1)
|
||||||
|
DEF(not_word_boundary, 1)
|
||||||
|
DEF(back_reference, 2)
|
||||||
|
DEF(backward_back_reference, 2) /* must come after back_reference */
|
||||||
|
DEF(range, 3) /* variable length */
|
||||||
|
DEF(range32, 3) /* variable length */
|
||||||
|
DEF(lookahead, 5)
|
||||||
|
DEF(negative_lookahead, 5)
|
||||||
|
DEF(push_char_pos, 1) /* push the character position on the stack */
|
||||||
|
DEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character
|
||||||
|
position */
|
||||||
|
DEF(prev, 1) /* go to the previous char */
|
||||||
|
DEF(simple_greedy_quant, 17)
|
||||||
|
|
||||||
|
#endif /* DEF */
|
2588
android/src/main/jni/quickjs/libregexp.c
Normal file
2588
android/src/main/jni/quickjs/libregexp.c
Normal file
File diff suppressed because it is too large
Load Diff
91
android/src/main/jni/quickjs/libregexp.h
Normal file
91
android/src/main/jni/quickjs/libregexp.h
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Regular Expression Engine
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018 Fabrice Bellard
|
||||||
|
*
|
||||||
|
* 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 LIBREGEXP_H
|
||||||
|
#define LIBREGEXP_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "libunicode.h"
|
||||||
|
|
||||||
|
#define LRE_BOOL int /* for documentation purposes */
|
||||||
|
|
||||||
|
#define LRE_FLAG_GLOBAL (1 << 0)
|
||||||
|
#define LRE_FLAG_IGNORECASE (1 << 1)
|
||||||
|
#define LRE_FLAG_MULTILINE (1 << 2)
|
||||||
|
#define LRE_FLAG_DOTALL (1 << 3)
|
||||||
|
#define LRE_FLAG_UTF16 (1 << 4)
|
||||||
|
#define LRE_FLAG_STICKY (1 << 5)
|
||||||
|
|
||||||
|
#define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */
|
||||||
|
|
||||||
|
uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
|
||||||
|
const char *buf, size_t buf_len, int re_flags,
|
||||||
|
void *opaque);
|
||||||
|
int lre_get_capture_count(const uint8_t *bc_buf);
|
||||||
|
int lre_get_flags(const uint8_t *bc_buf);
|
||||||
|
int lre_exec(uint8_t **capture,
|
||||||
|
const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen,
|
||||||
|
int cbuf_type, void *opaque);
|
||||||
|
|
||||||
|
int lre_parse_escape(const uint8_t **pp, int allow_utf16);
|
||||||
|
LRE_BOOL lre_is_space(int c);
|
||||||
|
|
||||||
|
/* must be provided by the user */
|
||||||
|
LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size);
|
||||||
|
void *lre_realloc(void *opaque, void *ptr, size_t size);
|
||||||
|
|
||||||
|
/* JS identifier test */
|
||||||
|
extern uint32_t const lre_id_start_table_ascii[4];
|
||||||
|
extern uint32_t const lre_id_continue_table_ascii[4];
|
||||||
|
|
||||||
|
static inline int lre_js_is_ident_first(int c)
|
||||||
|
{
|
||||||
|
if ((uint32_t)c < 128) {
|
||||||
|
return (lre_id_start_table_ascii[c >> 5] >> (c & 31)) & 1;
|
||||||
|
} else {
|
||||||
|
#ifdef CONFIG_ALL_UNICODE
|
||||||
|
return lre_is_id_start(c);
|
||||||
|
#else
|
||||||
|
return !lre_is_space(c);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int lre_js_is_ident_next(int c)
|
||||||
|
{
|
||||||
|
if ((uint32_t)c < 128) {
|
||||||
|
return (lre_id_continue_table_ascii[c >> 5] >> (c & 31)) & 1;
|
||||||
|
} else {
|
||||||
|
/* ZWNJ and ZWJ are accepted in identifiers */
|
||||||
|
#ifdef CONFIG_ALL_UNICODE
|
||||||
|
return lre_is_id_continue(c) || c == 0x200C || c == 0x200D;
|
||||||
|
#else
|
||||||
|
return !lre_is_space(c) || c == 0x200C || c == 0x200D;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef LRE_BOOL
|
||||||
|
|
||||||
|
#endif /* LIBREGEXP_H */
|
4368
android/src/main/jni/quickjs/libunicode-table.h
Normal file
4368
android/src/main/jni/quickjs/libunicode-table.h
Normal file
File diff suppressed because it is too large
Load Diff
1538
android/src/main/jni/quickjs/libunicode.c
Normal file
1538
android/src/main/jni/quickjs/libunicode.c
Normal file
File diff suppressed because it is too large
Load Diff
124
android/src/main/jni/quickjs/libunicode.h
Normal file
124
android/src/main/jni/quickjs/libunicode.h
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Unicode utilities
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018 Fabrice Bellard
|
||||||
|
*
|
||||||
|
* 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 LIBUNICODE_H
|
||||||
|
#define LIBUNICODE_H
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define LRE_BOOL int /* for documentation purposes */
|
||||||
|
|
||||||
|
/* define it to include all the unicode tables (40KB larger) */
|
||||||
|
#define CONFIG_ALL_UNICODE
|
||||||
|
|
||||||
|
#define LRE_CC_RES_LEN_MAX 3
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UNICODE_NFC,
|
||||||
|
UNICODE_NFD,
|
||||||
|
UNICODE_NFKC,
|
||||||
|
UNICODE_NFKD,
|
||||||
|
} UnicodeNormalizationEnum;
|
||||||
|
|
||||||
|
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type);
|
||||||
|
LRE_BOOL lre_is_cased(uint32_t c);
|
||||||
|
LRE_BOOL lre_is_case_ignorable(uint32_t c);
|
||||||
|
|
||||||
|
/* char ranges */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int len; /* in points, always even */
|
||||||
|
int size;
|
||||||
|
uint32_t *points; /* points sorted by increasing value */
|
||||||
|
void *mem_opaque;
|
||||||
|
void *(*realloc_func)(void *opaque, void *ptr, size_t size);
|
||||||
|
} CharRange;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CR_OP_UNION,
|
||||||
|
CR_OP_INTER,
|
||||||
|
CR_OP_XOR,
|
||||||
|
} CharRangeOpEnum;
|
||||||
|
|
||||||
|
void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
|
||||||
|
void cr_free(CharRange *cr);
|
||||||
|
int cr_realloc(CharRange *cr, int size);
|
||||||
|
int cr_copy(CharRange *cr, const CharRange *cr1);
|
||||||
|
|
||||||
|
static inline int cr_add_point(CharRange *cr, uint32_t v)
|
||||||
|
{
|
||||||
|
if (cr->len >= cr->size) {
|
||||||
|
if (cr_realloc(cr, cr->len + 1))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
cr->points[cr->len++] = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2)
|
||||||
|
{
|
||||||
|
if ((cr->len + 2) > cr->size) {
|
||||||
|
if (cr_realloc(cr, cr->len + 2))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
cr->points[cr->len++] = c1;
|
||||||
|
cr->points[cr->len++] = c2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len);
|
||||||
|
|
||||||
|
static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2)
|
||||||
|
{
|
||||||
|
uint32_t b_pt[2];
|
||||||
|
b_pt[0] = c1;
|
||||||
|
b_pt[1] = c2 + 1;
|
||||||
|
return cr_union1(cr, b_pt, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
|
||||||
|
const uint32_t *b_pt, int b_len, int op);
|
||||||
|
|
||||||
|
int cr_invert(CharRange *cr);
|
||||||
|
|
||||||
|
#ifdef CONFIG_ALL_UNICODE
|
||||||
|
|
||||||
|
LRE_BOOL lre_is_id_start(uint32_t c);
|
||||||
|
LRE_BOOL lre_is_id_continue(uint32_t c);
|
||||||
|
|
||||||
|
int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
|
||||||
|
UnicodeNormalizationEnum n_type,
|
||||||
|
void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
|
||||||
|
|
||||||
|
/* Unicode character range functions */
|
||||||
|
|
||||||
|
int unicode_script(CharRange *cr,
|
||||||
|
const char *script_name, LRE_BOOL is_ext);
|
||||||
|
int unicode_general_category(CharRange *cr, const char *gc_name);
|
||||||
|
int unicode_prop(CharRange *cr, const char *prop_name);
|
||||||
|
|
||||||
|
#endif /* CONFIG_ALL_UNICODE */
|
||||||
|
|
||||||
|
#undef LRE_BOOL
|
||||||
|
|
||||||
|
#endif /* LIBUNICODE_H */
|
100
android/src/main/jni/quickjs/list.h
Normal file
100
android/src/main/jni/quickjs/list.h
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Linux klist like system
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2017 Fabrice Bellard
|
||||||
|
*
|
||||||
|
* 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 LIST_H
|
||||||
|
#define LIST_H
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#include <stddef.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct list_head {
|
||||||
|
struct list_head *prev;
|
||||||
|
struct list_head *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define LIST_HEAD_INIT(el) { &(el), &(el) }
|
||||||
|
|
||||||
|
/* return the pointer of type 'type *' containing 'el' as field 'member' */
|
||||||
|
#define list_entry(el, type, member) \
|
||||||
|
((type *)((uint8_t *)(el) - offsetof(type, member)))
|
||||||
|
|
||||||
|
static inline void init_list_head(struct list_head *head)
|
||||||
|
{
|
||||||
|
head->prev = head;
|
||||||
|
head->next = head;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* insert 'el' between 'prev' and 'next' */
|
||||||
|
static inline void __list_add(struct list_head *el,
|
||||||
|
struct list_head *prev, struct list_head *next)
|
||||||
|
{
|
||||||
|
prev->next = el;
|
||||||
|
el->prev = prev;
|
||||||
|
el->next = next;
|
||||||
|
next->prev = el;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add 'el' at the head of the list 'head' (= after element head) */
|
||||||
|
static inline void list_add(struct list_head *el, struct list_head *head)
|
||||||
|
{
|
||||||
|
__list_add(el, head, head->next);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add 'el' at the end of the list 'head' (= before element head) */
|
||||||
|
static inline void list_add_tail(struct list_head *el, struct list_head *head)
|
||||||
|
{
|
||||||
|
__list_add(el, head->prev, head);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void list_del(struct list_head *el)
|
||||||
|
{
|
||||||
|
struct list_head *prev, *next;
|
||||||
|
prev = el->prev;
|
||||||
|
next = el->next;
|
||||||
|
prev->next = next;
|
||||||
|
next->prev = prev;
|
||||||
|
el->prev = NULL; /* fail safe */
|
||||||
|
el->next = NULL; /* fail safe */
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int list_empty(struct list_head *el)
|
||||||
|
{
|
||||||
|
return el->next == el;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define list_for_each(el, head) \
|
||||||
|
for(el = (head)->next; el != (head); el = el->next)
|
||||||
|
|
||||||
|
#define list_for_each_safe(el, el1, head) \
|
||||||
|
for(el = (head)->next, el1 = el->next; el != (head); \
|
||||||
|
el = el1, el1 = el->next)
|
||||||
|
|
||||||
|
#define list_for_each_prev(el, head) \
|
||||||
|
for(el = (head)->prev; el != (head); el = el->prev)
|
||||||
|
|
||||||
|
#define list_for_each_prev_safe(el, el1, head) \
|
||||||
|
for(el = (head)->prev, el1 = el->prev; el != (head); \
|
||||||
|
el = el1, el1 = el->prev)
|
||||||
|
|
||||||
|
#endif /* LIST_H */
|
272
android/src/main/jni/quickjs/quickjs-atom.h
Normal file
272
android/src/main/jni/quickjs/quickjs-atom.h
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
/*
|
||||||
|
* QuickJS atom definitions
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018 Fabrice Bellard
|
||||||
|
* Copyright (c) 2017-2018 Charlie Gordon
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef DEF
|
||||||
|
|
||||||
|
/* Note: first atoms are considered as keywords in the parser */
|
||||||
|
DEF(null, "null") /* must be first */
|
||||||
|
DEF(false, "false")
|
||||||
|
DEF(true, "true")
|
||||||
|
DEF(if, "if")
|
||||||
|
DEF(else, "else")
|
||||||
|
DEF(return, "return")
|
||||||
|
DEF(var, "var")
|
||||||
|
DEF(this, "this")
|
||||||
|
DEF(delete, "delete")
|
||||||
|
DEF(void, "void")
|
||||||
|
DEF(typeof, "typeof")
|
||||||
|
DEF(new, "new")
|
||||||
|
DEF(in, "in")
|
||||||
|
DEF(instanceof, "instanceof")
|
||||||
|
DEF(do, "do")
|
||||||
|
DEF(while, "while")
|
||||||
|
DEF(for, "for")
|
||||||
|
DEF(break, "break")
|
||||||
|
DEF(continue, "continue")
|
||||||
|
DEF(switch, "switch")
|
||||||
|
DEF(case, "case")
|
||||||
|
DEF(default, "default")
|
||||||
|
DEF(throw, "throw")
|
||||||
|
DEF(try, "try")
|
||||||
|
DEF(catch, "catch")
|
||||||
|
DEF(finally, "finally")
|
||||||
|
DEF(function, "function")
|
||||||
|
DEF(debugger, "debugger")
|
||||||
|
DEF(with, "with")
|
||||||
|
/* FutureReservedWord */
|
||||||
|
DEF(class, "class")
|
||||||
|
DEF(const, "const")
|
||||||
|
DEF(enum, "enum")
|
||||||
|
DEF(export, "export")
|
||||||
|
DEF(extends, "extends")
|
||||||
|
DEF(import, "import")
|
||||||
|
DEF(super, "super")
|
||||||
|
/* FutureReservedWords when parsing strict mode code */
|
||||||
|
DEF(implements, "implements")
|
||||||
|
DEF(interface, "interface")
|
||||||
|
DEF(let, "let")
|
||||||
|
DEF(package, "package")
|
||||||
|
DEF(private, "private")
|
||||||
|
DEF(protected, "protected")
|
||||||
|
DEF(public, "public")
|
||||||
|
DEF(static, "static")
|
||||||
|
DEF(yield, "yield")
|
||||||
|
DEF(await, "await")
|
||||||
|
|
||||||
|
/* empty string */
|
||||||
|
DEF(empty_string, "")
|
||||||
|
/* identifiers */
|
||||||
|
DEF(length, "length")
|
||||||
|
DEF(fileName, "fileName")
|
||||||
|
DEF(lineNumber, "lineNumber")
|
||||||
|
DEF(message, "message")
|
||||||
|
DEF(errors, "errors")
|
||||||
|
DEF(stack, "stack")
|
||||||
|
DEF(name, "name")
|
||||||
|
DEF(toString, "toString")
|
||||||
|
DEF(toLocaleString, "toLocaleString")
|
||||||
|
DEF(valueOf, "valueOf")
|
||||||
|
DEF(eval, "eval")
|
||||||
|
DEF(prototype, "prototype")
|
||||||
|
DEF(constructor, "constructor")
|
||||||
|
DEF(configurable, "configurable")
|
||||||
|
DEF(writable, "writable")
|
||||||
|
DEF(enumerable, "enumerable")
|
||||||
|
DEF(value, "value")
|
||||||
|
DEF(get, "get")
|
||||||
|
DEF(set, "set")
|
||||||
|
DEF(of, "of")
|
||||||
|
DEF(__proto__, "__proto__")
|
||||||
|
DEF(undefined, "undefined")
|
||||||
|
DEF(number, "number")
|
||||||
|
DEF(boolean, "boolean")
|
||||||
|
DEF(string, "string")
|
||||||
|
DEF(object, "object")
|
||||||
|
DEF(symbol, "symbol")
|
||||||
|
DEF(integer, "integer")
|
||||||
|
DEF(unknown, "unknown")
|
||||||
|
DEF(arguments, "arguments")
|
||||||
|
DEF(callee, "callee")
|
||||||
|
DEF(caller, "caller")
|
||||||
|
DEF(_eval_, "<eval>")
|
||||||
|
DEF(_ret_, "<ret>")
|
||||||
|
DEF(_var_, "<var>")
|
||||||
|
DEF(_with_, "<with>")
|
||||||
|
DEF(lastIndex, "lastIndex")
|
||||||
|
DEF(target, "target")
|
||||||
|
DEF(index, "index")
|
||||||
|
DEF(input, "input")
|
||||||
|
DEF(defineProperties, "defineProperties")
|
||||||
|
DEF(apply, "apply")
|
||||||
|
DEF(join, "join")
|
||||||
|
DEF(concat, "concat")
|
||||||
|
DEF(split, "split")
|
||||||
|
DEF(construct, "construct")
|
||||||
|
DEF(getPrototypeOf, "getPrototypeOf")
|
||||||
|
DEF(setPrototypeOf, "setPrototypeOf")
|
||||||
|
DEF(isExtensible, "isExtensible")
|
||||||
|
DEF(preventExtensions, "preventExtensions")
|
||||||
|
DEF(has, "has")
|
||||||
|
DEF(deleteProperty, "deleteProperty")
|
||||||
|
DEF(defineProperty, "defineProperty")
|
||||||
|
DEF(getOwnPropertyDescriptor, "getOwnPropertyDescriptor")
|
||||||
|
DEF(ownKeys, "ownKeys")
|
||||||
|
DEF(add, "add")
|
||||||
|
DEF(done, "done")
|
||||||
|
DEF(next, "next")
|
||||||
|
DEF(values, "values")
|
||||||
|
DEF(source, "source")
|
||||||
|
DEF(flags, "flags")
|
||||||
|
DEF(global, "global")
|
||||||
|
DEF(unicode, "unicode")
|
||||||
|
DEF(raw, "raw")
|
||||||
|
DEF(new_target, "new.target")
|
||||||
|
DEF(this_active_func, "this.active_func")
|
||||||
|
DEF(home_object, "<home_object>")
|
||||||
|
DEF(computed_field, "<computed_field>")
|
||||||
|
DEF(static_computed_field, "<static_computed_field>") /* must come after computed_fields */
|
||||||
|
DEF(class_fields_init, "<class_fields_init>")
|
||||||
|
DEF(brand, "<brand>")
|
||||||
|
DEF(hash_constructor, "#constructor")
|
||||||
|
DEF(as, "as")
|
||||||
|
DEF(from, "from")
|
||||||
|
DEF(meta, "meta")
|
||||||
|
DEF(_default_, "*default*")
|
||||||
|
DEF(_star_, "*")
|
||||||
|
DEF(Module, "Module")
|
||||||
|
DEF(then, "then")
|
||||||
|
DEF(resolve, "resolve")
|
||||||
|
DEF(reject, "reject")
|
||||||
|
DEF(promise, "promise")
|
||||||
|
DEF(proxy, "proxy")
|
||||||
|
DEF(revoke, "revoke")
|
||||||
|
DEF(async, "async")
|
||||||
|
DEF(exec, "exec")
|
||||||
|
DEF(groups, "groups")
|
||||||
|
DEF(status, "status")
|
||||||
|
DEF(reason, "reason")
|
||||||
|
DEF(globalThis, "globalThis")
|
||||||
|
#ifdef CONFIG_BIGNUM
|
||||||
|
DEF(bigint, "bigint")
|
||||||
|
DEF(bigfloat, "bigfloat")
|
||||||
|
DEF(bigdecimal, "bigdecimal")
|
||||||
|
DEF(roundingMode, "roundingMode")
|
||||||
|
DEF(maximumSignificantDigits, "maximumSignificantDigits")
|
||||||
|
DEF(maximumFractionDigits, "maximumFractionDigits")
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_ATOMICS
|
||||||
|
DEF(not_equal, "not-equal")
|
||||||
|
DEF(timed_out, "timed-out")
|
||||||
|
DEF(ok, "ok")
|
||||||
|
#endif
|
||||||
|
DEF(toJSON, "toJSON")
|
||||||
|
/* class names */
|
||||||
|
DEF(Object, "Object")
|
||||||
|
DEF(Array, "Array")
|
||||||
|
DEF(Error, "Error")
|
||||||
|
DEF(Number, "Number")
|
||||||
|
DEF(String, "String")
|
||||||
|
DEF(Boolean, "Boolean")
|
||||||
|
DEF(Symbol, "Symbol")
|
||||||
|
DEF(Arguments, "Arguments")
|
||||||
|
DEF(Math, "Math")
|
||||||
|
DEF(JSON, "JSON")
|
||||||
|
DEF(Date, "Date")
|
||||||
|
DEF(Function, "Function")
|
||||||
|
DEF(GeneratorFunction, "GeneratorFunction")
|
||||||
|
DEF(ForInIterator, "ForInIterator")
|
||||||
|
DEF(RegExp, "RegExp")
|
||||||
|
DEF(ArrayBuffer, "ArrayBuffer")
|
||||||
|
DEF(SharedArrayBuffer, "SharedArrayBuffer")
|
||||||
|
/* must keep same order as class IDs for typed arrays */
|
||||||
|
DEF(Uint8ClampedArray, "Uint8ClampedArray")
|
||||||
|
DEF(Int8Array, "Int8Array")
|
||||||
|
DEF(Uint8Array, "Uint8Array")
|
||||||
|
DEF(Int16Array, "Int16Array")
|
||||||
|
DEF(Uint16Array, "Uint16Array")
|
||||||
|
DEF(Int32Array, "Int32Array")
|
||||||
|
DEF(Uint32Array, "Uint32Array")
|
||||||
|
#ifdef CONFIG_BIGNUM
|
||||||
|
DEF(BigInt64Array, "BigInt64Array")
|
||||||
|
DEF(BigUint64Array, "BigUint64Array")
|
||||||
|
#endif
|
||||||
|
DEF(Float32Array, "Float32Array")
|
||||||
|
DEF(Float64Array, "Float64Array")
|
||||||
|
DEF(DataView, "DataView")
|
||||||
|
#ifdef CONFIG_BIGNUM
|
||||||
|
DEF(BigInt, "BigInt")
|
||||||
|
DEF(BigFloat, "BigFloat")
|
||||||
|
DEF(BigFloatEnv, "BigFloatEnv")
|
||||||
|
DEF(BigDecimal, "BigDecimal")
|
||||||
|
DEF(OperatorSet, "OperatorSet")
|
||||||
|
DEF(Operators, "Operators")
|
||||||
|
#endif
|
||||||
|
DEF(Map, "Map")
|
||||||
|
DEF(Set, "Set") /* Map + 1 */
|
||||||
|
DEF(WeakMap, "WeakMap") /* Map + 2 */
|
||||||
|
DEF(WeakSet, "WeakSet") /* Map + 3 */
|
||||||
|
DEF(Map_Iterator, "Map Iterator")
|
||||||
|
DEF(Set_Iterator, "Set Iterator")
|
||||||
|
DEF(Array_Iterator, "Array Iterator")
|
||||||
|
DEF(String_Iterator, "String Iterator")
|
||||||
|
DEF(RegExp_String_Iterator, "RegExp String Iterator")
|
||||||
|
DEF(Generator, "Generator")
|
||||||
|
DEF(Proxy, "Proxy")
|
||||||
|
DEF(Promise, "Promise")
|
||||||
|
DEF(PromiseResolveFunction, "PromiseResolveFunction")
|
||||||
|
DEF(PromiseRejectFunction, "PromiseRejectFunction")
|
||||||
|
DEF(AsyncFunction, "AsyncFunction")
|
||||||
|
DEF(AsyncFunctionResolve, "AsyncFunctionResolve")
|
||||||
|
DEF(AsyncFunctionReject, "AsyncFunctionReject")
|
||||||
|
DEF(AsyncGeneratorFunction, "AsyncGeneratorFunction")
|
||||||
|
DEF(AsyncGenerator, "AsyncGenerator")
|
||||||
|
DEF(EvalError, "EvalError")
|
||||||
|
DEF(RangeError, "RangeError")
|
||||||
|
DEF(ReferenceError, "ReferenceError")
|
||||||
|
DEF(SyntaxError, "SyntaxError")
|
||||||
|
DEF(TypeError, "TypeError")
|
||||||
|
DEF(URIError, "URIError")
|
||||||
|
DEF(InternalError, "InternalError")
|
||||||
|
/* private symbols */
|
||||||
|
DEF(Private_brand, "<brand>")
|
||||||
|
/* symbols */
|
||||||
|
DEF(Symbol_toPrimitive, "Symbol.toPrimitive")
|
||||||
|
DEF(Symbol_iterator, "Symbol.iterator")
|
||||||
|
DEF(Symbol_match, "Symbol.match")
|
||||||
|
DEF(Symbol_matchAll, "Symbol.matchAll")
|
||||||
|
DEF(Symbol_replace, "Symbol.replace")
|
||||||
|
DEF(Symbol_search, "Symbol.search")
|
||||||
|
DEF(Symbol_split, "Symbol.split")
|
||||||
|
DEF(Symbol_toStringTag, "Symbol.toStringTag")
|
||||||
|
DEF(Symbol_isConcatSpreadable, "Symbol.isConcatSpreadable")
|
||||||
|
DEF(Symbol_hasInstance, "Symbol.hasInstance")
|
||||||
|
DEF(Symbol_species, "Symbol.species")
|
||||||
|
DEF(Symbol_unscopables, "Symbol.unscopables")
|
||||||
|
DEF(Symbol_asyncIterator, "Symbol.asyncIterator")
|
||||||
|
#ifdef CONFIG_BIGNUM
|
||||||
|
DEF(Symbol_operatorSet, "Symbol.operatorSet")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* DEF */
|
367
android/src/main/jni/quickjs/quickjs-opcode.h
Normal file
367
android/src/main/jni/quickjs/quickjs-opcode.h
Normal file
@@ -0,0 +1,367 @@
|
|||||||
|
/*
|
||||||
|
* QuickJS opcode definitions
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018 Fabrice Bellard
|
||||||
|
* Copyright (c) 2017-2018 Charlie Gordon
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef FMT
|
||||||
|
FMT(none)
|
||||||
|
FMT(none_int)
|
||||||
|
FMT(none_loc)
|
||||||
|
FMT(none_arg)
|
||||||
|
FMT(none_var_ref)
|
||||||
|
FMT(u8)
|
||||||
|
FMT(i8)
|
||||||
|
FMT(loc8)
|
||||||
|
FMT(const8)
|
||||||
|
FMT(label8)
|
||||||
|
FMT(u16)
|
||||||
|
FMT(i16)
|
||||||
|
FMT(label16)
|
||||||
|
FMT(npop)
|
||||||
|
FMT(npopx)
|
||||||
|
FMT(npop_u16)
|
||||||
|
FMT(loc)
|
||||||
|
FMT(arg)
|
||||||
|
FMT(var_ref)
|
||||||
|
FMT(u32)
|
||||||
|
FMT(i32)
|
||||||
|
FMT(const)
|
||||||
|
FMT(label)
|
||||||
|
FMT(atom)
|
||||||
|
FMT(atom_u8)
|
||||||
|
FMT(atom_u16)
|
||||||
|
FMT(atom_label_u8)
|
||||||
|
FMT(atom_label_u16)
|
||||||
|
FMT(label_u16)
|
||||||
|
#undef FMT
|
||||||
|
#endif /* FMT */
|
||||||
|
|
||||||
|
#ifdef DEF
|
||||||
|
|
||||||
|
#ifndef def
|
||||||
|
#define def(id, size, n_pop, n_push, f) DEF(id, size, n_pop, n_push, f)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DEF(invalid, 1, 0, 0, none) /* never emitted */
|
||||||
|
|
||||||
|
/* push values */
|
||||||
|
DEF( push_i32, 5, 0, 1, i32)
|
||||||
|
DEF( push_const, 5, 0, 1, const)
|
||||||
|
DEF( fclosure, 5, 0, 1, const) /* must follow push_const */
|
||||||
|
DEF(push_atom_value, 5, 0, 1, atom)
|
||||||
|
DEF( private_symbol, 5, 0, 1, atom)
|
||||||
|
DEF( undefined, 1, 0, 1, none)
|
||||||
|
DEF( null, 1, 0, 1, none)
|
||||||
|
DEF( push_this, 1, 0, 1, none) /* only used at the start of a function */
|
||||||
|
DEF( push_false, 1, 0, 1, none)
|
||||||
|
DEF( push_true, 1, 0, 1, none)
|
||||||
|
DEF( object, 1, 0, 1, none)
|
||||||
|
DEF( special_object, 2, 0, 1, u8) /* only used at the start of a function */
|
||||||
|
DEF( rest, 3, 0, 1, u16) /* only used at the start of a function */
|
||||||
|
|
||||||
|
DEF( drop, 1, 1, 0, none) /* a -> */
|
||||||
|
DEF( nip, 1, 2, 1, none) /* a b -> b */
|
||||||
|
DEF( nip1, 1, 3, 2, none) /* a b c -> b c */
|
||||||
|
DEF( dup, 1, 1, 2, none) /* a -> a a */
|
||||||
|
DEF( dup1, 1, 2, 3, none) /* a b -> a a b */
|
||||||
|
DEF( dup2, 1, 2, 4, none) /* a b -> a b a b */
|
||||||
|
DEF( dup3, 1, 3, 6, none) /* a b c -> a b c a b c */
|
||||||
|
DEF( insert2, 1, 2, 3, none) /* obj a -> a obj a (dup_x1) */
|
||||||
|
DEF( insert3, 1, 3, 4, none) /* obj prop a -> a obj prop a (dup_x2) */
|
||||||
|
DEF( insert4, 1, 4, 5, none) /* this obj prop a -> a this obj prop a */
|
||||||
|
DEF( perm3, 1, 3, 3, none) /* obj a b -> a obj b */
|
||||||
|
DEF( perm4, 1, 4, 4, none) /* obj prop a b -> a obj prop b */
|
||||||
|
DEF( perm5, 1, 5, 5, none) /* this obj prop a b -> a this obj prop b */
|
||||||
|
DEF( swap, 1, 2, 2, none) /* a b -> b a */
|
||||||
|
DEF( swap2, 1, 4, 4, none) /* a b c d -> c d a b */
|
||||||
|
DEF( rot3l, 1, 3, 3, none) /* x a b -> a b x */
|
||||||
|
DEF( rot3r, 1, 3, 3, none) /* a b x -> x a b */
|
||||||
|
DEF( rot4l, 1, 4, 4, none) /* x a b c -> a b c x */
|
||||||
|
DEF( rot5l, 1, 5, 5, none) /* x a b c d -> a b c d x */
|
||||||
|
|
||||||
|
DEF(call_constructor, 3, 2, 1, npop) /* func new.target args -> ret. arguments are not counted in n_pop */
|
||||||
|
DEF( call, 3, 1, 1, npop) /* arguments are not counted in n_pop */
|
||||||
|
DEF( tail_call, 3, 1, 0, npop) /* arguments are not counted in n_pop */
|
||||||
|
DEF( call_method, 3, 2, 1, npop) /* arguments are not counted in n_pop */
|
||||||
|
DEF(tail_call_method, 3, 2, 0, npop) /* arguments are not counted in n_pop */
|
||||||
|
DEF( array_from, 3, 0, 1, npop) /* arguments are not counted in n_pop */
|
||||||
|
DEF( apply, 3, 3, 1, u16)
|
||||||
|
DEF( return, 1, 1, 0, none)
|
||||||
|
DEF( return_undef, 1, 0, 0, none)
|
||||||
|
DEF(check_ctor_return, 1, 1, 2, none)
|
||||||
|
DEF( check_ctor, 1, 0, 0, none)
|
||||||
|
DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */
|
||||||
|
DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */
|
||||||
|
DEF( return_async, 1, 1, 0, none)
|
||||||
|
DEF( throw, 1, 1, 0, none)
|
||||||
|
DEF( throw_var, 6, 0, 0, atom_u8)
|
||||||
|
DEF( eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */
|
||||||
|
DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */
|
||||||
|
DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a
|
||||||
|
bytecode string */
|
||||||
|
DEF( get_super, 1, 1, 1, none)
|
||||||
|
DEF( import, 1, 1, 1, none) /* dynamic module import */
|
||||||
|
|
||||||
|
DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */
|
||||||
|
DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */
|
||||||
|
DEF( get_var, 5, 0, 1, atom) /* throw an exception if the variable does not exist */
|
||||||
|
DEF( put_var, 5, 1, 0, atom) /* must come after get_var */
|
||||||
|
DEF( put_var_init, 5, 1, 0, atom) /* must come after put_var. Used to initialize a global lexical variable */
|
||||||
|
DEF( put_var_strict, 5, 2, 0, atom) /* for strict mode variable write */
|
||||||
|
|
||||||
|
DEF( get_ref_value, 1, 2, 3, none)
|
||||||
|
DEF( put_ref_value, 1, 3, 0, none)
|
||||||
|
|
||||||
|
DEF( define_var, 6, 0, 0, atom_u8)
|
||||||
|
DEF(check_define_var, 6, 0, 0, atom_u8)
|
||||||
|
DEF( define_func, 6, 1, 0, atom_u8)
|
||||||
|
DEF( get_field, 5, 1, 1, atom)
|
||||||
|
DEF( get_field2, 5, 1, 2, atom)
|
||||||
|
DEF( put_field, 5, 2, 0, atom)
|
||||||
|
DEF( get_private_field, 1, 2, 1, none) /* obj prop -> value */
|
||||||
|
DEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */
|
||||||
|
DEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */
|
||||||
|
DEF( get_array_el, 1, 2, 1, none)
|
||||||
|
DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */
|
||||||
|
DEF( put_array_el, 1, 3, 0, none)
|
||||||
|
DEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */
|
||||||
|
DEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */
|
||||||
|
DEF( define_field, 5, 2, 1, atom)
|
||||||
|
DEF( set_name, 5, 1, 1, atom)
|
||||||
|
DEF(set_name_computed, 1, 2, 2, none)
|
||||||
|
DEF( set_proto, 1, 2, 1, none)
|
||||||
|
DEF(set_home_object, 1, 2, 2, none)
|
||||||
|
DEF(define_array_el, 1, 3, 2, none)
|
||||||
|
DEF( append, 1, 3, 2, none) /* append enumerated object, update length */
|
||||||
|
DEF(copy_data_properties, 2, 3, 3, u8)
|
||||||
|
DEF( define_method, 6, 2, 1, atom_u8)
|
||||||
|
DEF(define_method_computed, 2, 3, 1, u8) /* must come after define_method */
|
||||||
|
DEF( define_class, 6, 2, 2, atom_u8) /* parent ctor -> ctor proto */
|
||||||
|
DEF( define_class_computed, 6, 3, 3, atom_u8) /* field_name parent ctor -> field_name ctor proto (class with computed name) */
|
||||||
|
|
||||||
|
DEF( get_loc, 3, 0, 1, loc)
|
||||||
|
DEF( put_loc, 3, 1, 0, loc) /* must come after get_loc */
|
||||||
|
DEF( set_loc, 3, 1, 1, loc) /* must come after put_loc */
|
||||||
|
DEF( get_arg, 3, 0, 1, arg)
|
||||||
|
DEF( put_arg, 3, 1, 0, arg) /* must come after get_arg */
|
||||||
|
DEF( set_arg, 3, 1, 1, arg) /* must come after put_arg */
|
||||||
|
DEF( get_var_ref, 3, 0, 1, var_ref)
|
||||||
|
DEF( put_var_ref, 3, 1, 0, var_ref) /* must come after get_var_ref */
|
||||||
|
DEF( set_var_ref, 3, 1, 1, var_ref) /* must come after put_var_ref */
|
||||||
|
DEF(set_loc_uninitialized, 3, 0, 0, loc)
|
||||||
|
DEF( get_loc_check, 3, 0, 1, loc)
|
||||||
|
DEF( put_loc_check, 3, 1, 0, loc) /* must come after get_loc_check */
|
||||||
|
DEF( put_loc_check_init, 3, 1, 0, loc)
|
||||||
|
DEF(get_var_ref_check, 3, 0, 1, var_ref)
|
||||||
|
DEF(put_var_ref_check, 3, 1, 0, var_ref) /* must come after get_var_ref_check */
|
||||||
|
DEF(put_var_ref_check_init, 3, 1, 0, var_ref)
|
||||||
|
DEF( close_loc, 3, 0, 0, loc)
|
||||||
|
DEF( if_false, 5, 1, 0, label)
|
||||||
|
DEF( if_true, 5, 1, 0, label) /* must come after if_false */
|
||||||
|
DEF( goto, 5, 0, 0, label) /* must come after if_true */
|
||||||
|
DEF( catch, 5, 0, 1, label)
|
||||||
|
DEF( gosub, 5, 0, 0, label) /* used to execute the finally block */
|
||||||
|
DEF( ret, 1, 1, 0, none) /* used to return from the finally block */
|
||||||
|
|
||||||
|
DEF( to_object, 1, 1, 1, none)
|
||||||
|
//DEF( to_string, 1, 1, 1, none)
|
||||||
|
DEF( to_propkey, 1, 1, 1, none)
|
||||||
|
DEF( to_propkey2, 1, 2, 2, none)
|
||||||
|
|
||||||
|
DEF( with_get_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||||
|
DEF( with_put_var, 10, 2, 1, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||||
|
DEF(with_delete_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||||
|
DEF( with_make_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||||
|
DEF( with_get_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||||
|
DEF(with_get_ref_undef, 10, 1, 0, atom_label_u8)
|
||||||
|
|
||||||
|
DEF( make_loc_ref, 7, 0, 2, atom_u16)
|
||||||
|
DEF( make_arg_ref, 7, 0, 2, atom_u16)
|
||||||
|
DEF(make_var_ref_ref, 7, 0, 2, atom_u16)
|
||||||
|
DEF( make_var_ref, 5, 0, 2, atom)
|
||||||
|
|
||||||
|
DEF( for_in_start, 1, 1, 1, none)
|
||||||
|
DEF( for_of_start, 1, 1, 3, none)
|
||||||
|
DEF(for_await_of_start, 1, 1, 3, none)
|
||||||
|
DEF( for_in_next, 1, 1, 3, none)
|
||||||
|
DEF( for_of_next, 2, 3, 5, u8)
|
||||||
|
DEF(for_await_of_next, 1, 3, 4, none)
|
||||||
|
DEF(iterator_get_value_done, 1, 1, 2, none)
|
||||||
|
DEF( iterator_close, 1, 3, 0, none)
|
||||||
|
DEF(iterator_close_return, 1, 4, 4, none)
|
||||||
|
DEF(async_iterator_close, 1, 3, 2, none)
|
||||||
|
DEF(async_iterator_next, 1, 4, 4, none)
|
||||||
|
DEF(async_iterator_get, 2, 4, 5, u8)
|
||||||
|
DEF( initial_yield, 1, 0, 0, none)
|
||||||
|
DEF( yield, 1, 1, 2, none)
|
||||||
|
DEF( yield_star, 1, 2, 2, none)
|
||||||
|
DEF(async_yield_star, 1, 1, 2, none)
|
||||||
|
DEF( await, 1, 1, 1, none)
|
||||||
|
|
||||||
|
/* arithmetic/logic operations */
|
||||||
|
DEF( neg, 1, 1, 1, none)
|
||||||
|
DEF( plus, 1, 1, 1, none)
|
||||||
|
DEF( dec, 1, 1, 1, none)
|
||||||
|
DEF( inc, 1, 1, 1, none)
|
||||||
|
DEF( post_dec, 1, 1, 2, none)
|
||||||
|
DEF( post_inc, 1, 1, 2, none)
|
||||||
|
DEF( dec_loc, 2, 0, 0, loc8)
|
||||||
|
DEF( inc_loc, 2, 0, 0, loc8)
|
||||||
|
DEF( add_loc, 2, 1, 0, loc8)
|
||||||
|
DEF( not, 1, 1, 1, none)
|
||||||
|
DEF( lnot, 1, 1, 1, none)
|
||||||
|
DEF( typeof, 1, 1, 1, none)
|
||||||
|
DEF( delete, 1, 2, 1, none)
|
||||||
|
DEF( delete_var, 5, 0, 1, atom)
|
||||||
|
|
||||||
|
DEF( mul, 1, 2, 1, none)
|
||||||
|
DEF( div, 1, 2, 1, none)
|
||||||
|
DEF( mod, 1, 2, 1, none)
|
||||||
|
DEF( add, 1, 2, 1, none)
|
||||||
|
DEF( sub, 1, 2, 1, none)
|
||||||
|
DEF( pow, 1, 2, 1, none)
|
||||||
|
DEF( shl, 1, 2, 1, none)
|
||||||
|
DEF( sar, 1, 2, 1, none)
|
||||||
|
DEF( shr, 1, 2, 1, none)
|
||||||
|
DEF( lt, 1, 2, 1, none)
|
||||||
|
DEF( lte, 1, 2, 1, none)
|
||||||
|
DEF( gt, 1, 2, 1, none)
|
||||||
|
DEF( gte, 1, 2, 1, none)
|
||||||
|
DEF( instanceof, 1, 2, 1, none)
|
||||||
|
DEF( in, 1, 2, 1, none)
|
||||||
|
DEF( eq, 1, 2, 1, none)
|
||||||
|
DEF( neq, 1, 2, 1, none)
|
||||||
|
DEF( strict_eq, 1, 2, 1, none)
|
||||||
|
DEF( strict_neq, 1, 2, 1, none)
|
||||||
|
DEF( and, 1, 2, 1, none)
|
||||||
|
DEF( xor, 1, 2, 1, none)
|
||||||
|
DEF( or, 1, 2, 1, none)
|
||||||
|
DEF(is_undefined_or_null, 1, 1, 1, none)
|
||||||
|
#ifdef CONFIG_BIGNUM
|
||||||
|
DEF( mul_pow10, 1, 2, 1, none)
|
||||||
|
DEF( math_mod, 1, 2, 1, none)
|
||||||
|
#endif
|
||||||
|
/* must be the last non short and non temporary opcode */
|
||||||
|
DEF( nop, 1, 0, 0, none)
|
||||||
|
|
||||||
|
/* temporary opcodes: never emitted in the final bytecode */
|
||||||
|
|
||||||
|
def(set_arg_valid_upto, 3, 0, 0, arg) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
|
||||||
|
def( enter_scope, 3, 0, 0, u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def( leave_scope, 3, 0, 0, u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
|
||||||
|
def( label, 5, 0, 0, label) /* emitted in phase 1, removed in phase 3 */
|
||||||
|
|
||||||
|
def(scope_get_var_undef, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def( scope_get_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def( scope_put_var, 7, 1, 0, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def(scope_delete_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def( scope_make_ref, 11, 0, 2, atom_label_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def( scope_get_ref, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def(scope_put_var_init, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
def(scope_get_private_field, 7, 1, 1, atom_u16) /* obj -> value, emitted in phase 1, removed in phase 2 */
|
||||||
|
def(scope_get_private_field2, 7, 1, 2, atom_u16) /* obj -> obj value, emitted in phase 1, removed in phase 2 */
|
||||||
|
def(scope_put_private_field, 7, 1, 1, atom_u16) /* obj value ->, emitted in phase 1, removed in phase 2 */
|
||||||
|
|
||||||
|
def( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */
|
||||||
|
|
||||||
|
def( line_num, 5, 0, 0, u32) /* emitted in phase 1, removed in phase 3 */
|
||||||
|
|
||||||
|
#if SHORT_OPCODES
|
||||||
|
DEF( push_minus1, 1, 0, 1, none_int)
|
||||||
|
DEF( push_0, 1, 0, 1, none_int)
|
||||||
|
DEF( push_1, 1, 0, 1, none_int)
|
||||||
|
DEF( push_2, 1, 0, 1, none_int)
|
||||||
|
DEF( push_3, 1, 0, 1, none_int)
|
||||||
|
DEF( push_4, 1, 0, 1, none_int)
|
||||||
|
DEF( push_5, 1, 0, 1, none_int)
|
||||||
|
DEF( push_6, 1, 0, 1, none_int)
|
||||||
|
DEF( push_7, 1, 0, 1, none_int)
|
||||||
|
DEF( push_i8, 2, 0, 1, i8)
|
||||||
|
DEF( push_i16, 3, 0, 1, i16)
|
||||||
|
DEF( push_const8, 2, 0, 1, const8)
|
||||||
|
DEF( fclosure8, 2, 0, 1, const8) /* must follow push_const8 */
|
||||||
|
DEF(push_empty_string, 1, 0, 1, none)
|
||||||
|
|
||||||
|
DEF( get_loc8, 2, 0, 1, loc8)
|
||||||
|
DEF( put_loc8, 2, 1, 0, loc8)
|
||||||
|
DEF( set_loc8, 2, 1, 1, loc8)
|
||||||
|
|
||||||
|
DEF( get_loc0, 1, 0, 1, none_loc)
|
||||||
|
DEF( get_loc1, 1, 0, 1, none_loc)
|
||||||
|
DEF( get_loc2, 1, 0, 1, none_loc)
|
||||||
|
DEF( get_loc3, 1, 0, 1, none_loc)
|
||||||
|
DEF( put_loc0, 1, 1, 0, none_loc)
|
||||||
|
DEF( put_loc1, 1, 1, 0, none_loc)
|
||||||
|
DEF( put_loc2, 1, 1, 0, none_loc)
|
||||||
|
DEF( put_loc3, 1, 1, 0, none_loc)
|
||||||
|
DEF( set_loc0, 1, 1, 1, none_loc)
|
||||||
|
DEF( set_loc1, 1, 1, 1, none_loc)
|
||||||
|
DEF( set_loc2, 1, 1, 1, none_loc)
|
||||||
|
DEF( set_loc3, 1, 1, 1, none_loc)
|
||||||
|
DEF( get_arg0, 1, 0, 1, none_arg)
|
||||||
|
DEF( get_arg1, 1, 0, 1, none_arg)
|
||||||
|
DEF( get_arg2, 1, 0, 1, none_arg)
|
||||||
|
DEF( get_arg3, 1, 0, 1, none_arg)
|
||||||
|
DEF( put_arg0, 1, 1, 0, none_arg)
|
||||||
|
DEF( put_arg1, 1, 1, 0, none_arg)
|
||||||
|
DEF( put_arg2, 1, 1, 0, none_arg)
|
||||||
|
DEF( put_arg3, 1, 1, 0, none_arg)
|
||||||
|
DEF( set_arg0, 1, 1, 1, none_arg)
|
||||||
|
DEF( set_arg1, 1, 1, 1, none_arg)
|
||||||
|
DEF( set_arg2, 1, 1, 1, none_arg)
|
||||||
|
DEF( set_arg3, 1, 1, 1, none_arg)
|
||||||
|
DEF( get_var_ref0, 1, 0, 1, none_var_ref)
|
||||||
|
DEF( get_var_ref1, 1, 0, 1, none_var_ref)
|
||||||
|
DEF( get_var_ref2, 1, 0, 1, none_var_ref)
|
||||||
|
DEF( get_var_ref3, 1, 0, 1, none_var_ref)
|
||||||
|
DEF( put_var_ref0, 1, 1, 0, none_var_ref)
|
||||||
|
DEF( put_var_ref1, 1, 1, 0, none_var_ref)
|
||||||
|
DEF( put_var_ref2, 1, 1, 0, none_var_ref)
|
||||||
|
DEF( put_var_ref3, 1, 1, 0, none_var_ref)
|
||||||
|
DEF( set_var_ref0, 1, 1, 1, none_var_ref)
|
||||||
|
DEF( set_var_ref1, 1, 1, 1, none_var_ref)
|
||||||
|
DEF( set_var_ref2, 1, 1, 1, none_var_ref)
|
||||||
|
DEF( set_var_ref3, 1, 1, 1, none_var_ref)
|
||||||
|
|
||||||
|
DEF( get_length, 1, 1, 1, none)
|
||||||
|
|
||||||
|
DEF( if_false8, 2, 1, 0, label8)
|
||||||
|
DEF( if_true8, 2, 1, 0, label8) /* must come after if_false8 */
|
||||||
|
DEF( goto8, 2, 0, 0, label8) /* must come after if_true8 */
|
||||||
|
DEF( goto16, 3, 0, 0, label16)
|
||||||
|
|
||||||
|
DEF( call0, 1, 1, 1, npopx)
|
||||||
|
DEF( call1, 1, 1, 1, npopx)
|
||||||
|
DEF( call2, 1, 1, 1, npopx)
|
||||||
|
DEF( call3, 1, 1, 1, npopx)
|
||||||
|
|
||||||
|
DEF( is_undefined, 1, 1, 1, none)
|
||||||
|
DEF( is_null, 1, 1, 1, none)
|
||||||
|
DEF( is_function, 1, 1, 1, none)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef DEF
|
||||||
|
#undef def
|
||||||
|
#endif /* DEF */
|
53312
android/src/main/jni/quickjs/quickjs.c
Normal file
53312
android/src/main/jni/quickjs/quickjs.c
Normal file
File diff suppressed because it is too large
Load Diff
1030
android/src/main/jni/quickjs/quickjs.h
Normal file
1030
android/src/main/jni/quickjs/quickjs.h
Normal file
File diff suppressed because it is too large
Load Diff
1303
android/src/main/jni/quickjs/quickjspp.hpp
Normal file
1303
android/src/main/jni/quickjs/quickjspp.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
|||||||
|
package soko.ekibun.flutter_qjs
|
||||||
|
|
||||||
|
import android.os.Handler
|
||||||
|
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||||
|
import io.flutter.plugin.common.MethodCall
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||||
|
import io.flutter.plugin.common.MethodChannel.Result
|
||||||
|
import io.flutter.plugin.common.PluginRegistry.Registrar
|
||||||
|
|
||||||
|
/** FlutterQjsPlugin */
|
||||||
|
class FlutterQjsPlugin: FlutterPlugin, MethodCallHandler {
|
||||||
|
/// The MethodChannel that will the communication between Flutter and native Android
|
||||||
|
///
|
||||||
|
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
|
||||||
|
/// when the Flutter Engine is detached from the Activity
|
||||||
|
private lateinit var channelwrapper : MethodChannelWrapper
|
||||||
|
private lateinit var channel : MethodChannel
|
||||||
|
private var engine : JniBridge? = null
|
||||||
|
private lateinit var applicationContext: android.content.Context
|
||||||
|
private val handler by lazy { Handler() }
|
||||||
|
|
||||||
|
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
|
applicationContext = flutterPluginBinding.applicationContext
|
||||||
|
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "soko.ekibun.flutter_qjs")
|
||||||
|
channel.setMethodCallHandler(this)
|
||||||
|
channelwrapper = MethodChannelWrapper(handler, channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMethodCall(call: MethodCall, result: Result) {
|
||||||
|
if (call.method == "initEngine") {
|
||||||
|
// engine = JsEngine(channel)
|
||||||
|
engine = JniBridge()
|
||||||
|
engine?.initEngine(channelwrapper)
|
||||||
|
result.success(1)
|
||||||
|
} else if (call.method == "evaluate") {
|
||||||
|
val script: String = call.argument<String>("script")!!
|
||||||
|
val name: String = call.argument<String>("name")!!
|
||||||
|
engine?.evaluate(script, name, ResultWrapper(handler, result))
|
||||||
|
// engine?.evaluate(script, result)
|
||||||
|
} else if (call.method == "close") {
|
||||||
|
// engine?.release()
|
||||||
|
engine?.close()
|
||||||
|
engine = null
|
||||||
|
result.success(null)
|
||||||
|
} else {
|
||||||
|
result.notImplemented()
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
|
channel.setMethodCallHandler(null)
|
||||||
|
}
|
||||||
|
}
|
22
android/src/main/kotlin/soko/ekibun/flutter_qjs/JniBridge.kt
Normal file
22
android/src/main/kotlin/soko/ekibun/flutter_qjs/JniBridge.kt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package soko.ekibun.flutter_qjs
|
||||||
|
|
||||||
|
class JniBridge {
|
||||||
|
companion object {
|
||||||
|
// Used to load the 'native-lib' library on application startup.
|
||||||
|
init {
|
||||||
|
System.loadLibrary("libjsengine")
|
||||||
|
}
|
||||||
|
|
||||||
|
val instance by lazy { JniBridge() }
|
||||||
|
}
|
||||||
|
|
||||||
|
external fun initEngine(channel: MethodChannelWrapper): Int
|
||||||
|
|
||||||
|
external fun evaluate(script: String, name: String, result: ResultWrapper)
|
||||||
|
|
||||||
|
external fun close()
|
||||||
|
|
||||||
|
external fun reject(promise: Long, reason: String)
|
||||||
|
|
||||||
|
external fun resolve(promise: Long, data: Any?)
|
||||||
|
}
|
80
android/src/main/kotlin/soko/ekibun/flutter_qjs/JsEngine.kt
Normal file
80
android/src/main/kotlin/soko/ekibun/flutter_qjs/JsEngine.kt
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package soko.ekibun.flutter_qjs
|
||||||
|
|
||||||
|
// import android.util.Log
|
||||||
|
// import de.prosiebensat1digital.oasisjsbridge.*
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
// import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
class JsEngine(private val channel: MethodChannel) {
|
||||||
|
// private val jsBridge = JsBridge(JsBridgeConfig.bareConfig())
|
||||||
|
|
||||||
|
// fun processPromiseQueue() {
|
||||||
|
// JsBridge::class.java.getDeclaredMethod("processPromiseQueue").invoke(jsBridge)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private fun dartInteract(resolve: (String) -> Unit, reject: (String) -> Unit, method: String, args: String) {
|
||||||
|
// println("dart: $method")
|
||||||
|
// jsBridge.launch(Dispatchers.Main) {
|
||||||
|
// channel.invokeMethod(method, args, object : MethodChannel.Result {
|
||||||
|
// override fun notImplemented() {
|
||||||
|
// println("dart error: notImplemented")
|
||||||
|
// jsBridge.launch(Dispatchers.Main) {
|
||||||
|
// reject("notImplemented")
|
||||||
|
// withContext(jsBridge.coroutineContext) {
|
||||||
|
// processPromiseQueue()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// override fun error(error_code: String?, error_message: String?, error_details: Any?) {
|
||||||
|
// println("dart error: ${error_message ?: "undefined"}")
|
||||||
|
// jsBridge.launch(Dispatchers.Main) {
|
||||||
|
// reject(error_message ?: "undefined")
|
||||||
|
// withContext(jsBridge.coroutineContext) {
|
||||||
|
// processPromiseQueue()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// override fun success(result: Any?) {
|
||||||
|
// println("dart success: $result")
|
||||||
|
// jsBridge.launch(Dispatchers.Main) {
|
||||||
|
// resolve(result.toString())
|
||||||
|
// withContext(jsBridge.coroutineContext) {
|
||||||
|
// processPromiseQueue()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// init {
|
||||||
|
// // jsBridge.initEngine()
|
||||||
|
// jsBridge.launch(Dispatchers.Main) {
|
||||||
|
// JsValue.fromNativeFunction4(jsBridge, ::dartInteract).assignToGlobal("__DartImpl__invoke")
|
||||||
|
// jsBridge.evaluateAsync<Deferred<String>>("""
|
||||||
|
// this.dart = (method, ...args) => new Promise((res, rej) =>
|
||||||
|
// this.__DartImpl__invoke((v) => res(JSON.parse(v)), rej, method, JSON.stringify(args)))
|
||||||
|
// """).await().await()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fun eval(script: String, result: MethodChannel.Result) {
|
||||||
|
// jsBridge.launch(Dispatchers.Main) {
|
||||||
|
// try {
|
||||||
|
// var ret = jsBridge.evaluateAsync<Deferred<String>>(script).await().await()
|
||||||
|
// println(ret)
|
||||||
|
// result.success(ret)
|
||||||
|
// } catch (e: Throwable) {
|
||||||
|
// e.printStackTrace()
|
||||||
|
// result.error("FlutterJSException", Log.getStackTraceString(e), null)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fun release() {
|
||||||
|
// jsBridge.release()
|
||||||
|
// }
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package soko.ekibun.flutter_qjs
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
|
import android.os.Handler
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
class MethodChannelWrapper(private val handler: Handler, private val channel: MethodChannel) {
|
||||||
|
fun invokeMethod(method: String, arguments: String, promise: Long) {
|
||||||
|
handler.post {
|
||||||
|
channel.invokeMethod(method, arguments, object : MethodChannel.Result {
|
||||||
|
override fun notImplemented() {
|
||||||
|
JniBridge.instance.reject(promise, "notImplemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(error_code: String?, error_message: String?, error_data: Any?) {
|
||||||
|
JniBridge.instance.reject(promise, error_message ?: "undefined")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun success(data: Any?) {
|
||||||
|
JniBridge.instance.resolve(promise, data.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,20 @@
|
|||||||
|
package soko.ekibun.flutter_qjs
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
|
import android.os.Handler
|
||||||
|
import io.flutter.plugin.common.MethodChannel.Result
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
class ResultWrapper(private val handler: Handler, private val result: Result) {
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
fun success(dat: String) {
|
||||||
|
handler.post { result.success(dat) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
fun error(error_message: String) {
|
||||||
|
handler.post { result.error("FlutterJSException", error_message, null) }
|
||||||
|
}
|
||||||
|
}
|
11
example/android/.gitignore
vendored
Normal file
11
example/android/.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
gradle-wrapper.jar
|
||||||
|
/.gradle
|
||||||
|
/captures/
|
||||||
|
/gradlew
|
||||||
|
/gradlew.bat
|
||||||
|
/local.properties
|
||||||
|
GeneratedPluginRegistrant.java
|
||||||
|
|
||||||
|
# Remember to never publicly share your keystore.
|
||||||
|
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
|
||||||
|
key.properties
|
17
example/android/.project
Normal file
17
example/android/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>android</name>
|
||||||
|
<comment>Project android created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
13
example/android/.settings/org.eclipse.buildship.core.prefs
Normal file
13
example/android/.settings/org.eclipse.buildship.core.prefs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
arguments=
|
||||||
|
auto.sync=false
|
||||||
|
build.scans.enabled=false
|
||||||
|
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||||
|
connection.project.dir=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
gradle.user.home=
|
||||||
|
java.home=C\:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2019.3.2/jbr
|
||||||
|
jvm.arguments=
|
||||||
|
offline.mode=false
|
||||||
|
override.workspace.settings=true
|
||||||
|
show.console.view=true
|
||||||
|
show.executions.view=true
|
6
example/android/app/.classpath
Normal file
6
example/android/app/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||||
|
<classpathentry kind="output" path="bin/default"/>
|
||||||
|
</classpath>
|
23
example/android/app/.project
Normal file
23
example/android/app/.project
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>app</name>
|
||||||
|
<comment>Project app created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=..
|
||||||
|
eclipse.preferences.version=1
|
63
example/android/app/build.gradle
Normal file
63
example/android/app/build.gradle
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
def localProperties = new Properties()
|
||||||
|
def localPropertiesFile = rootProject.file('local.properties')
|
||||||
|
if (localPropertiesFile.exists()) {
|
||||||
|
localPropertiesFile.withReader('UTF-8') { reader ->
|
||||||
|
localProperties.load(reader)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def flutterRoot = localProperties.getProperty('flutter.sdk')
|
||||||
|
if (flutterRoot == null) {
|
||||||
|
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
|
||||||
|
}
|
||||||
|
|
||||||
|
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
|
||||||
|
if (flutterVersionCode == null) {
|
||||||
|
flutterVersionCode = '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
def flutterVersionName = localProperties.getProperty('flutter.versionName')
|
||||||
|
if (flutterVersionName == null) {
|
||||||
|
flutterVersionName = '1.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 28
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
}
|
||||||
|
|
||||||
|
lintOptions {
|
||||||
|
disable 'InvalidPackage'
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
|
applicationId "soko.ekibun.example"
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 28
|
||||||
|
versionCode flutterVersionCode.toInteger()
|
||||||
|
versionName flutterVersionName
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
// TODO: Add your own signing config for the release build.
|
||||||
|
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||||
|
signingConfig signingConfigs.debug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flutter {
|
||||||
|
source '../..'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
}
|
7
example/android/app/src/debug/AndroidManifest.xml
Normal file
7
example/android/app/src/debug/AndroidManifest.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="soko.ekibun.example">
|
||||||
|
<!-- Flutter needs it to communicate with the running application
|
||||||
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
|
-->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
</manifest>
|
47
example/android/app/src/main/AndroidManifest.xml
Normal file
47
example/android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="soko.ekibun.example">
|
||||||
|
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||||
|
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||||
|
In most cases you can leave this as-is, but you if you want to provide
|
||||||
|
additional functionality it is fine to subclass or reimplement
|
||||||
|
FlutterApplication and put your custom class here. -->
|
||||||
|
<application
|
||||||
|
android:name="io.flutter.app.FlutterApplication"
|
||||||
|
android:label="example"
|
||||||
|
android:icon="@mipmap/ic_launcher">
|
||||||
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:theme="@style/LaunchTheme"
|
||||||
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
|
android:hardwareAccelerated="true"
|
||||||
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||||
|
the Android process has started. This theme is visible to the user
|
||||||
|
while the Flutter UI initializes. After that, this theme continues
|
||||||
|
to determine the Window background behind the Flutter UI. -->
|
||||||
|
<meta-data
|
||||||
|
android:name="io.flutter.embedding.android.NormalTheme"
|
||||||
|
android:resource="@style/NormalTheme"
|
||||||
|
/>
|
||||||
|
<!-- Displays an Android View that continues showing the launch screen
|
||||||
|
Drawable until Flutter paints its first frame, then this splash
|
||||||
|
screen fades out. A splash screen is useful to avoid any visual
|
||||||
|
gap between the end of Android's launch screen and the painting of
|
||||||
|
Flutter's first frame. -->
|
||||||
|
<meta-data
|
||||||
|
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
||||||
|
android:resource="@drawable/launch_background"
|
||||||
|
/>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<!-- Don't delete the meta-data below.
|
||||||
|
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||||
|
<meta-data
|
||||||
|
android:name="flutterEmbedding"
|
||||||
|
android:value="2" />
|
||||||
|
</application>
|
||||||
|
</manifest>
|
@@ -0,0 +1,6 @@
|
|||||||
|
package soko.ekibun.example
|
||||||
|
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
|
||||||
|
class MainActivity: FlutterActivity() {
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
package soko.ekibun.flutter_qjs_example
|
||||||
|
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
|
||||||
|
class MainActivity: FlutterActivity() {
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Modify this file to customize your launch splash screen -->
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@android:color/white" />
|
||||||
|
|
||||||
|
<!-- You can insert your own image assets here -->
|
||||||
|
<!-- <item>
|
||||||
|
<bitmap
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@mipmap/launch_image" />
|
||||||
|
</item> -->
|
||||||
|
</layer-list>
|
BIN
example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 544 B |
BIN
example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 442 B |
BIN
example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 721 B |
BIN
example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
18
example/android/app/src/main/res/values/styles.xml
Normal file
18
example/android/app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<!-- Theme applied to the Android Window while the process is starting -->
|
||||||
|
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||||
|
<!-- Show a splash screen on the activity. Automatically removed when
|
||||||
|
Flutter draws its first frame -->
|
||||||
|
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||||
|
</style>
|
||||||
|
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||||
|
This theme determines the color of the Android Window while your
|
||||||
|
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||||
|
running.
|
||||||
|
|
||||||
|
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||||
|
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||||
|
<item name="android:windowBackground">@android:color/white</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
7
example/android/app/src/profile/AndroidManifest.xml
Normal file
7
example/android/app/src/profile/AndroidManifest.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="soko.ekibun.example">
|
||||||
|
<!-- Flutter needs it to communicate with the running application
|
||||||
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
|
-->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
</manifest>
|
31
example/android/build.gradle
Normal file
31
example/android/build.gradle
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.3.50'
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.buildDir = '../build'
|
||||||
|
subprojects {
|
||||||
|
project.buildDir = "${rootProject.buildDir}/${project.name}"
|
||||||
|
}
|
||||||
|
subprojects {
|
||||||
|
project.evaluationDependsOn(':app')
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
4
example/android/gradle.properties
Normal file
4
example/android/gradle.properties
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
org.gradle.jvmargs=-Xmx1536M
|
||||||
|
android.enableR8=true
|
||||||
|
android.useAndroidX=true
|
||||||
|
android.enableJetifier=true
|
6
example/android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
example/android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#Fri Jun 23 08:50:38 CEST 2017
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
11
example/android/settings.gradle
Normal file
11
example/android/settings.gradle
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
include ':app'
|
||||||
|
|
||||||
|
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||||
|
def properties = new Properties()
|
||||||
|
|
||||||
|
assert localPropertiesFile.exists()
|
||||||
|
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
|
||||||
|
|
||||||
|
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||||
|
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||||
|
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
@@ -8,11 +8,12 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
||||||
</content>
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
|
||||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||||
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
||||||
</component>
|
</component>
|
||||||
|
@@ -34,6 +34,9 @@ flutter:
|
|||||||
# -------------------
|
# -------------------
|
||||||
windows:
|
windows:
|
||||||
pluginClass: FlutterQjsPlugin
|
pluginClass: FlutterQjsPlugin
|
||||||
|
android:
|
||||||
|
pluginClass: FlutterQjsPlugin
|
||||||
|
package: soko.ekibun.flutter_qjs
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
||||||
# To add assets to your plugin package, add an assets section, like this:
|
# To add assets to your plugin package, add an assets section, like this:
|
||||||
|
@@ -87,7 +87,7 @@ namespace
|
|||||||
}
|
}
|
||||||
else if (method_call.method_name().compare("evaluate") == 0)
|
else if (method_call.method_name().compare("evaluate") == 0)
|
||||||
{
|
{
|
||||||
flutter::EncodableMap args = *((flutter::EncodableMap *)method_call.arguments());
|
flutter::EncodableMap args = *std::get_if<flutter::EncodableMap>(method_call.arguments());
|
||||||
std::string script = std::get<std::string>(ValueOrNull(args, "script"));
|
std::string script = std::get<std::string>(ValueOrNull(args, "script"));
|
||||||
std::string name = std::get<std::string>(ValueOrNull(args, "name"));
|
std::string name = std::get<std::string>(ValueOrNull(args, "name"));
|
||||||
auto presult = result.release();
|
auto presult = result.release();
|
||||||
|
Reference in New Issue
Block a user