├── .gitignore
├── .gitmodules
├── AndroidJSCore
├── .gitignore
├── .idea
│ ├── .name
│ ├── compiler.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── inspectionProfiles
│ │ ├── Project_Default.xml
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── runConfigurations.xml
├── AndroidJSCore-library
│ ├── .gitignore
│ ├── build.gradle
│ ├── jni
│ │ ├── Android.mk
│ │ ├── Application.mk
│ │ ├── Instance.cpp
│ │ ├── Instance.h
│ │ ├── JSContext.cpp
│ │ ├── JSFunction.cpp
│ │ ├── JSFunction.h
│ │ ├── JSJNI.h
│ │ ├── JSObject.cpp
│ │ ├── JSString.cpp
│ │ ├── JSValue.cpp
│ │ ├── include
│ │ │ └── JavaScriptCore
│ │ │ │ ├── JSBase.h
│ │ │ │ ├── JSContextRef.h
│ │ │ │ ├── JSObjectRef.h
│ │ │ │ ├── JSStringRef.h
│ │ │ │ ├── JSValueRef.h
│ │ │ │ ├── JavaScript.h
│ │ │ │ └── WebKitAvailability.h
│ │ └── lib
│ │ │ ├── arm64-v8a
│ │ │ └── libjavascriptcoregtk-4.0.so
│ │ │ ├── armeabi-v7a
│ │ │ └── libjavascriptcoregtk-4.0.so
│ │ │ ├── armeabi
│ │ │ └── libjavascriptcoregtk-4.0.so
│ │ │ ├── mips
│ │ │ └── libjavascriptcoregtk-4.0.so
│ │ │ ├── mips64
│ │ │ └── libjavascriptcoregtk-4.0.so
│ │ │ ├── x86
│ │ │ └── libjavascriptcoregtk-4.0.so
│ │ │ └── x86_64
│ │ │ └── libjavascriptcoregtk-4.0.so
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── org
│ │ │ └── liquidplayer
│ │ │ └── webkit
│ │ │ └── javascriptcore
│ │ │ ├── JSArrayBufferTest.java
│ │ │ ├── JSArrayTest.java
│ │ │ ├── JSContextTest.java
│ │ │ ├── JSDataViewTest.java
│ │ │ ├── JSDateTest.java
│ │ │ ├── JSErrorTest.java
│ │ │ ├── JSFloat32ArrayTest.java
│ │ │ ├── JSFloat64ArrayTest.java
│ │ │ ├── JSFunctionTest.java
│ │ │ ├── JSInt16ArrayTest.java
│ │ │ ├── JSInt32ArrayTest.java
│ │ │ ├── JSInt8ArrayTest.java
│ │ │ ├── JSIteratorTest.java
│ │ │ ├── JSONTest.java
│ │ │ ├── JSObjectPropertiesMapTest.java
│ │ │ ├── JSObjectTest.java
│ │ │ ├── JSRegExpTest.java
│ │ │ ├── JSTypedArrayTest.java
│ │ │ ├── JSUint16ArrayTest.java
│ │ │ ├── JSUint32ArrayTest.java
│ │ │ ├── JSUint8ArrayTest.java
│ │ │ ├── JSUint8ClampedArrayTest.java
│ │ │ └── JSValueTest.java
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── org
│ │ └── liquidplayer
│ │ └── webkit
│ │ └── javascriptcore
│ │ ├── JSArray.java
│ │ ├── JSArrayBuffer.java
│ │ ├── JSBaseArray.java
│ │ ├── JSContext.java
│ │ ├── JSContextGroup.java
│ │ ├── JSDataView.java
│ │ ├── JSDate.java
│ │ ├── JSError.java
│ │ ├── JSException.java
│ │ ├── JSFloat32Array.java
│ │ ├── JSFloat64Array.java
│ │ ├── JSFunction.java
│ │ ├── JSInt16Array.java
│ │ ├── JSInt32Array.java
│ │ ├── JSInt8Array.java
│ │ ├── JSIterator.java
│ │ ├── JSON.java
│ │ ├── JSObject.java
│ │ ├── JSObjectPropertiesMap.java
│ │ ├── JSObjectWrapper.java
│ │ ├── JSRegExp.java
│ │ ├── JSTypedArray.java
│ │ ├── JSUint16Array.java
│ │ ├── JSUint32Array.java
│ │ ├── JSUint8Array.java
│ │ ├── JSUint8ClampedArray.java
│ │ └── JSValue.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
└── examples
└── AndroidJSCoreExample
├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── liquidplayer
│ │ └── androidjscoreexample
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── org
│ │ │ └── liquidplayer
│ │ │ └── androidjscoreexample
│ │ │ ├── AsyncExample.java
│ │ │ ├── ExampleContext.java
│ │ │ ├── ExceptionHandlingExample.java
│ │ │ ├── IExample.java
│ │ │ ├── IExampleContext.java
│ │ │ ├── MainActivity.java
│ │ │ ├── OwenMatthewsExample.java
│ │ │ └── SharingFunctionsExample.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── example_fragment.xml
│ │ └── fragment_main.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── org
│ └── liquidplayer
│ └── androidjscoreexample
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .settings
3 | bin
4 | gen
5 | libs/
6 | obj
7 | project.properties
8 | build/
9 | *~
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "webkit"]
2 | path = webkit
3 | url = https://github.com/ericwlange/webkit.git
4 |
--------------------------------------------------------------------------------
/AndroidJSCore/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | /AndroidJSCore/libs
10 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/.name:
--------------------------------------------------------------------------------
1 | AndroidJSCore
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AndroidJSCore/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'jacoco'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | android {
6 | compileSdkVersion 24
7 | buildToolsVersion "23.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 11
11 | targetSdkVersion 24
12 | versionCode 3
13 | versionName "3.0.1"
14 | setProperty("archivesBaseName", "AndroidJSCore-$versionName")
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | debug {
19 | testCoverageEnabled = true
20 | }
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | sourceSets { main { jniLibs.srcDirs 'libs' } }
27 | }
28 |
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | testCompile 'junit:junit:4.12'
32 | compile 'com.android.support:appcompat-v7:24.1.1'
33 | androidTestCompile 'junit:junit:4.0'
34 | androidTestCompile 'com.android.support:support-annotations:24.1.1'
35 | androidTestCompile 'com.android.support.test:runner:0.5'
36 | androidTestCompile 'com.android.support.test:rules:0.5'
37 | androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
38 | }
39 |
40 | // build a jar with source files
41 | task sourcesJar(type: Jar) {
42 | from android.sourceSets.main.java.srcDirs
43 | classifier = 'sources'
44 | }
45 |
46 | task javadoc(type: Javadoc) {
47 | failOnError false
48 | source = android.sourceSets.main.java.sourceFiles
49 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
50 | classpath += configurations.compile
51 | }
52 |
53 | // build a jar with javadoc
54 | task javadocJar(type: Jar, dependsOn: javadoc) {
55 | classifier = 'javadoc'
56 | from javadoc.destinationDir
57 | }
58 |
59 | artifacts {
60 | archives sourcesJar
61 | archives javadocJar
62 | }
63 |
64 |
65 | apply plugin: 'com.github.dcendents.android-maven'
66 |
67 | group='com.github.ericwlange'
68 |
69 | task hemroidBuild(type: Exec) {
70 | def rootDir = project.rootDir
71 | def localProperties = new File(rootDir, "local.properties")
72 | def ndkDir = ''
73 | if (localProperties.exists()) {
74 | Properties properties = new Properties()
75 | localProperties.withInputStream { instr ->
76 | properties.load(instr)
77 | }
78 | ndkDir = properties.getProperty('ndk.dir')
79 | }
80 | executable "$ndkDir/ndk-build"
81 | }
82 |
83 | preBuild.dependsOn hemroidBuild
84 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/Android.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Android.mk
3 | # AndroidJSCore project
4 | #
5 | # https://github.com/ericwlange/AndroidJSCore/
6 | #
7 | # Created by Eric Lange
8 | #
9 | #
10 | # Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 | #
12 | # Redistribution and use in source and binary forms, with or without
13 | # modification, are permitted provided that the following conditions are met:
14 | #
15 | # - Redistributions of source code must retain the above copyright notice, this
16 | # list of conditions and the following disclaimer.
17 | #
18 | # - Redistributions in binary form must reproduce the above copyright notice,
19 | # this list of conditions and the following disclaimer in the documentation
20 | # and/or other materials provided with the distribution.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
33 | LOCAL_PATH := $(call my-dir)
34 |
35 | include $(CLEAR_VARS)
36 | LOCAL_MODULE := javascriptcore
37 | LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libjavascriptcoregtk-4.0.so
38 | include $(PREBUILT_SHARED_LIBRARY)
39 |
40 | include $(CLEAR_VARS)
41 |
42 | LOCAL_MODULE := android-js-core
43 | LOCAL_SRC_FILES := JSContext.cpp \
44 | JSObject.cpp \
45 | JSString.cpp \
46 | JSValue.cpp \
47 | Instance.cpp \
48 | JSFunction.cpp
49 |
50 | LOCAL_SHARED_LIBRARIES := javascriptcore
51 |
52 | LOCAL_CPPFLAGS := -std=c++11 -fexceptions -I$(LOCAL_PATH)/include
53 | LOCAL_LDFLAGS := -llog
54 |
55 | include $(BUILD_SHARED_LIBRARY)
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/Application.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Application.mk
3 | # AndroidJSCore project
4 | #
5 | # https://github.com/ericwlange/AndroidJSCore/
6 | #
7 | # Created by Eric Lange
8 | #
9 | #
10 | # Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 | #
12 | # Redistribution and use in source and binary forms, with or without
13 | # modification, are permitted provided that the following conditions are met:
14 | #
15 | # - Redistributions of source code must retain the above copyright notice, this
16 | # list of conditions and the following disclaimer.
17 | #
18 | # - Redistributions in binary form must reproduce the above copyright notice,
19 | # this list of conditions and the following disclaimer in the documentation
20 | # and/or other materials provided with the distribution.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
33 | APP_ABI := all
34 | APP_PLATFORM := android-13
35 | APP_STL := gnustl_static
36 | NDK_TOOLCHAIN_VERSION=4.9
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/Instance.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Instance.cpp
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #include "Instance.h"
35 |
36 | Instance::Instance(JNIEnv *env, jobject thiz, JSContextRef ctx,
37 | JSClassDefinition def, JSStringRef name)
38 | {
39 | env->GetJavaVM(&jvm);
40 | definition = def;
41 | definition.finalize = StaticFinalizeCallback;
42 | classRef = JSClassCreate(&definition);
43 | objRef = JSObjectMake(ctx, classRef, name);
44 | JSValueProtect(ctx, objRef);
45 | this->thiz = env->NewWeakGlobalRef(thiz);
46 |
47 | mutex.lock();
48 | objMap[objRef] = this;
49 | mutex.unlock();
50 | }
51 |
52 | Instance::~Instance()
53 | {
54 | JSClassRelease(classRef);
55 | JNIEnv *env;
56 | int getEnvStat = jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
57 | if (getEnvStat == JNI_EDETACHED) {
58 | jvm->AttachCurrentThread(&env, NULL);
59 | }
60 | env->DeleteWeakGlobalRef(thiz);
61 |
62 | mutex.lock();
63 | objMap.erase(objRef);
64 | mutex.unlock();
65 |
66 | if (getEnvStat == JNI_EDETACHED) {
67 | jvm->DetachCurrentThread();
68 | }
69 | }
70 |
71 | Instance* Instance::getInstance(JSObjectRef objref)
72 | {
73 | Instance *inst = NULL;
74 | mutex.lock();
75 | inst = objMap[objref];
76 | mutex.unlock();
77 | return inst;
78 | }
79 |
80 | std::map Instance::objMap = std::map();
81 | std::mutex Instance::mutex;
82 |
83 | void Instance::StaticFinalizeCallback(JSObjectRef object)
84 | {
85 | Instance *thiz = getInstance(object);
86 |
87 | if (thiz) {
88 | delete thiz;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/Instance.h:
--------------------------------------------------------------------------------
1 | //
2 | // Instance.h
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #ifndef ANDROIDJSCORE_INSTANCE_H
35 | #define ANDROIDJSCORE_INSTANCE_H
36 |
37 | #include "JSJNI.h"
38 | #include
39 | #include
40 |
41 | class Instance {
42 | public:
43 | Instance(JNIEnv *env, jobject thiz, JSContextRef ctx,
44 | JSClassDefinition def = kJSClassDefinitionEmpty, JSStringRef name = NULL);
45 | virtual ~Instance();
46 | virtual long getObjRef() { return (long) objRef; }
47 | static Instance* getInstance(JSObjectRef objref);
48 |
49 | protected:
50 | JavaVM *jvm;
51 | jobject thiz;
52 |
53 | private:
54 | JSObjectRef objRef;
55 | JSClassRef classRef;
56 | JSClassDefinition definition;
57 |
58 | static std::map objMap;
59 | static std::mutex mutex;
60 |
61 | static void StaticFinalizeCallback(JSObjectRef object);
62 | };
63 |
64 | #endif //ANDROIDJSCORE_INSTANCE_H
65 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/JSContext.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // JSContext.cpp
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #include "JSJNI.h"
35 | #include
36 | #include
37 | #include
38 | #include
39 |
40 | static int pfd[2];
41 | static pthread_t thr;
42 |
43 | static void *thread_func(void*)
44 | {
45 | ssize_t rdsz;
46 | char buf[128];
47 | while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
48 | if(buf[rdsz - 1] == '\n') --rdsz;
49 | buf[rdsz - 1] = 0; /* add null-terminator */
50 | __android_log_write(ANDROID_LOG_DEBUG, "JavaScriptCore", buf);
51 | }
52 | return 0;
53 | }
54 |
55 | NATIVE(JSContext,void,staticInit) (PARAMS) {
56 | /* make stdout line-buffered and stderr unbuffered */
57 | setvbuf(stdout, 0, _IOLBF, 0);
58 | setvbuf(stderr, 0, _IONBF, 0);
59 |
60 | /* create the pipe and redirect stdout and stderr */
61 | pipe(pfd);
62 | dup2(pfd[1], 1);
63 | dup2(pfd[1], 2);
64 |
65 | /* spawn the logging thread */
66 | if(pthread_create(&thr, 0, thread_func, 0) == -1)
67 | return; // fail silently
68 | pthread_detach(thr);
69 | }
70 |
71 | NATIVE(JSContextGroup,jlong,create) (PARAMS) {
72 | JSContextGroupRef group = JSContextGroupCreate();
73 | JSContextGroupRetain(group);
74 | return (long)group;
75 | }
76 |
77 | NATIVE(JSContextGroup,jlong,retain) (PARAMS,jlong group) {
78 | return (long) JSContextGroupRetain((JSContextGroupRef)group);
79 | }
80 |
81 | NATIVE(JSContextGroup,void,release) (PARAMS,jlong group) {
82 | JSContextGroupRelease((JSContextGroupRef) group);
83 | }
84 |
85 | NATIVE(JSContext,jlong,create) (PARAMS) {
86 | JSGlobalContextRef ref = JSGlobalContextCreate((JSClassRef) NULL);
87 | //JSGlobalContextRetain(ref);
88 | return (long)ref;
89 | }
90 |
91 | NATIVE(JSContext,jlong,createInGroup) (PARAMS,jlong group) {
92 | JSGlobalContextRef ref = JSGlobalContextCreateInGroup((JSContextGroupRef)group,
93 | (JSClassRef) NULL);
94 | //JSGlobalContextRetain(ref);
95 | return (long)ref;
96 | }
97 |
98 | NATIVE(JSContext,jlong,retain) (PARAMS,jlong ctx) {
99 | return (jlong) JSGlobalContextRetain((JSGlobalContextRef) ctx);
100 | }
101 |
102 | NATIVE(JSContext,void,release) (PARAMS,jlong ctx) {
103 | JSGlobalContextRelease((JSGlobalContextRef) ctx);
104 | }
105 |
106 | NATIVE(JSContext,jlong,getGlobalObject) (PARAMS, jlong ctx) {
107 | JSObjectRef ref = JSContextGetGlobalObject((JSContextRef) ctx);
108 | JSValueProtect((JSContextRef)ctx,ref);
109 | return (long)ref;
110 | }
111 |
112 | NATIVE(JSContext,jlong,getGroup) (PARAMS, jlong ctx) {
113 | JSContextGroupRef group = JSContextGetGroup((JSContextRef) ctx);
114 | JSContextGroupRetain(group);
115 | return (long)group;
116 | }
117 |
118 | NATIVE(JSContext,jobject,evaluateScript) (PARAMS, jlong ctx, jlong script,
119 | jlong thisObject, jlong sourceURL, int startingLineNumber) {
120 |
121 | JSValueRef exception = NULL;
122 |
123 | jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JSValue$JNIReturnObject");
124 | jmethodID cid = env->GetMethodID(ret,"","()V");
125 | jobject out = env->NewObject(ret, cid);
126 |
127 | jfieldID fid = env->GetFieldID(ret , "reference", "J");
128 |
129 | JSValueRef value = JSEvaluateScript(
130 | (JSContextRef)ctx,
131 | (JSStringRef)script,
132 | (JSObjectRef)thisObject,
133 | (JSStringRef)sourceURL,
134 | startingLineNumber,
135 | &exception);
136 | JSValueProtect((JSContextRef)ctx, value);
137 |
138 | env->SetLongField( out, fid, (long)value);
139 |
140 | fid = env->GetFieldID(ret , "exception", "J");
141 | env->SetLongField( out, fid, (jlong) exception);
142 |
143 | return out;
144 | }
145 |
146 | NATIVE(JSContext,jobject,checkScriptSyntax) (PARAMS, jlong ctx, jlong script,
147 | jlong sourceURL, jint startingLineNumber) {
148 |
149 | JSValueRef exception = NULL;
150 |
151 | jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JSValue$JNIReturnObject");
152 | jmethodID cid = env->GetMethodID(ret,"","()V");
153 | jobject out = env->NewObject(ret, cid);
154 |
155 | jfieldID fid = env->GetFieldID(ret , "reference", "J");
156 | bool value = JSCheckScriptSyntax(
157 | (JSContextRef)ctx,
158 | (JSStringRef)script,
159 | (JSStringRef)sourceURL,
160 | startingLineNumber,
161 | &exception);
162 | env->SetBooleanField( out, fid, value );
163 |
164 | fid = env->GetFieldID(ret , "exception", "J");
165 | env->SetLongField( out, fid, (jlong) exception);
166 |
167 | return out;
168 | }
169 |
170 | NATIVE(JSContext,void,garbageCollect) (PARAMS, jlong ctx) {
171 | JSGarbageCollect((JSContextRef)ctx);
172 | }
173 |
174 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/JSFunction.h:
--------------------------------------------------------------------------------
1 | //
2 | // JSFunction.h
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #ifndef ANDROIDJSCORE_JSFUNCTION_H
35 | #define ANDROIDJSCORE_JSFUNCTION_H
36 |
37 | #include "Instance.h"
38 |
39 | class JSFunction : public Instance {
40 | public:
41 | JSFunction(JNIEnv *env, jobject thiz, JSContextRef ctx, JSStringRef name = NULL);
42 | virtual ~JSFunction();
43 |
44 | private:
45 | static JSValueRef StaticFunctionCallback(JSContextRef ctx, JSObjectRef function,
46 | JSObjectRef thisObject,size_t argumentCount, const JSValueRef arguments[],
47 | JSValueRef* exception);
48 | static JSObjectRef StaticConstructorCallback(JSContextRef ctx,
49 | JSObjectRef constructor,size_t argumentCount,const JSValueRef arguments[],
50 | JSValueRef* exception);
51 | static bool StaticHasInstanceCallback(JSContextRef ctx, JSObjectRef constructor,
52 | JSValueRef possibleInstance, JSValueRef* exception);
53 | static JSClassDefinition JSFunctionClassDefinition();
54 |
55 | JSObjectRef ConstructorCallback(JSContextRef ctx, JSObjectRef constructor,
56 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
57 | JSValueRef FunctionCallback(JSContextRef ctx, JSObjectRef function,
58 | JSObjectRef thisObject, size_t argumentCount,const JSValueRef arguments[],
59 | JSValueRef* exception);
60 | bool HasInstanceCallback(JSContextRef ctx, JSObjectRef constructor,
61 | JSValueRef possibleInstance, JSValueRef* exception);
62 | };
63 |
64 | #endif //ANDROIDJSCORE_JSFUNCTION_H
65 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/JSJNI.h:
--------------------------------------------------------------------------------
1 | //
2 | // JSJNI.h
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #include
35 | #include
36 | #include
37 |
38 | #include "JavaScriptCore/JavaScript.h"
39 |
40 | #define NATIVE(package,rt,f) extern "C" \
41 | rt Java_org_liquidplayer_webkit_javascriptcore_##package##_##f
42 | #define PARAMS __attribute__((unused))JNIEnv* env, __attribute__((unused))jobject thiz
43 |
44 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/JSString.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // JSString.cpp
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #include "JSJNI.h"
35 |
36 | NATIVE(JSValue_00024JSString,jlong,createWithCharacters) (PARAMS, jstring str)
37 | {
38 | const jchar *chars = env->GetStringChars(str, NULL);
39 | JSStringRef string = JSStringRetain(JSStringCreateWithCharacters(chars,
40 | env->GetStringLength(str)));
41 | env->ReleaseStringChars(str,chars);
42 | return (long)string;
43 | }
44 |
45 | NATIVE(JSValue_00024JSString,jlong,createWithUTF8CString) (PARAMS, jstring str)
46 | {
47 | const char *string = env->GetStringUTFChars(str, NULL);
48 | JSStringRef ret = JSStringRetain(JSStringCreateWithUTF8CString(string));
49 | env->ReleaseStringUTFChars(str, string);
50 | return (long)ret;
51 | }
52 |
53 | NATIVE(JSValue_00024JSString,jlong,retain) (PARAMS, jlong strRef) {
54 | return (jlong) JSStringRetain((JSStringRef)strRef);
55 | }
56 |
57 | NATIVE(JSValue_00024JSString,void,release) (PARAMS, jlong stringRef) {
58 | JSStringRelease((JSStringRef)stringRef);
59 | }
60 |
61 | NATIVE(JSValue_00024JSString,jint,getLength) (PARAMS, jlong stringRef) {
62 | return (jint) JSStringGetLength((JSStringRef)stringRef);
63 | }
64 |
65 | NATIVE(JSValue_00024JSString,jstring,toString) (PARAMS, jlong stringRef) {
66 | char *buffer = new char[JSStringGetMaximumUTF8CStringSize((JSStringRef)stringRef)+1];
67 | JSStringGetUTF8CString((JSStringRef)stringRef, buffer,
68 | JSStringGetMaximumUTF8CStringSize((JSStringRef)stringRef)+1);
69 | jstring ret = env->NewStringUTF(buffer);
70 | delete buffer;
71 | return ret;
72 | }
73 |
74 | NATIVE(JSValue_00024JSString,jint,getMaximumUTF8CStringSize) (PARAMS, jlong stringRef) {
75 | return (jint) JSStringGetMaximumUTF8CStringSize((JSStringRef)stringRef);
76 | }
77 |
78 | NATIVE(JSValue_00024JSString,jboolean,isEqual) (PARAMS, jlong a, jlong b) {
79 | return (jboolean) JSStringIsEqual((JSStringRef)a, (JSStringRef)b);
80 | }
81 |
82 | NATIVE(JSValue_00024JSString,jboolean,isEqualToUTF8CString) (PARAMS, jlong a, jstring b) {
83 | const char *string = env->GetStringUTFChars(b, NULL);
84 | jboolean ret = JSStringIsEqualToUTF8CString((JSStringRef)a, string);
85 | env->ReleaseStringUTFChars(b, string);
86 | return ret;
87 | }
88 |
89 |
90 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/include/JavaScriptCore/JSStringRef.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 Apple Inc. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | *
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 | */
25 |
26 | #ifndef JSStringRef_h
27 | #define JSStringRef_h
28 |
29 | #include
30 |
31 | #ifndef __cplusplus
32 | #include
33 | #endif
34 | #include /* for size_t */
35 |
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | #if !defined(WIN32) && !defined(_WIN32) \
41 | && !((defined(__CC_ARM) || defined(__ARMCC__)) && !defined(__linux__)) /* RVCT */
42 | /*!
43 | @typedef JSChar
44 | @abstract A Unicode character.
45 | */
46 | typedef unsigned short JSChar;
47 | #else
48 | typedef wchar_t JSChar;
49 | #endif
50 |
51 | /*!
52 | @function
53 | @abstract Creates a JavaScript string from a buffer of Unicode characters.
54 | @param chars The buffer of Unicode characters to copy into the new JSString.
55 | @param numChars The number of characters to copy from the buffer pointed to by chars.
56 | @result A JSString containing chars. Ownership follows the Create Rule.
57 | */
58 | JS_EXPORT JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
59 | /*!
60 | @function
61 | @abstract Creates a JavaScript string from a null-terminated UTF8 string.
62 | @param string The null-terminated UTF8 string to copy into the new JSString.
63 | @result A JSString containing string. Ownership follows the Create Rule.
64 | */
65 | JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string);
66 |
67 | /*!
68 | @function
69 | @abstract Retains a JavaScript string.
70 | @param string The JSString to retain.
71 | @result A JSString that is the same as string.
72 | */
73 | JS_EXPORT JSStringRef JSStringRetain(JSStringRef string);
74 | /*!
75 | @function
76 | @abstract Releases a JavaScript string.
77 | @param string The JSString to release.
78 | */
79 | JS_EXPORT void JSStringRelease(JSStringRef string);
80 |
81 | /*!
82 | @function
83 | @abstract Returns the number of Unicode characters in a JavaScript string.
84 | @param string The JSString whose length (in Unicode characters) you want to know.
85 | @result The number of Unicode characters stored in string.
86 | */
87 | JS_EXPORT size_t JSStringGetLength(JSStringRef string);
88 | /*!
89 | @function
90 | @abstract Returns a pointer to the Unicode character buffer that
91 | serves as the backing store for a JavaScript string.
92 | @param string The JSString whose backing store you want to access.
93 | @result A pointer to the Unicode character buffer that serves as string's
94 | backing store, which will be deallocated when string is deallocated.
95 | */
96 | JS_EXPORT const JSChar* JSStringGetCharactersPtr(JSStringRef string);
97 |
98 | /*!
99 | @function
100 | @abstract Returns the maximum number of bytes a JavaScript string will
101 | take up if converted into a null-terminated UTF8 string.
102 | @param string The JSString whose maximum converted size (in bytes) you
103 | want to know.
104 | @result The maximum number of bytes that could be required to convert string into a
105 | null-terminated UTF8 string. The number of bytes that the conversion actually ends
106 | up requiring could be less than this, but never more.
107 | */
108 | JS_EXPORT size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
109 | /*!
110 | @function
111 | @abstract Converts a JavaScript string into a null-terminated UTF8 string,
112 | and copies the result into an external byte buffer.
113 | @param string The source JSString.
114 | @param buffer The destination byte buffer into which to copy a null-terminated
115 | UTF8 representation of string. On return, buffer contains a UTF8 string
116 | representation of string. If bufferSize is too small, buffer will contain only
117 | partial results. If buffer is not at least bufferSize bytes in size,
118 | behavior is undefined.
119 | @param bufferSize The size of the external buffer in bytes.
120 | @result The number of bytes written into buffer (including the null-terminator byte).
121 | */
122 | JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
123 |
124 | /*!
125 | @function
126 | @abstract Tests whether two JavaScript strings match.
127 | @param a The first JSString to test.
128 | @param b The second JSString to test.
129 | @result true if the two strings match, otherwise false.
130 | */
131 | JS_EXPORT bool JSStringIsEqual(JSStringRef a, JSStringRef b);
132 | /*!
133 | @function
134 | @abstract Tests whether a JavaScript string matches a null-terminated UTF8 string.
135 | @param a The JSString to test.
136 | @param b The null-terminated UTF8 string to test.
137 | @result true if the two strings match, otherwise false.
138 | */
139 | JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
140 |
141 | #ifdef __cplusplus
142 | }
143 | #endif
144 |
145 | #endif /* JSStringRef_h */
146 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/include/JavaScriptCore/JavaScript.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 Apple Inc. All rights reserved.
3 | * Copyright (C) 2008 Alp Toker
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef JavaScript_h
28 | #define JavaScript_h
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #endif /* JavaScript_h */
37 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/include/JavaScriptCore/WebKitAvailability.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008, 2009, 2010, 2014 Apple Inc. All Rights Reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | *
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 | */
25 |
26 | #ifndef __WebKitAvailability__
27 | #define __WebKitAvailability__
28 |
29 | #if defined(__APPLE__) && !defined(BUILDING_GTK__)
30 |
31 | #include
32 | #include
33 |
34 | #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
35 | /* To support availability macros that mention newer OS X versions when building on older OS X versions,
36 | we provide our own definitions of the underlying macros that the availability macros expand to. We're
37 | free to expand the macros as no-ops since frameworks built on older OS X versions only ship bundled with
38 | an application rather than as part of the system.
39 | */
40 |
41 | #ifndef __NSi_10_10 // Building from trunk rather than SDK.
42 | #define __NSi_10_10 introduced=10.0 // Use 10.0 to indicate that everything is available.
43 | #endif
44 |
45 | #ifndef __NSi_10_11 // Building from trunk rather than SDK.
46 | #define __NSi_10_11 introduced=10.0 // Use 10.0 to indicate that everything is available.
47 | #endif
48 |
49 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_9
50 | #define __AVAILABILITY_INTERNAL__MAC_10_9
51 | #endif
52 |
53 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_10
54 | #define __AVAILABILITY_INTERNAL__MAC_10_10
55 | #endif
56 |
57 | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER
58 | #define AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER
59 | #endif
60 |
61 | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER
62 | #define AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER
63 | #endif
64 |
65 | #endif /* __MAC_OS_X_VERSION_MIN_REQUIRED <= 101100 */
66 |
67 | #else
68 | #define CF_AVAILABLE(_mac, _ios)
69 | #endif
70 |
71 | #endif /* __WebKitAvailability__ */
72 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/arm64-v8a/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/arm64-v8a/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/armeabi-v7a/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/armeabi-v7a/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/armeabi/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/armeabi/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/mips/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/mips/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/mips64/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/mips64/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/x86/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/x86/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/jni/lib/x86_64/libjavascriptcoregtk-4.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/AndroidJSCore-library/jni/lib/x86_64/libjavascriptcoregtk-4.0.so
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Eric/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSArrayBufferTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.*;
7 | import static org.hamcrest.Matchers.*;
8 |
9 | public class JSArrayBufferTest {
10 |
11 | private JSContext context;
12 | private JSArrayBuffer arrayBuffer;
13 | private final int BYTE_LENGTH = 100;
14 |
15 | @Before
16 | public void setUp() throws Exception {
17 | context = new JSContext();
18 | arrayBuffer = new JSArrayBuffer(context,BYTE_LENGTH);
19 | }
20 |
21 | @Test
22 | public void testGetJSObject() throws Exception {
23 | JSObject obj = arrayBuffer.getJSObject();
24 |
25 | assertEquals(arrayBuffer.byteLength(),obj.property("byteLength").toNumber().intValue());
26 | }
27 |
28 | @Test
29 | public void testByteLength() throws Exception {
30 | assertThat(arrayBuffer.byteLength(),is(BYTE_LENGTH));
31 | }
32 |
33 | @Test
34 | public void testIsView() throws Exception {
35 | assertFalse(JSArrayBuffer.isView(new JSArray<>(context,JSValue.class)));
36 | assertFalse(JSArrayBuffer.isView(new JSObject(context)));
37 | assertFalse(JSArrayBuffer.isView(new JSValue(context,null)));
38 | assertFalse(JSArrayBuffer.isView(new JSValue(context)));
39 | assertFalse(JSArrayBuffer.isView(new JSArrayBuffer(context,10).getJSObject()));
40 |
41 | assertTrue(JSArrayBuffer.isView(new JSUint8Array(context,0)));
42 | assertTrue(JSArrayBuffer.isView(new JSFloat32Array(context,0)));
43 | assertTrue(JSArrayBuffer.isView(new JSInt8Array(context,10).subarray(0, 3)));
44 |
45 | JSArrayBuffer buffer = new JSArrayBuffer(context,2);
46 | JSDataView dv = new JSDataView(buffer);
47 | assertTrue(JSArrayBuffer.isView(dv));
48 | }
49 |
50 | @Test
51 | public void testSlice() throws Exception {
52 | JSArrayBuffer buf1 = new JSArrayBuffer(context,8);
53 | new JSInt32Array(buf1).set(0,42);
54 | JSArrayBuffer buf2 = buf1.slice(0);
55 |
56 | assertEquals(buf1.byteLength(),buf2.byteLength());
57 | assertThat(new JSInt32Array(buf1).get(0),is(42));
58 | assertThat(new JSInt32Array(buf2).get(0),is(42));
59 |
60 | new JSInt32Array(buf1).set(0,69);
61 | assertThat(new JSInt32Array(buf1).get(0),is(69));
62 | assertThat(new JSInt32Array(buf2).get(0),is(42));
63 |
64 | JSArrayBuffer buf3 = buf2.slice(0,4);
65 | assertThat(buf3.byteLength(),is(4));
66 | assertNotEquals(buf3.byteLength(),buf2.byteLength());
67 | assertThat(new JSInt32Array(buf3).get(0),is(42));
68 | }
69 |
70 | @org.junit.After
71 | public void shutDown() {
72 | Runtime.getRuntime().gc();
73 | }
74 |
75 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSDataViewTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.*;
7 |
8 | public class JSDataViewTest {
9 |
10 | private JSContext context;
11 |
12 | @Before
13 | public void setUp() throws Exception {
14 | context = new JSContext();
15 | }
16 |
17 | @Test
18 | public void testConstructorsAndProperties() throws Exception {
19 | JSArrayBuffer buffer = new JSArrayBuffer(context,8);
20 | JSDataView view = new JSDataView(buffer);
21 | assertEquals(buffer.byteLength(),view.buffer().byteLength());
22 | assertEquals(view.byteLength(),buffer.byteLength());
23 | assertEquals(view.byteOffset(),0);
24 |
25 | JSDataView view2 = new JSDataView(buffer,4);
26 | assertEquals(buffer.byteLength(),view2.buffer().byteLength());
27 | assertEquals(view2.byteLength(),4);
28 | assertEquals(view2.byteOffset(),4);
29 |
30 | JSDataView view3 = new JSDataView(buffer,4,2);
31 | assertEquals(buffer.byteLength(),view3.buffer().byteLength());
32 | assertEquals(view3.byteLength(),2);
33 | assertEquals(view3.byteOffset(),4);
34 |
35 | JSDataView view4 = new JSDataView(view3);
36 | assertTrue(view4.isStrictEqual(view3));
37 | }
38 |
39 | @Test
40 | public void testFloat32() throws Exception {
41 | JSDataView view = new JSDataView(new JSArrayBuffer(context,12));
42 | view.setFloat32(0,5.56f);
43 | view.setFloat32(4,6.87f,true);
44 | view.setFloat32(8,6.87f,false);
45 |
46 | assertTrue(view.getFloat32(0).equals(5.56f));
47 | assertTrue(view.getFloat32(4,true).equals(6.87f));
48 | assertTrue(view.getFloat32(8,false).equals(6.87f));
49 | assertFalse(view.getFloat32(4,false).equals(6.87f));
50 | assertFalse(view.getFloat32(8,true).equals(6.87f));
51 | }
52 |
53 | @Test
54 | public void testFloat64() throws Exception {
55 | JSDataView view = new JSDataView(new JSArrayBuffer(context,24));
56 | view.setFloat64(0,5.5678);
57 | view.setFloat64(8,6.8765,true);
58 | view.setFloat64(16,6.8765,false);
59 |
60 | assertTrue(view.getFloat64(0).equals(5.5678));
61 | assertTrue(view.getFloat64(8,true).equals(6.8765));
62 | assertTrue(view.getFloat64(16,false).equals(6.8765));
63 | assertFalse(view.getFloat64(6,false).equals(6.8765));
64 | assertFalse(view.getFloat64(16,true).equals(6.8765));
65 | }
66 |
67 | @Test
68 | public void testInt32() throws Exception {
69 | JSDataView view = new JSDataView(new JSArrayBuffer(context,12));
70 | view.setInt32(0,5);
71 | view.setInt32(4,6,true);
72 | view.setInt32(8,6,false);
73 |
74 | assertTrue(view.getInt32(0).equals(5));
75 | assertTrue(view.getInt32(4,true).equals(6));
76 | assertTrue(view.getInt32(8,false).equals(6));
77 | assertFalse(view.getInt32(4,false).equals(6));
78 | assertFalse(view.getInt32(8,true).equals(6));
79 | }
80 |
81 | @Test
82 | public void testInt16() throws Exception {
83 | JSDataView view = new JSDataView(new JSArrayBuffer(context,6));
84 | view.setInt16(0,(short)5);
85 | view.setInt16(2,(short)-6,true);
86 | view.setInt16(4,(short)-6,false);
87 |
88 | assertTrue(view.getInt16(0).equals((short)5));
89 | assertTrue(view.getInt16(2,true).equals((short)-6));
90 | assertTrue(view.getInt16(4,false).equals((short)-6));
91 | assertFalse(view.getInt16(2,false).equals((short)-6));
92 | assertFalse(view.getInt16(4,true).equals((short)-6));
93 | }
94 |
95 | @Test
96 | public void testInt8() throws Exception {
97 | JSDataView view = new JSDataView(new JSArrayBuffer(context,2));
98 | view.setInt8(0,(byte)5);
99 | view.setInt8(1,(byte)-6);
100 |
101 | assertTrue(view.getInt8(0).equals((byte)5));
102 | assertTrue(view.getInt8(1).equals((byte)-6));
103 | }
104 |
105 | @Test
106 | public void testUint32() throws Exception {
107 | JSDataView view = new JSDataView(new JSArrayBuffer(context,12));
108 | view.setUint32(0,0xffffffffL);
109 | view.setUint32(4,6L,true);
110 | view.setUint32(8,6L,false);
111 |
112 | assertEquals(0xffffffffL,view.getUint32(0).longValue());
113 | assertTrue(view.getUint32(0).equals(0xffffffffL));
114 | assertTrue(view.getUint32(4,true).equals(6L));
115 | assertTrue(view.getUint32(8,false).equals(6L));
116 | assertFalse(view.getUint32(4,false).equals(6L));
117 | assertFalse(view.getUint32(8,true).equals(6L));
118 | }
119 |
120 | @Test
121 | public void testUint16() throws Exception {
122 | JSDataView view = new JSDataView(new JSArrayBuffer(context,6));
123 | view.setUint16(0,(short)0xfffe);
124 | view.setUint16(2,(short)6,true);
125 | view.setUint16(4,(short)6,false);
126 |
127 | assertTrue(view.getUint16(0).equals((short)0xfffe));
128 | assertTrue(view.getUint16(2,true).equals((short)6));
129 | assertTrue(view.getUint16(4,false).equals((short)6));
130 | assertFalse(view.getUint16(2,false).equals((short)6));
131 | assertFalse(view.getUint16(4,true).equals((short)6));
132 | }
133 |
134 | @Test
135 | public void testUint8() throws Exception {
136 | JSDataView view = new JSDataView(new JSArrayBuffer(context,2));
137 | view.setUint8(0,(byte)0xfd);
138 | view.setUint8(1,(byte)6);
139 |
140 | assertTrue(view.getUint8(0).equals((byte)0xfd));
141 | assertTrue(view.getUint8(1).equals((byte)6));
142 | }
143 |
144 | @org.junit.After
145 | public void shutDown() {
146 | Runtime.getRuntime().gc();
147 | }
148 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSErrorTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 | import static org.hamcrest.Matchers.*;
7 |
8 | public class JSErrorTest {
9 |
10 | @Test
11 | public void TestJSErrorAndJSException() throws Exception {
12 | JSContext context = new JSContext();
13 |
14 | JSError error = new JSError(context, "This is an error message");
15 | assertThat(error.message(),is("This is an error message"));
16 | assertThat(error.name(),is("Error"));
17 | assertThat(error.stack(),is("undefined"));
18 |
19 | JSError error2 = new JSError(context, "Message2");
20 | assertThat(error2.message(),is("Message2"));
21 | assertThat(error2.name(),is("Error"));
22 | assertThat(error2.stack(),is("undefined"));
23 |
24 | JSError error3 = new JSError(context);
25 | assertThat(error3.message(),is(""));
26 | assertThat(error3.name(),is("Error"));
27 | assertThat(error3.stack(),is("undefined"));
28 |
29 | JSFunction fail = new JSFunction(context, "_fail", new String[] {},
30 | "var undef; var foo = undef.accessme;",
31 | "fail.js", 10) {
32 | };
33 | try {
34 | fail.call();
35 | assertFalse(true); // should not get here
36 | } catch (JSException e) {
37 | JSError error4 = e.getError();
38 | assertThat(error4.message(),is("undefined is not an object (evaluating 'undef.accessme')"));
39 | assertThat(e.getMessage(),is("undefined is not an object (evaluating 'undef.accessme')"));
40 | assertThat(e.toString(),is("TypeError: undefined is not an object (evaluating 'undef.accessme')"));
41 | assertThat(error4.name(),is("TypeError"));
42 | assertThat(e.name(),is("TypeError"));
43 | assertThat(error4.stack(),is("_fail@fail.js:11:27"));
44 | assertThat(e.stack(),is("_fail@fail.js:11:27"));
45 | }
46 |
47 | try {
48 | context.property("_error_",error);
49 | context.evaluateScript("throw _error_;",null,"main.js",1);
50 | assertFalse(true); // should not get here
51 | } catch (JSException e) {
52 | JSError error4 = e.getError();
53 | assertThat(error4.message(),is("This is an error message"));
54 | assertThat(e.getMessage(),is("This is an error message"));
55 | assertThat(e.toString(),is("Error: This is an error message"));
56 | assertThat(error4.name(),is("Error"));
57 | assertThat(e.name(),is("Error"));
58 | assertThat(error4.stack(),is("undefined"));
59 | assertThat(e.stack(),is("undefined"));
60 | }
61 |
62 | try {
63 | throw new JSException(error);
64 | } catch (JSException e) {
65 | JSError error5 = e.getError();
66 | assertThat(error5.message(),is("This is an error message"));
67 | assertThat(e.getMessage(),is("This is an error message"));
68 | assertThat(e.toString(),is("Error: This is an error message"));
69 | assertThat(error5.name(),is("Error"));
70 | assertThat(e.name(),is("Error"));
71 | assertThat(error5.stack(),is("undefined"));
72 | assertThat(e.stack(),is("undefined"));
73 | }
74 |
75 | try {
76 | throw new JSException(context,"Another exception");
77 | } catch (JSException e) {
78 | JSError error5 = e.getError();
79 | assertThat(error5.message(),is("Another exception"));
80 | assertThat(e.getMessage(),is("Another exception"));
81 | assertThat(e.toString(),is("Error: Another exception"));
82 | assertThat(error5.name(),is("Error"));
83 | assertThat(e.name(),is("Error"));
84 | assertThat(error5.stack(),is("undefined"));
85 | assertThat(e.stack(),is("undefined"));
86 | }
87 |
88 | try {
89 | throw new JSException(context,null);
90 | } catch (JSException e) {
91 | assertNotNull(e.getError());
92 | assertNull(e.getMessage());
93 | assertThat(e.toString(),is("Error: null"));
94 | assertThat(e.name(),is("Error"));
95 | assertThat(e.stack(),is("undefined"));
96 | }
97 | }
98 |
99 | @Test
100 | @SuppressWarnings("deprecation")
101 | public void testDeprecatedFunctions() {
102 | boolean exception = false;
103 | try {
104 | new JSError(new JSContext(), "foo", "bar.js", 1);
105 | } catch(UnsupportedOperationException e) {
106 | exception = true;
107 | }
108 | assertTrue(exception);
109 | }
110 |
111 | @org.junit.After
112 | public void shutDown() {
113 | Runtime.getRuntime().gc();
114 | }
115 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSIteratorTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.Arrays;
6 |
7 | import static org.junit.Assert.*;
8 |
9 | public class JSIteratorTest {
10 |
11 | @Test
12 | public void testJSIterator() throws Exception {
13 | JSContext context = new JSContext();
14 | JSArray array = new JSArray<>(context, Arrays.asList(1,2,3,4,5), Integer.class);
15 | JSArray.ValuesIterator iterator = array.values();
16 |
17 | int i=0;
18 | for(; iterator.hasNext(); i++) {
19 | assertEquals(iterator.next(),array.get(i));
20 | boolean exception = false;
21 | try {
22 | iterator.remove();
23 | } catch (UnsupportedOperationException e) {
24 | exception = true;
25 | } finally {
26 | assertTrue(exception);
27 | }
28 | }
29 | assertEquals(i,array.size());
30 | }
31 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSONTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import java.util.Arrays;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | public class JSONTest {
13 |
14 | private JSContext context;
15 |
16 | @Before
17 | public void setUp() throws Exception {
18 | context = new JSContext();
19 | }
20 |
21 | @Test
22 | public void testStringify() throws Exception {
23 | context.evaluateScript("var s1 = JSON.stringify(1);");
24 | context.evaluateScript("var s2 = JSON.stringify('abc');");
25 | context.evaluateScript("var s3 = JSON.stringify([1,2,3]);");
26 | context.evaluateScript("var s4 = JSON.stringify({foo:'bar'});");
27 | String s1 = JSON.stringify(context,1);
28 | String s2 = JSON.stringify(context,"abc");
29 | String s3 = JSON.stringify(context, Arrays.asList(1,2,3));
30 | Map map = new HashMap<>();
31 | map.put("foo","bar");
32 | String s4 = JSON.stringify(context, map);
33 | assertEquals(context.property("s1").toString(),s1);
34 | assertEquals(context.property("s2").toString(),s2);
35 | assertEquals(context.property("s3").toString(),s3);
36 | assertEquals(context.property("s4").toString(),s4);
37 | }
38 |
39 | @Test
40 | public void testStringify1() throws Exception {
41 | context.evaluateScript("var s1 = JSON.stringify(1);");
42 | context.evaluateScript("var s2 = JSON.stringify('abc');");
43 | context.evaluateScript("var s3 = JSON.stringify([1,2,3]);");
44 | context.evaluateScript("var s4 = JSON.stringify({foo:'bar'});");
45 | String s1 = JSON.stringify(new JSValue(context,1));
46 | String s2 = JSON.stringify(new JSValue(context,"abc"));
47 | String s3 = JSON.stringify(new JSValue(context, Arrays.asList(1,2,3)));
48 | Map map = new HashMap<>();
49 | map.put("foo","bar");
50 | String s4 = JSON.stringify(new JSValue(context, map));
51 | assertEquals(context.property("s1").toString(),s1);
52 | assertEquals(context.property("s2").toString(),s2);
53 | assertEquals(context.property("s3").toString(),s3);
54 | assertEquals(context.property("s4").toString(),s4);
55 | }
56 |
57 | @Test
58 | public void testParse() throws Exception {
59 | context.evaluateScript("var s1 = JSON.stringify(1);");
60 | context.evaluateScript("var s2 = JSON.stringify('abc');");
61 | context.evaluateScript("var s3 = JSON.stringify([1,2,3]);");
62 | context.evaluateScript("var s4 = JSON.stringify({foo:'bar'});");
63 | JSValue v1 = JSON.parse(context,context.property("s1").toString());
64 | JSValue v2 = JSON.parse(context,context.property("s2").toString());
65 | JSValue v3 = JSON.parse(context,context.property("s3").toString());
66 | JSValue v4 = JSON.parse(context,context.property("s4").toString());
67 | assertEquals(v1.toNumber().intValue(),1);
68 | assertEquals(v2.toString(),"abc");
69 | assertEquals(v3.toJSArray(),Arrays.asList(1,2,3));
70 | assertEquals(v4.toObject().property("foo").toString(),"bar");
71 |
72 | JSValue v5 = JSON.parse(context,"x,z,1");
73 | assertTrue(v5.isNull());
74 | }
75 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSRegExpTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | public class JSRegExpTest {
8 | @Test
9 | public void testJSRegExp() throws Exception {
10 | JSContext context = new JSContext();
11 |
12 | JSRegExp regExp = new JSRegExp(context,"quick\\s(brown).+?(jumps)","ig");
13 | JSRegExp.ExecResult result = regExp.exec("The Quick Brown Fox Jumps Over The Lazy Dog");
14 | assertEquals(result.get(0),"Quick Brown Fox Jumps");
15 | assertEquals(result.get(1),"Brown");
16 | assertEquals(result.get(2),"Jumps");
17 | assertEquals(result.index().intValue(),4);
18 | assertEquals(result.input(),"The Quick Brown Fox Jumps Over The Lazy Dog");
19 |
20 | assertEquals(regExp.lastIndex().intValue(),25);
21 | assertEquals(regExp.ignoreCase(),true);
22 | assertEquals(regExp.global(),true);
23 | assertEquals(regExp.multiline(),false);
24 | assertEquals(regExp.source(),"quick\\s(brown).+?(jumps)");
25 |
26 | JSRegExp regExp2 = new JSRegExp(context,"quick\\s(brown).+?(jumps)");
27 | assertEquals(regExp2.ignoreCase(),false);
28 | assertEquals(regExp2.global(),false);
29 | assertEquals(regExp2.multiline(),false);
30 |
31 | String str = "hello world!";
32 | assertTrue(new JSRegExp(context,"^hello").test(str));
33 | }
34 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/androidTest/java/org/liquidplayer/webkit/javascriptcore/JSTypedArrayTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | public class JSTypedArrayTest {
8 |
9 | @Test
10 | public void testJSTypedArray() throws Exception {
11 | JSContext context = new JSContext();
12 | boolean exception = false;
13 | try {
14 | JSTypedArray.from(new JSObject(context));
15 | } catch (JSException e) {
16 | exception = true;
17 | } finally {
18 | assertTrue(exception);
19 | }
20 |
21 | assertFalse(JSTypedArray.isTypedArray(new JSValue(context)));
22 | }
23 | }
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSArrayBuffer.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSArrayBuffer.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | /**
36 | * A wrapper class for a JavaScript ArrayBuffer
37 | * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
38 | * Note, experimental ArrayBuffer.transfer() is not supported by this JavaScriptCore version
39 | * @since 3.0
40 | */
41 | public class JSArrayBuffer extends JSObjectWrapper {
42 | /**
43 | * Creates a new array buffer of 'length' bytes
44 | * @param ctx the JSContext in which to create the ArrayBuffer
45 | * @param length the length in bytes of the ArrayBuffer
46 | * @since 3.0
47 | */
48 | public JSArrayBuffer(JSContext ctx, int length) {
49 | super(new JSFunction(ctx,"_ArrayBuffer",new String[] {"length"},
50 | "return new ArrayBuffer(length);",
51 | null, 0).call(null,length).toObject());
52 | }
53 |
54 | /**
55 | * Treats an existing JSObject as an ArrayBuffer. It is up to the user to ensure the
56 | * underlying JSObject is actually an ArrayBuffer.
57 | * @param buffer The ArrayBuffer JSObject to wrap
58 | * @since 3.0
59 | */
60 | public JSArrayBuffer(JSObject buffer) {
61 | super(buffer);
62 | }
63 |
64 | /**
65 | * JavaScript: ArrayBuffer.prototype.byteLength, see:
66 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength
67 | * @return length of ArrayBuffer in bytes
68 | * @since 3.0
69 | */
70 | public int byteLength() {
71 | return property("byteLength").toNumber().intValue();
72 | }
73 |
74 | /**
75 | * JavaScript: ArrayBuffer.isView(), see:
76 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
77 | * @param arg the argument to be checked
78 | * @return true if arg is one of the ArrayBuffer views, such as typed array objects or
79 | * a DataView; false otherwise
80 | * @since 3.0
81 | */
82 | public static boolean isView(JSValue arg) {
83 | return arg.getContext().property("ArrayBuffer").toObject().property("isView").toFunction()
84 | .call(null,arg).toBoolean();
85 | }
86 |
87 | /**
88 | * JavaScript: ArrayBuffer.prototype.slice(), see:
89 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice
90 | * @param begin Zero-based byte index at which to begin slicing
91 | * @param end Byte index to end slicing
92 | * @return new ArrayBuffer with sliced contents copied
93 | * @since 3.0
94 | */
95 | public JSArrayBuffer slice(int begin, int end) {
96 | return new JSArrayBuffer(
97 | property("slice").toFunction().call(this,begin,end).toObject());
98 | }
99 | /**
100 | * JavaScript: ArrayBuffer.prototype.slice(), see:
101 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice
102 | * @param begin Zero-based byte index at which to begin slicing
103 | * @return new ArrayBuffer with sliced contents copied
104 | * @since 3.0
105 | */
106 | public JSArrayBuffer slice(int begin) {
107 | return new JSArrayBuffer(
108 | property("slice").toFunction().call(this,begin).toObject());
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSContextGroup.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSContextGroup.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | /**
36 | * A JSContextGroup associates JavaScript contexts with one another. Contexts
37 | * in the same group may share and exchange JavaScript objects. Sharing and/or
38 | * exchanging JavaScript objects between contexts in different groups will produce
39 | * undefined behavior. When objects from the same context group are used in multiple
40 | * threads, explicit synchronization is required.
41 | *
42 | */
43 | public class JSContextGroup {
44 | private Long group;
45 |
46 | /**
47 | * Creates a new context group
48 | * @since 1.0
49 | */
50 | public JSContextGroup() {
51 | group = create();
52 | }
53 | /**
54 | * Wraps an existing context group
55 | * @param groupRef the JavaScriptCore context group reference
56 | * @since 1.0
57 | */
58 | public JSContextGroup(Long groupRef)
59 | {
60 | group = groupRef;
61 | }
62 |
63 | @Override
64 | protected void finalize() throws Throwable {
65 | if (group!=0) release(group);
66 | super.finalize();
67 | }
68 |
69 | /**
70 | * Gets the JavaScriptCore context group reference
71 | * @since 1.0
72 | * @return the JavaScriptCore context group reference
73 | */
74 | public Long groupRef() {
75 | return group;
76 | }
77 |
78 | /**
79 | * Checks if two JSContextGroups refer to the same JS context group
80 | * @param other the other object to compare
81 | * @return true if refer to same context group, false otherwise
82 | * @since 2.2
83 | */
84 | @Override
85 | public boolean equals(Object other) {
86 | return (other !=null) &&
87 | (this == other) ||
88 | (other instanceof JSContextGroup) &&
89 | !(groupRef() == null || groupRef() == 0) &&
90 | groupRef().equals(((JSContextGroup)other).groupRef());
91 | }
92 |
93 | protected native long create();
94 | protected native long retain(long group);
95 | protected native void release(long group);
96 | }
97 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSError.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSError.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | /**
36 | * A convenience class for managing JavaScript error objects
37 | * @since 1.0
38 | */
39 | public class JSError extends JSObject {
40 | /**
41 | * Generates a JavaScript throwable exception object
42 | * @param ctx The context in which to create the error
43 | * @param message The description of the error
44 | * @since 1.0
45 | */
46 | public JSError(JSContext ctx, String message) {
47 | context = ctx;
48 | long [] args = {
49 | new JSValue(context,message).valueRef()
50 | };
51 | JNIReturnObject jni = makeError(context.ctxRef(), args);
52 | if (BuildConfig.DEBUG && jni.exception != 0) throw new AssertionError();
53 | valueRef = jni.reference;
54 | }
55 | /**
56 | * Generates a JavaScript throwable exception object
57 | * @param ctx The context in which to create the error
58 | * @since 1.0
59 | */
60 | public JSError(JSContext ctx) {
61 | context = ctx;
62 | JNIReturnObject jni = makeError(context.ctxRef(), new long[0]);
63 | if (BuildConfig.DEBUG && jni.exception != 0) throw new AssertionError();
64 | valueRef = jni.reference;
65 | }
66 |
67 | /**
68 | * Constructs a JSError from a JSValue. Assumes JSValue is a properly constructed JS Error
69 | * object.
70 | * @param error the JavaScript Error object
71 | */
72 | public JSError(JSValue error) {
73 | super(error.valueRef(), error.getContext());
74 | }
75 |
76 | /**
77 | * JavaScript error stack trace, see:
78 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
79 | * @return stack trace for error
80 | * @since 3.0
81 | */
82 | public String stack() {
83 | return property("stack").toString();
84 | }
85 |
86 | /**
87 | * JavaScript error message, see:
88 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message
89 | * @return error message
90 | * @since 3.0
91 | */
92 | public String message() {
93 | return property("message").toString();
94 | }
95 |
96 | /**
97 | * JavaScript error name, see:
98 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name
99 | * @return error name
100 | * @since 3.0
101 | */
102 | public String name() {
103 | return property("name").toString();
104 | }
105 |
106 | /* -- Deprecated -- */
107 |
108 | /**
109 | * Deprecated since 3.0. filename and lineNumber not supported by JavaScriptCoreGTK
110 | * @param ctx The context in which to create the error
111 | * @param message The description of the error
112 | * @param filename The name of the file in which the error occurred. This is used for stack
113 | * tracing and is optional.
114 | * @param lineNumber The line number where the error occurred. This is used for stack tracing
115 | * and is optional.
116 | * @since 1.0
117 | */
118 | @Deprecated
119 | @SuppressWarnings("unused")
120 | public JSError(JSContext ctx, String message, String filename, Integer lineNumber) {
121 | throw new UnsupportedOperationException();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSException.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSException.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | /**
36 | * A JSException is thrown for a number of different reasons, mostly by the JavaScriptCore
37 | * library. The description of the exception is given in the message.
38 | * @since 1.0
39 | *
40 | */
41 | public class JSException extends RuntimeException {
42 | private static final long serialVersionUID = 1L;
43 |
44 | private JSError error;
45 |
46 | /**
47 | * Creates a Java exception from a thrown JavaScript exception
48 | * @param error The JSValue thrown by the JavaScriptCore engine
49 | * @since 1.0
50 | */
51 | public JSException(JSValue error) {
52 | super(new JSError(error).message());
53 | this.error = new JSError(error);
54 | }
55 |
56 | /**
57 | * Creates a JavaScriptCore exception from a string message
58 | * @param ctx The JSContext in which to create the exception
59 | * @param message The exception meessage
60 | * @since 1.0
61 | */
62 | public JSException(JSContext ctx, String message) {
63 | super(message);
64 | try {
65 | this.error = new JSError(ctx,message);
66 | } catch (JSException e) {
67 | // We are having an Exception Inception. Stop the madness
68 | this.error = null;
69 | }
70 | }
71 | /**
72 | * Gets the JSValue of the thrown exception
73 | * @return the JSValue of the JavaScriptCore exception
74 | * @since 1.0
75 | */
76 | public JSError getError() {
77 | return error;
78 | }
79 |
80 | /**
81 | * JavaScript error stack trace, see:
82 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
83 | * @return stack trace for error
84 | * @since 3.0
85 | */
86 | public String stack() {
87 | return (error!=null) ? error.stack() : "undefined";
88 | }
89 |
90 | /**
91 | * JavaScript error name, see:
92 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name
93 | * @return error name
94 | * @since 3.0
95 | */
96 | public String name() {
97 | return (error!=null) ? error.name() : "JSError";
98 | }
99 |
100 | @Override
101 | public String toString() {
102 | if (error!=null) {
103 | try {
104 | return error.toString();
105 | } catch (JSException e) {
106 | return "Unknown Error";
107 | }
108 | }
109 | return "Unknown Error";
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSFloat32Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSFloat32Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Float32Array
39 | * @since 3.0
40 | */
41 | public class JSFloat32Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSFloat32Array(JSContext ctx, int length) {
49 | super(ctx,length,"Float32Array",Float.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSFloat32Array from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSFloat32Array(JSTypedArray tarr) {
58 | super(tarr,"Float32Array",Float.class);
59 | }
60 |
61 | /**
62 | * Creates new typed array as if by TypedArray.from()
63 | * @param ctx The context in which to create the typed array
64 | * @param object The object to create the array from
65 | * @since 3.0
66 | */
67 | public JSFloat32Array(JSContext ctx, Object object) {
68 | super(ctx,object,"Float32Array",Float.class);
69 | }
70 |
71 | /**
72 | * Creates a typed array from a JSArrayBuffer
73 | * @param buffer The JSArrayBuffer to create the typed array from
74 | * @param byteOffset The byte offset in the ArrayBuffer to start from
75 | * @param length The number of elements (not bytes!) from 'byteOffset' to include in the array
76 | * @since 3.0
77 | */
78 | public JSFloat32Array(JSArrayBuffer buffer, int byteOffset, int length) {
79 | super(buffer,byteOffset,length,"Float32Array",Float.class);
80 | }
81 | /**
82 | * Creates a typed array from a JSArrayBuffer
83 | * @param buffer The JSArrayBuffer to create the typed array from
84 | * @param byteOffset The byte offset in the ArrayBuffer to start from
85 | * @since 3.0
86 | */
87 | public JSFloat32Array(JSArrayBuffer buffer, int byteOffset) {
88 | super(buffer,byteOffset,"Float32Array",Float.class);
89 | }
90 | /**
91 | * Creates a typed array from a JSArrayBuffer
92 | * @param buffer The JSArrayBuffer to create the typed array from
93 | * @since 3.0
94 | */
95 | public JSFloat32Array(JSArrayBuffer buffer) {
96 | super(buffer,"Float32Array",Float.class);
97 | }
98 |
99 | /**
100 | * Treats an existing value as a typed array
101 | * @param valueRef the JavaScriptCore value reference
102 | * @param ctx The JSContext of the value
103 | * @since 3.0
104 | */
105 | public JSFloat32Array(long valueRef, JSContext ctx) {
106 | super(valueRef,ctx,Float.class);
107 | }
108 |
109 | /**
110 | * JavaScript: TypedArray.prototype.subarray(), see:
111 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
112 | * @param begin the element to begin at (inclusive)
113 | * @param end the element to end at (exclusive)
114 | * @return the new typed subarray
115 | */
116 | public JSFloat32Array subarray(int begin, int end) {
117 | return (JSFloat32Array)super.subarray(begin,end);
118 | }
119 | /**
120 | * JavaScript: TypedArray.prototype.subarray(), see:
121 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
122 | * @param begin the element to begin at (inclusive)
123 | * @return the new typed subarray
124 | */
125 | public JSFloat32Array subarray(int begin) {
126 | return (JSFloat32Array)super.subarray(begin);
127 | }
128 |
129 | private JSFloat32Array(JSFloat32Array superList, int leftBuffer, int rightBuffer) {
130 | super(superList,leftBuffer,rightBuffer,Float.class);
131 | }
132 | /**
133 | * @see java.util.List#subList(int, int)
134 | * @since 3.0
135 | */
136 | @Override @NonNull
137 | @SuppressWarnings("unchecked")
138 | public JSFloat32Array subList(final int fromIndex, final int toIndex) {
139 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
140 | throw new IndexOutOfBoundsException();
141 | }
142 | return new JSFloat32Array(this,fromIndex,size()-toIndex);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSFloat64Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSFloat64Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Float64Array
39 | * @since 3.0
40 | */
41 | public class JSFloat64Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSFloat64Array(JSContext ctx, int length) {
49 | super(ctx,length,"Float64Array",Double.class);
50 | }
51 | /**
52 | * Creates a new JSFloat64Array from the contents of another typed array
53 | * @param tarr the typed array from which to create the new array
54 | * @since 3.0
55 | */
56 | public JSFloat64Array(JSTypedArray tarr) {
57 | super(tarr,"Float64Array",Double.class);
58 | }
59 |
60 | /**
61 | * Creates new typed array as if by TypedArray.from()
62 | * @param ctx The context in which to create the typed array
63 | * @param object The object to create the array from
64 | * @since 3.0
65 | */
66 | public JSFloat64Array(JSContext ctx, Object object) {
67 | super(ctx,object,"Float64Array",Double.class);
68 | }
69 |
70 | /**
71 | * Creates a typed array from a JSArrayBuffer
72 | * @param buffer The JSArrayBuffer to create the typed array from
73 | * @param byteOffset The byte offset in the ArrayBuffer to start from
74 | * @param length The number of bytes from 'byteOffset' to include in the array
75 | * @since 3.0
76 | */
77 | public JSFloat64Array(JSArrayBuffer buffer, int byteOffset, int length) {
78 | super(buffer,byteOffset,length,"Float64Array",Double.class);
79 | }
80 | /**
81 | * Creates a typed array from a JSArrayBuffer
82 | * @param buffer The JSArrayBuffer to create the typed array from
83 | * @param byteOffset The byte offset in the ArrayBuffer to start from
84 | * @since 3.0
85 | */
86 | public JSFloat64Array(JSArrayBuffer buffer, int byteOffset) {
87 | super(buffer,byteOffset,"Float64Array",Double.class);
88 | }
89 | /**
90 | * Creates a typed array from a JSArrayBuffer
91 | * @param buffer The JSArrayBuffer to create the typed array from
92 | * @since 3.0
93 | */
94 | public JSFloat64Array(JSArrayBuffer buffer) {
95 | super(buffer,"Float64Array",Double.class);
96 | }
97 |
98 | /**
99 | * Treats an existing value as a typed array
100 | * @param valueRef the JavaScriptCore value reference
101 | * @param ctx The JSContext of the value
102 | * @since 3.0
103 | */
104 | public JSFloat64Array(long valueRef, JSContext ctx) {
105 | super(valueRef,ctx,Double.class);
106 | }
107 |
108 | /**
109 | * JavaScript: TypedArray.prototype.subarray(), see:
110 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
111 | * @param begin the element to begin at (inclusive)
112 | * @param end the element to end at (exclusive)
113 | * @return the new typed subarray
114 | */
115 | public JSFloat64Array subarray(int begin, int end) {
116 | return (JSFloat64Array)super.subarray(begin,end);
117 | }
118 | /**
119 | * JavaScript: TypedArray.prototype.subarray(), see:
120 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
121 | * @param begin the element to begin at (inclusive)
122 | * @return the new typed subarray
123 | */
124 | public JSFloat64Array subarray(int begin) {
125 | return (JSFloat64Array)super.subarray(begin);
126 | }
127 |
128 | private JSFloat64Array(JSFloat64Array superList, int leftBuffer, int rightBuffer) {
129 | super(superList,leftBuffer,rightBuffer,Double.class);
130 | }
131 | /**
132 | * @see java.util.List#subList(int, int)
133 | * @since 3.0
134 | */
135 | @Override @NonNull
136 | @SuppressWarnings("unchecked")
137 | public JSFloat64Array subList(final int fromIndex, final int toIndex) {
138 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
139 | throw new IndexOutOfBoundsException();
140 | }
141 | return new JSFloat64Array(this,fromIndex,size()-toIndex);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSInt16Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSInt16Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Int16Array
39 | */
40 | public class JSInt16Array extends JSTypedArray {
41 | /**
42 | * Creates a typed array of length 'length' in JSContext 'context'
43 | * @param ctx the JSContext in which to create the typed array
44 | * @param length the length of the array in elements
45 | */
46 | public JSInt16Array(JSContext ctx, int length) {
47 | super(ctx,length,"Int16Array",Short.class);
48 | }
49 |
50 | /**
51 | * Creates a new JSInt16Array from the contents of another typed array
52 | * @param tarr the typed array from which to create the new array
53 | */
54 | public JSInt16Array(JSTypedArray tarr) {
55 | super(tarr,"Int16Array",Short.class);
56 | }
57 |
58 | /**
59 | * Creates new typed array as if by TypedArray.from()
60 | * @param ctx The context in which to create the typed array
61 | * @param object The object to create the array from
62 | */
63 | public JSInt16Array(JSContext ctx, Object object) {
64 | super(ctx,object,"Int16Array",Short.class);
65 | }
66 |
67 | /**
68 | * Creates a typed array from a JSArrayBuffer
69 | * @param buffer The JSArrayBuffer to create the typed array from
70 | * @param byteOffset The byte offset in the ArrayBuffer to start from
71 | * @param length The number of bytes from 'byteOffset' to include in the array
72 | */
73 | public JSInt16Array(JSArrayBuffer buffer, int byteOffset, int length) {
74 | super(buffer,byteOffset,length,"Int16Array",Short.class);
75 | }
76 | /**
77 | * Creates a typed array from a JSArrayBuffer
78 | * @param buffer The JSArrayBuffer to create the typed array from
79 | * @param byteOffset The byte offset in the ArrayBuffer to start from
80 | */
81 | public JSInt16Array(JSArrayBuffer buffer, int byteOffset) {
82 | super(buffer,byteOffset,"Int16Array",Short.class);
83 | }
84 | /**
85 | * Creates a typed array from a JSArrayBuffer
86 | * @param buffer The JSArrayBuffer to create the typed array from
87 | */
88 | public JSInt16Array(JSArrayBuffer buffer) {
89 | super(buffer,"Int16Array",Short.class);
90 | }
91 |
92 | /**
93 | * Treats an existing value as a typed array
94 | * @param valueRef the JavaScriptCore value reference
95 | * @param ctx The JSContext of the value
96 | */
97 | public JSInt16Array(long valueRef, JSContext ctx) {
98 | super(valueRef,ctx,Short.class);
99 | }
100 |
101 | /**
102 | * JavaScript: TypedArray.prototype.subarray(), see:
103 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
104 | * @param begin the element to begin at (inclusive)
105 | * @param end the element to end at (exclusive)
106 | * @return the new typed subarray
107 | */
108 | public JSInt16Array subarray(int begin, int end) {
109 | return (JSInt16Array)super.subarray(begin,end);
110 | }
111 | /**
112 | * JavaScript: TypedArray.prototype.subarray(), see:
113 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
114 | * @param begin the element to begin at (inclusive)
115 | * @return the new typed subarray
116 | */
117 | public JSInt16Array subarray(int begin) {
118 | return (JSInt16Array)super.subarray(begin);
119 | }
120 |
121 | private JSInt16Array(JSInt16Array superList, int leftBuffer, int rightBuffer) {
122 | super(superList,leftBuffer,rightBuffer,Short.class);
123 | }
124 | /**
125 | * @see java.util.List#subList(int, int)
126 | * @since 3.0
127 | */
128 | @Override @NonNull
129 | @SuppressWarnings("unchecked")
130 | public JSInt16Array subList(final int fromIndex, final int toIndex) {
131 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
132 | throw new IndexOutOfBoundsException();
133 | }
134 | return new JSInt16Array(this,fromIndex,size()-toIndex);
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSInt32Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSInt32Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Int32Array
39 | * @since 3.0
40 | */
41 | public class JSInt32Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSInt32Array(JSContext ctx, int length) {
49 | super(ctx,length,"Int32Array",Integer.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSInt32Array from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSInt32Array(JSTypedArray tarr) {
58 | super(tarr,"Int32Array",Integer.class);
59 | }
60 |
61 | /**
62 | * Creates new typed array as if by TypedArray.from()
63 | * @param ctx The context in which to create the typed array
64 | * @param object The object to create the array from
65 | * @since 3.0
66 | */
67 | public JSInt32Array(JSContext ctx, Object object) {
68 | super(ctx,object,"Int32Array",Integer.class);
69 | }
70 |
71 | /**
72 | * Creates a typed array from a JSArrayBuffer
73 | * @param buffer The JSArrayBuffer to create the typed array from
74 | * @param byteOffset The byte offset in the ArrayBuffer to start from
75 | * @param length The number of bytes from 'byteOffset' to include in the array
76 | * @since 3.0
77 | */
78 | public JSInt32Array(JSArrayBuffer buffer, int byteOffset, int length) {
79 | super(buffer,byteOffset,length,"Int32Array",Integer.class);
80 | }
81 | /**
82 | * Creates a typed array from a JSArrayBuffer
83 | * @param buffer The JSArrayBuffer to create the typed array from
84 | * @param byteOffset The byte offset in the ArrayBuffer to start from
85 | * @since 3.0
86 | */
87 | public JSInt32Array(JSArrayBuffer buffer, int byteOffset) {
88 | super(buffer,byteOffset,"Int32Array",Integer.class);
89 | }
90 | /**
91 | * Creates a typed array from a JSArrayBuffer
92 | * @param buffer The JSArrayBuffer to create the typed array from
93 | * @since 3.0
94 | */
95 | public JSInt32Array(JSArrayBuffer buffer) {
96 | super(buffer,"Int32Array",Integer.class);
97 | }
98 |
99 | /**
100 | * Treats an existing value as a typed array
101 | * @param valueRef the JavaScriptCore value reference
102 | * @param ctx The JSContext of the value
103 | * @since 3.0
104 | */
105 | public JSInt32Array(long valueRef, JSContext ctx) {
106 | super(valueRef,ctx,Integer.class);
107 | }
108 |
109 | /**
110 | * JavaScript: TypedArray.prototype.subarray(), see:
111 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
112 | * @param begin the element to begin at (inclusive)
113 | * @param end the element to end at (exclusive)
114 | * @return the new typed subarray
115 | */
116 | public JSInt32Array subarray(int begin, int end) {
117 | return (JSInt32Array)super.subarray(begin,end);
118 | }
119 | /**
120 | * JavaScript: TypedArray.prototype.subarray(), see:
121 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
122 | * @param begin the element to begin at (inclusive)
123 | * @return the new typed subarray
124 | */
125 | public JSInt32Array subarray(int begin) {
126 | return (JSInt32Array)super.subarray(begin);
127 | }
128 |
129 | private JSInt32Array(JSInt32Array superList, int leftBuffer, int rightBuffer) {
130 | super(superList,leftBuffer,rightBuffer,Integer.class);
131 | }
132 | /**
133 | * @see java.util.List#subList(int, int)
134 | * @since 3.0
135 | */
136 | @Override @NonNull
137 | @SuppressWarnings("unchecked")
138 | public JSInt32Array subList(final int fromIndex, final int toIndex) {
139 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
140 | throw new IndexOutOfBoundsException();
141 | }
142 | return new JSInt32Array(this,fromIndex,size()-toIndex);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSInt8Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSInt8Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Int8Array
39 | * @since 3.0
40 | */
41 | public class JSInt8Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSInt8Array(JSContext ctx, int length) {
49 | super(ctx,length,"Int8Array",Byte.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSInt8Array from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSInt8Array(JSTypedArray tarr) {
58 | super(tarr,"Int8Array",Byte.class);
59 | }
60 |
61 | /**
62 | * Creates new typed array as if by TypedArray.from()
63 | * @param ctx The context in which to create the typed array
64 | * @param object The object to create the array from
65 | * @since 3.0
66 | */
67 | public JSInt8Array(JSContext ctx, Object object) {
68 | super(ctx,object,"Int8Array",Byte.class);
69 | }
70 |
71 | /**
72 | * Creates a typed array from a JSArrayBuffer
73 | * @param buffer The JSArrayBuffer to create the typed array from
74 | * @param byteOffset The byte offset in the ArrayBuffer to start from
75 | * @param length The number of bytes from 'byteOffset' to include in the array
76 | * @since 3.0
77 | */
78 | public JSInt8Array(JSArrayBuffer buffer, int byteOffset, int length) {
79 | super(buffer,byteOffset,length,"Int8Array",Byte.class);
80 | }
81 | /**
82 | * Creates a typed array from a JSArrayBuffer
83 | * @param buffer The JSArrayBuffer to create the typed array from
84 | * @param byteOffset The byte offset in the ArrayBuffer to start from
85 | * @since 3.0
86 | */
87 | public JSInt8Array(JSArrayBuffer buffer, int byteOffset) {
88 | super(buffer,byteOffset,"Int8Array",Byte.class);
89 | }
90 | /**
91 | * Creates a typed array from a JSArrayBuffer
92 | * @param buffer The JSArrayBuffer to create the typed array from
93 | * @since 3.0
94 | */
95 | public JSInt8Array(JSArrayBuffer buffer) {
96 | super(buffer,"Int8Array",Byte.class);
97 | }
98 |
99 | /**
100 | * Treats an existing value as a typed array
101 | * @param valueRef the JavaScriptCore value reference
102 | * @param ctx The JSContext of the value
103 | * @since 3.0
104 | */
105 | public JSInt8Array(long valueRef, JSContext ctx) {
106 | super(valueRef,ctx,Byte.class);
107 | }
108 |
109 | /**
110 | * JavaScript: TypedArray.prototype.subarray(), see:
111 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
112 | * @param begin the element to begin at (inclusive)
113 | * @param end the element to end at (exclusive)
114 | * @return the new typed subarray
115 | */
116 | public JSInt8Array subarray(int begin, int end) {
117 | return (JSInt8Array)super.subarray(begin,end);
118 | }
119 | /**
120 | * JavaScript: TypedArray.prototype.subarray(), see:
121 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
122 | * @param begin the element to begin at (inclusive)
123 | * @return the new typed subarray
124 | */
125 | public JSInt8Array subarray(int begin) {
126 | return (JSInt8Array)super.subarray(begin);
127 | }
128 |
129 | private JSInt8Array(JSInt8Array superList, int leftBuffer, int rightBuffer) {
130 | super(superList,leftBuffer,rightBuffer,Byte.class);
131 | }
132 | /**
133 | * @see java.util.List#subList(int, int)
134 | * @since 3.0
135 | */
136 | @Override @NonNull
137 | @SuppressWarnings("unchecked")
138 | public JSInt8Array subList(final int fromIndex, final int toIndex) {
139 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
140 | throw new IndexOutOfBoundsException();
141 | }
142 | return new JSInt8Array(this,fromIndex,size()-toIndex);
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSIterator.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSIterator.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import java.util.Iterator;
36 |
37 | /**
38 | * A JavaScript iterator interface shadow object
39 | * @since 3.0
40 | * @param Parameterized type of iterator elements
41 | */
42 | public class JSIterator extends JSObjectWrapper implements Iterator {
43 | /**
44 | * Represents the object returned by 'next'
45 | * @since 3.0
46 | */
47 | public class Next extends JSObjectWrapper {
48 | protected Next(JSObject next) {
49 | super(next);
50 | }
51 |
52 | /**
53 | * Tests if there are any more elements in the array
54 | * @return true if more elements to iterate, false otherwise
55 | */
56 | public boolean done() {
57 | return getJSObject().property("done").toBoolean();
58 | }
59 |
60 | /**
61 | * Returns the JSValue of the iterated element
62 | * @return the value returned from next()
63 | */
64 | public JSValue value() {
65 | return getJSObject().property("value");
66 | }
67 | }
68 |
69 | /**
70 | * Wraps a JavaScript iterator in a Java iterator
71 | * @param iterator the JavaScript iterator object. Assumes the object is a properly formed JS
72 | * iterator
73 | */
74 | public JSIterator(JSObject iterator) {
75 | super(iterator);
76 | next = _jsnext();
77 | }
78 | private Next next = null;
79 |
80 | private Next _jsnext() {
81 | return new Next(getJSObject().property("next").toFunction().call(getJSObject()).toObject());
82 | }
83 |
84 | /**
85 | * The 'next' JavaScript iterator object
86 | * @return the next JSObject in the JSIterator
87 | */
88 | public Next jsnext() {
89 | Next ret = next;
90 | next = _jsnext();
91 | return ret;
92 | }
93 |
94 | /**
95 | * @see Iterator#next()
96 | * @return next value in the iterator
97 | */
98 | @Override
99 | @SuppressWarnings("unchecked")
100 | public T next() {
101 | return (T) jsnext().value();
102 | }
103 |
104 | /**
105 | * @see Iterator#hasNext()
106 | * @return true if next() will return a value, false if no values left
107 | */
108 | @Override
109 | public boolean hasNext() {
110 | return !next.done();
111 | }
112 |
113 | /**
114 | * @see Iterator#remove()
115 | * @throws UnsupportedOperationException always
116 | */
117 | @Override
118 | public void remove() {
119 | throw new UnsupportedOperationException();
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSON.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSON.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | /**
36 | * A convenience class for creating JavaScript values from JSON
37 | * @since 3.0
38 | */
39 | public class JSON extends JSValue {
40 | private JSON(JSContext ctx, String str) {
41 | context = ctx;
42 | valueRef = this.makeFromJSONString(context.ctxRef(), new JSString(str).stringRef());
43 | }
44 |
45 | /**
46 | * Gets a JSON string representation of any object
47 | * @param value The JSValue to convert to JSON
48 | * @return a JSON string representing 'object'
49 | * @since 3.0
50 | */
51 | public static String stringify(JSValue value) {
52 | return value.getContext().property("JSON").toObject()
53 | .property("stringify").toFunction().call(null,value)
54 | .toString();
55 | }
56 |
57 | /**
58 | * Gets a JSON string representation of any object
59 | * @param ctx A js context
60 | * @param object The object to convert to JSON
61 | * @return a JSON string representing 'object'
62 | * @since 3.0
63 | */
64 | public static String stringify(JSContext ctx, Object object) {
65 | return ctx.property("JSON").toObject()
66 | .property("stringify").toFunction().call(null,object)
67 | .toString();
68 | }
69 |
70 | /**
71 | * Creates a new JavaScript value from a JSString JSON string
72 | * @param ctx The context in which to create the value
73 | * @param json The string containing the JSON
74 | * @return a JSValue containing the parsed value, or JSValue.isNull() if malformed
75 | * @since 3.0
76 | */
77 | public static JSValue parse(JSContext ctx, String json) {
78 | return new JSON(ctx,json);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSObjectWrapper.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.webkit.javascriptcore;
2 |
3 | //
4 | // JSArrayBuffer.java
5 | // AndroidJSCore project
6 | //
7 | // https://github.com/ericwlange/AndroidJSCore/
8 | //
9 | // Created by Eric Lange
10 | //
11 | /*
12 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
13 |
14 | Redistribution and use in source and binary forms, with or without
15 | modification, are permitted provided that the following conditions are met:
16 |
17 | - Redistributions of source code must retain the above copyright notice, this
18 | list of conditions and the following disclaimer.
19 |
20 | - Redistributions in binary form must reproduce the above copyright notice,
21 | this list of conditions and the following disclaimer in the documentation
22 | and/or other materials provided with the distribution.
23 |
24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 | public abstract class JSObjectWrapper extends JSObject {
36 | protected JSObjectWrapper(JSObject obj) {
37 | mJSObject = obj;
38 | context = obj.getContext();
39 | valueRef = obj.valueRef();
40 | }
41 | private final JSObject mJSObject;
42 |
43 | /**
44 | * Gets underlying JSObject
45 | * @return JSObject representing the wrapped object
46 | * @since 3.0
47 | */
48 | public JSObject getJSObject() {
49 | return mJSObject;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSRegExp.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSRegExp.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | /**
36 | * A convenience class for managing JavaScript regular expressions. See
37 | *
38 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
39 | * for details on JavaScript regexp.
40 | * @since 1.0
41 | */
42 | public class JSRegExp extends JSObject {
43 | /**
44 | * Creates a new JavaScript regular expression
45 | * @param ctx The context in which to create the regular expression
46 | * @param pattern The REGEXP pattern
47 | * @param flags The REGEXP flags
48 | * @since 1.0
49 | */
50 | public JSRegExp(JSContext ctx, String pattern, String flags) {
51 | context = ctx;
52 | long [] args = {
53 | new JSValue(context,pattern).valueRef(),
54 | new JSValue(context,flags).valueRef(),
55 | };
56 | valueRef = makeRegExp(context.ctxRef(), args).reference;
57 | }
58 | /**
59 | * Creates a new JavaScript regular expression
60 | * @param ctx The context in which to create the regular expression
61 | * @param pattern The REGEXP pattern
62 | * @since 1.0
63 | */
64 | public JSRegExp(JSContext ctx, String pattern) {
65 | context = ctx;
66 | long [] args = {
67 | new JSValue(context,pattern).valueRef()
68 | };
69 | JNIReturnObject jni = makeRegExp(context.ctxRef(), args);
70 | valueRef = makeRegExp(context.ctxRef(), args).reference;
71 | }
72 |
73 | /**
74 | * A special JSArray returned by the result of JSRegExp.exec()
75 | * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
76 | * @since 3.0
77 | */
78 | public class ExecResult extends JSArray {
79 | protected ExecResult(JSObject result) {
80 | super(result.valueRef(),result.getContext(),String.class);
81 | }
82 |
83 | /**
84 | * Returns index of match
85 | * @return The 0-based index of the match in the string
86 | * @since 3.0
87 | */
88 | public Integer index() {
89 | return property("index").toNumber().intValue();
90 | }
91 |
92 | /**
93 | * Returns the original string to be matched
94 | * @return The original string
95 | * @since 3.0
96 | */
97 | public String input() {
98 | return property("input").toString();
99 | }
100 | }
101 |
102 | /**
103 | * JavaScript RegExp.prototype.exec(), see:
104 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
105 | * @param str The string to match
106 | * @return an ExecResult JSArray, containing match information
107 | * @since 3.0
108 | */
109 | public ExecResult exec(String str) {
110 | JSValue result = property("exec").toFunction().call(this,str);
111 | return (result.isNull()) ? null : new ExecResult(result.toObject());
112 | }
113 |
114 | /**
115 | * JavaScript RegExp.prototype.lastIndex
116 | * The index at which to start the next match
117 | * @return The index at which to start the next match
118 | * @since 3.0
119 | */
120 | public Integer lastIndex() {
121 | return property("lastIndex").toNumber().intValue();
122 | }
123 |
124 | /**
125 | * Indicates if the "i" flag was used to ignore case
126 | * @return true if "i" flag was used, false otherwise
127 | * @since 3.0
128 | */
129 | public Boolean ignoreCase() {
130 | return property("ignoreCase").toBoolean();
131 | }
132 |
133 | /**
134 | * Indicates if the "g" flag was used for a global match
135 | * @return true if "g" flag was used, false otherwise
136 | * @since 3.0
137 | */
138 | public Boolean global() {
139 | return property("global").toBoolean();
140 | }
141 |
142 | /**
143 | * Indicates if the "m" flag was used to search in strings across multiple lines
144 | * @return true if "m" flag was used, false otherwise
145 | * @since 3.0
146 | */
147 | public Boolean multiline() {
148 | return property("multiline").toBoolean();
149 | }
150 |
151 | /**
152 | * Return the text of the pattern
153 | * @return the text of the pattern
154 | * @since 3.0
155 | */
156 | public String source() {
157 | return property("source").toString();
158 | }
159 |
160 | /**
161 | * JavaScript, RegExp.prototype.test(), see:
162 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
163 | * @param str The string against which to match the regular expression
164 | * @return true if test succeeded, false otherwise
165 | * @since 3.0
166 | */
167 | public Boolean test(String str) {
168 | return property("test").toFunction().call(this,str).toBoolean();
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSUint16Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSUint16Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Uint16Array
39 | * @since 3.0
40 | */
41 | public class JSUint16Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSUint16Array(JSContext ctx, int length) {
49 | super(ctx,length,"Uint16Array",Short.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSUint16Array from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSUint16Array(JSTypedArray tarr) {
58 | super(tarr,"Uint16Array",Short.class);
59 | }
60 | /**
61 | * Creates new typed array as if by TypedArray.from()
62 | * @param ctx The context in which to create the typed array
63 | * @param object The object to create the array from
64 | * @since 3.0
65 | */
66 | public JSUint16Array(JSContext ctx, Object object) {
67 | super(ctx,object,"Uint16Array",Short.class);
68 | }
69 |
70 | /**
71 | * Creates a typed array from a JSArrayBuffer
72 | * @param buffer The JSArrayBuffer to create the typed array from
73 | * @param byteOffset The byte offset in the ArrayBuffer to start from
74 | * @param length The number of bytes from 'byteOffset' to include in the array
75 | * @since 3.0
76 | */
77 | public JSUint16Array(JSArrayBuffer buffer, int byteOffset, int length) {
78 | super(buffer,byteOffset,length,"Uint16Array",Short.class);
79 | }
80 | /**
81 | * Creates a typed array from a JSArrayBuffer
82 | * @param buffer The JSArrayBuffer to create the typed array from
83 | * @param byteOffset The byte offset in the ArrayBuffer to start from
84 | * @since 3.0
85 | */
86 | public JSUint16Array(JSArrayBuffer buffer, int byteOffset) {
87 | super(buffer,byteOffset,"Uint16Array",Short.class);
88 | }
89 | /**
90 | * Creates a typed array from a JSArrayBuffer
91 | * @param buffer The JSArrayBuffer to create the typed array from
92 | * @since 3.0
93 | */
94 | public JSUint16Array(JSArrayBuffer buffer) {
95 | super(buffer,"Uint16Array",Short.class);
96 | }
97 |
98 | /**
99 | * Treats an existing value as a typed array
100 | * @param valueRef the JavaScriptCore value reference
101 | * @param ctx The JSContext of the value
102 | * @since 3.0
103 | */
104 | public JSUint16Array(long valueRef, JSContext ctx) {
105 | super(valueRef,ctx,Short.class);
106 | }
107 |
108 | /**
109 | * JavaScript: TypedArray.prototype.subarray(), see:
110 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
111 | * @param begin the element to begin at (inclusive)
112 | * @param end the element to end at (exclusive)
113 | * @return the new typed subarray
114 | */
115 | public JSUint16Array subarray(int begin, int end) {
116 | return (JSUint16Array)super.subarray(begin,end);
117 | }
118 | /**
119 | * JavaScript: TypedArray.prototype.subarray(), see:
120 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
121 | * @param begin the element to begin at (inclusive)
122 | * @return the new typed subarray
123 | */
124 | public JSUint16Array subarray(int begin) {
125 | return (JSUint16Array)super.subarray(begin);
126 | }
127 |
128 | private JSUint16Array(JSUint16Array superList, int leftBuffer, int rightBuffer) {
129 | super(superList,leftBuffer,rightBuffer,Short.class);
130 | }
131 | /**
132 | * @see java.util.List#subList(int, int)
133 | * @since 3.0
134 | */
135 | @Override @NonNull
136 | @SuppressWarnings("unchecked")
137 | public JSUint16Array subList(final int fromIndex, final int toIndex) {
138 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
139 | throw new IndexOutOfBoundsException();
140 | }
141 | return new JSUint16Array(this,fromIndex,size()-toIndex);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSUint32Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSUint32Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Uint32Array
39 | * @since 3.0
40 | */
41 | public class JSUint32Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSUint32Array(JSContext ctx, int length) {
49 | super(ctx,length,"Uint32Array",Long.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSUint32Array from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSUint32Array(JSTypedArray tarr) {
58 | super(tarr,"Uint32Array",Long.class);
59 | }
60 |
61 | /**
62 | * Creates new typed array as if by TypedArray.from()
63 | * @param ctx The context in which to create the typed array
64 | * @param object The object to create the array from
65 | * @since 3.0
66 | */
67 | public JSUint32Array(JSContext ctx, Object object) {
68 | super(ctx,object,"Uint32Array",Long.class);
69 | }
70 |
71 | /**
72 | * Creates a typed array from a JSArrayBuffer
73 | * @param buffer The JSArrayBuffer to create the typed array from
74 | * @param byteOffset The byte offset in the ArrayBuffer to start from
75 | * @param length The number of bytes from 'byteOffset' to include in the array
76 | * @since 3.0
77 | */
78 | public JSUint32Array(JSArrayBuffer buffer, int byteOffset, int length) {
79 | super(buffer,byteOffset,length,"Uint32Array",Long.class);
80 | }
81 | /**
82 | * Creates a typed array from a JSArrayBuffer
83 | * @param buffer The JSArrayBuffer to create the typed array from
84 | * @param byteOffset The byte offset in the ArrayBuffer to start from
85 | * @since 3.0
86 | */
87 | public JSUint32Array(JSArrayBuffer buffer, int byteOffset) {
88 | super(buffer,byteOffset,"Uint32Array",Long.class);
89 | }
90 | /**
91 | * Creates a typed array from a JSArrayBuffer
92 | * @param buffer The JSArrayBuffer to create the typed array from
93 | * @since 3.0
94 | */
95 | public JSUint32Array(JSArrayBuffer buffer) {
96 | super(buffer,"Uint32Array",Long.class);
97 | }
98 |
99 | /**
100 | * Treats an existing value as a typed array
101 | * @param valueRef the JavaScriptCore value reference
102 | * @param ctx The JSContext of the value
103 | * @since 3.0
104 | */
105 | public JSUint32Array(long valueRef, JSContext ctx) {
106 | super(valueRef,ctx,Long.class);
107 | }
108 |
109 | /**
110 | * JavaScript: TypedArray.prototype.subarray(), see:
111 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
112 | * @param begin the element to begin at (inclusive)
113 | * @param end the element to end at (exclusive)
114 | * @return the new typed subarray
115 | */
116 | public JSUint32Array subarray(int begin, int end) {
117 | return (JSUint32Array)super.subarray(begin,end);
118 | }
119 | /**
120 | * JavaScript: TypedArray.prototype.subarray(), see:
121 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
122 | * @param begin the element to begin at (inclusive)
123 | * @return the new typed subarray
124 | */
125 | public JSUint32Array subarray(int begin) {
126 | return (JSUint32Array)super.subarray(begin);
127 | }
128 |
129 | private JSUint32Array(JSUint32Array superList, int leftBuffer, int rightBuffer) {
130 | super(superList,leftBuffer,rightBuffer,Long.class);
131 | }
132 | /**
133 | * @see java.util.List#subList(int, int)
134 | * @since 3.0
135 | */
136 | @Override @NonNull
137 | @SuppressWarnings("unchecked")
138 | public JSUint32Array subList(final int fromIndex, final int toIndex) {
139 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
140 | throw new IndexOutOfBoundsException();
141 | }
142 | return new JSUint32Array(this,fromIndex,size()-toIndex);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSUint8Array.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSUint8Array.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Uint8Array
39 | * @since 3.0
40 | */
41 | public class JSUint8Array extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSUint8Array(JSContext ctx, int length) {
49 | super(ctx,length,"Uint8Array",Byte.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSUint8Array from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSUint8Array(JSTypedArray tarr) {
58 | super(tarr,"Uint8Array",Byte.class);
59 | }
60 |
61 | /**
62 | * Creates new typed array as if by TypedArray.from()
63 | * @param ctx The context in which to create the typed array
64 | * @param object The object to create the array from
65 | * @since 3.0
66 | */
67 | public JSUint8Array(JSContext ctx, Object object) {
68 | super(ctx,object,"Uint8Array",Byte.class);
69 | }
70 |
71 | /**
72 | * Creates a typed array from a JSArrayBuffer
73 | * @param buffer The JSArrayBuffer to create the typed array from
74 | * @param byteOffset The byte offset in the ArrayBuffer to start from
75 | * @param length The number of bytes from 'byteOffset' to include in the array
76 | * @since 3.0
77 | */
78 | public JSUint8Array(JSArrayBuffer buffer, int byteOffset, int length) {
79 | super(buffer,byteOffset,length,"Uint8Array",Byte.class);
80 | }
81 | /**
82 | * Creates a typed array from a JSArrayBuffer
83 | * @param buffer The JSArrayBuffer to create the typed array from
84 | * @param byteOffset The byte offset in the ArrayBuffer to start from
85 | * @since 3.0
86 | */
87 | public JSUint8Array(JSArrayBuffer buffer, int byteOffset) {
88 | super(buffer,byteOffset,"Uint8Array",Byte.class);
89 | }
90 | /**
91 | * Creates a typed array from a JSArrayBuffer
92 | * @param buffer The JSArrayBuffer to create the typed array from
93 | * @since 3.0
94 | */
95 | public JSUint8Array(JSArrayBuffer buffer) {
96 | super(buffer,"Uint8Array",Byte.class);
97 | }
98 |
99 | /**
100 | * Treats an existing value as a typed array
101 | * @param valueRef the JavaScriptCore value reference
102 | * @param ctx The JSContext of the value
103 | * @since 3.0
104 | */
105 | public JSUint8Array(long valueRef, JSContext ctx) {
106 | super(valueRef,ctx,Byte.class);
107 | }
108 |
109 | /**
110 | * JavaScript: TypedArray.prototype.subarray(), see:
111 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
112 | * @param begin the element to begin at (inclusive)
113 | * @param end the element to end at (exclusive)
114 | * @return the new typed subarray
115 | */
116 | public JSUint8Array subarray(int begin, int end) {
117 | return (JSUint8Array)super.subarray(begin,end);
118 | }
119 | /**
120 | * JavaScript: TypedArray.prototype.subarray(), see:
121 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
122 | * @param begin the element to begin at (inclusive)
123 | * @return the new typed subarray
124 | */
125 | public JSUint8Array subarray(int begin) {
126 | return (JSUint8Array)super.subarray(begin);
127 | }
128 |
129 | private JSUint8Array(JSUint8Array superList, int leftBuffer, int rightBuffer) {
130 | super(superList,leftBuffer,rightBuffer,Byte.class);
131 | }
132 | /**
133 | * @see java.util.List#subList(int, int)
134 | * @since 3.0
135 | */
136 | @Override @NonNull
137 | @SuppressWarnings("unchecked")
138 | public JSUint8Array subList(final int fromIndex, final int toIndex) {
139 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
140 | throw new IndexOutOfBoundsException();
141 | }
142 | return new JSUint8Array(this,fromIndex,size()-toIndex);
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/AndroidJSCore/AndroidJSCore-library/src/main/java/org/liquidplayer/webkit/javascriptcore/JSUint8ClampedArray.java:
--------------------------------------------------------------------------------
1 | //
2 | // JSUint8ClampedArray.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014-2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.webkit.javascriptcore;
34 |
35 | import android.support.annotation.NonNull;
36 |
37 | /**
38 | * A convenience class for handling JavaScript's Uint8ClampedArray
39 | * @since 3.0
40 | */
41 | public class JSUint8ClampedArray extends JSTypedArray {
42 | /**
43 | * Creates a typed array of length 'length' in JSContext 'context'
44 | * @param ctx the JSContext in which to create the typed array
45 | * @param length the length of the array in elements
46 | * @since 3.0
47 | */
48 | public JSUint8ClampedArray(JSContext ctx, int length) {
49 | super(ctx,length,"Uint8ClampedArray",Byte.class);
50 | }
51 |
52 | /**
53 | * Creates a new JSUint8ClampedArray from the contents of another typed array
54 | * @param tarr the typed array from which to create the new array
55 | * @since 3.0
56 | */
57 | public JSUint8ClampedArray(JSTypedArray tarr) {
58 | super(tarr,"Uint8ClampedArray",Byte.class);
59 | }
60 |
61 | /**
62 | * Creates new typed array as if by TypedArray.from()
63 | * @param ctx The context in which to create the typed array
64 | * @param object The object to create the array from
65 | * @since 3.0
66 | */
67 | public JSUint8ClampedArray(JSContext ctx, Object object) {
68 | super(ctx,object,"Uint8ClampedArray",Byte.class);
69 | }
70 |
71 | /**
72 | * Creates a typed array from a JSArrayBuffer
73 | * @param buffer The JSArrayBuffer to create the typed array from
74 | * @param byteOffset The byte offset in the ArrayBuffer to start from
75 | * @param length The number of bytes from 'byteOffset' to include in the array
76 | * @since 3.0
77 | */
78 | public JSUint8ClampedArray(JSArrayBuffer buffer, int byteOffset, int length) {
79 | super(buffer,byteOffset,length,"Uint8ClampedArray",Byte.class);
80 | }
81 | /**
82 | * Creates a typed array from a JSArrayBuffer
83 | * @param buffer The JSArrayBuffer to create the typed array from
84 | * @param byteOffset The byte offset in the ArrayBuffer to start from
85 | * @since 3.0
86 | */
87 | public JSUint8ClampedArray(JSArrayBuffer buffer, int byteOffset) {
88 | super(buffer,byteOffset,"Uint8ClampedArray",Byte.class);
89 | }
90 | /**
91 | * Creates a typed array from a JSArrayBuffer
92 | * @param buffer The JSArrayBuffer to create the typed array from
93 | * @since 3.0
94 | */
95 | public JSUint8ClampedArray(JSArrayBuffer buffer) {
96 | super(buffer,"Uint8ClampedArray",Byte.class);
97 | }
98 |
99 | /**
100 | * Treats an existing value as a typed array
101 | * @param valueRef the JavaScriptCore value reference
102 | * @param ctx The JSContext of the value
103 | * @since 3.0
104 | */
105 | public JSUint8ClampedArray(long valueRef, JSContext ctx) {
106 | super(valueRef,ctx,Byte.class);
107 | }
108 |
109 | /**
110 | * JavaScript: TypedArray.prototype.subarray(), see:
111 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
112 | * @param begin the element to begin at (inclusive)
113 | * @param end the element to end at (exclusive)
114 | * @return the new typed subarray
115 | */
116 | public JSUint8ClampedArray subarray(int begin, int end) {
117 | return (JSUint8ClampedArray)super.subarray(begin,end);
118 | }
119 | /**
120 | * JavaScript: TypedArray.prototype.subarray(), see:
121 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
122 | * @param begin the element to begin at (inclusive)
123 | * @return the new typed subarray
124 | */
125 | public JSUint8ClampedArray subarray(int begin) {
126 | return (JSUint8ClampedArray)super.subarray(begin);
127 | }
128 |
129 | private JSUint8ClampedArray(JSUint8ClampedArray superList, int leftBuffer, int rightBuffer) {
130 | super(superList,leftBuffer,rightBuffer,Byte.class);
131 | }
132 | /**
133 | * @see java.util.List#subList(int, int)
134 | * @since 3.0
135 | */
136 | @Override @NonNull
137 | @SuppressWarnings("unchecked")
138 | public JSUint8ClampedArray subList(final int fromIndex, final int toIndex) {
139 | if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
140 | throw new IndexOutOfBoundsException();
141 | }
142 | return new JSUint8ClampedArray(this,fromIndex,size()-toIndex);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/AndroidJSCore/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/AndroidJSCore/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | org.gradle.jvmargs=-Xmx2048M
--------------------------------------------------------------------------------
/AndroidJSCore/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/AndroidJSCore/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/AndroidJSCore/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jul 25 08:03:17 IST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/AndroidJSCore/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/AndroidJSCore/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/AndroidJSCore/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':AndroidJSCore-library'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AndroidJSCore
2 | =============
3 |
4 | AndroidJSCore allows Android developers to use JavaScript natively in their apps.
5 |
6 | AndroidJSCore is an Android Java JNI wrapper around Webkit's JavaScriptCore C library.
7 | It is inspired by the Objective-C JavaScriptCore Framework included natively in
8 | iOS 7 and above. Being able to natively use JavaScript in an app without requiring the use of
9 | JavaScript injection on a bloated, slow, security-constrained WebView is very useful
10 | for many types of apps, such as games or platforms that support plugins. However,
11 | its use is artificially limited because the framework is only supported on iOS. Most
12 | developers want to use technologies that will scale across both major mobile
13 | operating systems. AndroidJSCore was designed to support that requirement.
14 |
15 | IMPORTANT NOTICE
16 | ------
17 | **AndroidJSCore is DEPRECATED! All of this functionality and more is now maintained at
18 | its permanent home, [LiquidCore](https://github.com/LiquidPlayer/LiquidCore). Please migrate to this
19 | version going forward.**
20 |
21 | Too see how to use LiquidCore as an AndroidJSCore replacement, read [this document](https://github.com/LiquidPlayer/LiquidCore/wiki/LiquidCore-as-a-Native-Javascript-Engine).
22 |
23 | (For the old documentation, see [here](https://github.com/ericwlange/AndroidJSCore/wiki/AndroidJSCore-Deprecated-Documentation), but seriously, it's time to upgrade.)
24 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/.name:
--------------------------------------------------------------------------------
1 | AndroidJSCoreExample
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "23.0.2"
6 | defaultConfig {
7 | applicationId "org.liquidplayer.androidjscoreexample"
8 | minSdkVersion 11
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | productFlavors {
14 | }
15 | }
16 |
17 | repositories {
18 | flatDir {
19 | dirs '../../../AndroidJSCore/AndroidJSCore/build/outputs/aar/', '../../../lib'
20 | }
21 | }
22 |
23 | dependencies {
24 | compile 'com.github.ericwlange:AndroidJSCore:3.0.1'
25 | //compile(name:'AndroidJSCore-3.0.0-release', ext:'aar')
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | testCompile 'junit:junit:4.12'
31 | compile 'com.android.support:appcompat-v7:24.1.1'
32 | compile 'com.android.support:design:24.1.1'
33 | }
34 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Eric/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/androidTest/java/org/liquidplayer/androidjscoreexample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.androidjscoreexample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/java/org/liquidplayer/androidjscoreexample/AsyncExample.java:
--------------------------------------------------------------------------------
1 | //
2 | // AsyncExample.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.androidjscoreexample;
34 |
35 | import org.liquidplayer.webkit.javascriptcore.JSContext;
36 | import org.liquidplayer.webkit.javascriptcore.JSException;
37 | import org.liquidplayer.webkit.javascriptcore.JSFunction;
38 | import org.liquidplayer.webkit.javascriptcore.JSObject;
39 | import org.liquidplayer.webkit.javascriptcore.JSValue;
40 |
41 | import android.os.AsyncTask;
42 | import android.os.Handler;
43 | import android.os.Looper;
44 |
45 | public class AsyncExample implements IExample {
46 | public AsyncExample(ExampleContext ctx) {
47 | context = ctx;
48 | }
49 | private final ExampleContext context;
50 |
51 | // We can also handle asynchronous callbacks to JavaScript. We will define a function
52 | // that waits a specified period of time and then makes a callback with a message
53 | // to be displayed by the JS code.
54 | //
55 | // This is really useful for handling long actions on the Java side. For instance,
56 | // if the script need to make HTTP calls. Since JavaScriptCore is just the isolated
57 | // JavaScript environment, it does not include any DOM or xmlHttp objects you may be
58 | // used to in the browser. To access HTTP, you will need to expose some Java functions
59 | // to handle that for you.
60 | public interface IAsyncObj {
61 | @SuppressWarnings("unused")
62 | void callMeMaybe(Integer ms, JSValue callback) throws JSException;
63 | }
64 | public class AsyncObj extends JSObject implements IAsyncObj {
65 | public AsyncObj(JSContext ctx) throws JSException { super(ctx,IAsyncObj.class); }
66 | @Override
67 | public void callMeMaybe(final Integer ms, final JSValue callback) throws JSException {
68 | Handler handler = new Handler(Looper.getMainLooper());
69 | handler.post(
70 | new Runnable() {
71 | @Override
72 | public void run() {
73 | new CallMeLater(ms).execute(callback.toFunction());
74 | }
75 | }
76 | );
77 | }
78 |
79 | private class CallMeLater extends AsyncTask {
80 | public CallMeLater(Integer ms) {
81 | this.ms = ms;
82 | }
83 | private final Integer ms;
84 | @Override
85 | protected JSFunction doInBackground(JSFunction... params) {
86 | try {
87 | Thread.sleep(ms);
88 | } catch (InterruptedException e) {
89 | Thread.interrupted();
90 | }
91 | return params[0];
92 | }
93 |
94 | @Override
95 | protected void onPostExecute(JSFunction callback) {
96 | try {
97 | callback.call(null, "This is a delayed message from Java!");
98 | } catch (JSException e) {
99 | System.out.println(e.toString());
100 | }
101 | }
102 | }
103 | }
104 |
105 | public void run() throws JSException {
106 | context.clear();
107 | context.log("Asynchrous Callback");
108 | context.log("---------------------");
109 | AsyncObj async = new AsyncObj(context);
110 | context.property("async",async);
111 | context.evaluateScript(
112 | "log('Please call me back in 5 seconds');\n" +
113 | "async.callMeMaybe(5000, function(msg) {\n" +
114 | " alert(msg);\n" +
115 | " log('Whoomp. There it is.');\n" +
116 | "});\n" +
117 | "log('async.callMeMaybe() has returned, but wait for it ...');\n"
118 | );
119 | // For fun, rotate your device 90 degrees back and forth a few times and see what happens
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/java/org/liquidplayer/androidjscoreexample/ExampleContext.java:
--------------------------------------------------------------------------------
1 | //
2 | // ExampleContext.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.androidjscoreexample;
34 |
35 | import org.liquidplayer.webkit.javascriptcore.JSContext;
36 | import org.liquidplayer.webkit.javascriptcore.JSException;
37 |
38 | import android.widget.TextView;
39 | import android.os.Handler;
40 | import android.os.Looper;
41 |
42 | public class ExampleContext extends JSContext implements IExampleContext {
43 |
44 | ExampleContext(TextView tv) throws JSException {
45 | super(IExampleContext.class);
46 | this.tv = tv;
47 | }
48 |
49 | private final TextView tv;
50 | private String log = "";
51 |
52 | public void clear() {
53 | log = "";
54 | tv.setText(log);
55 | }
56 |
57 | @Override
58 | public void log(String msg) {
59 | final String message = msg;
60 | Handler handler = new Handler(Looper.getMainLooper());
61 | handler.post(
62 | new Runnable()
63 | {
64 | @Override
65 | public void run()
66 | {
67 | log = log.concat(message);
68 | log = log.concat("\n");
69 | tv.setText(log);
70 | }
71 | }
72 | );
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/java/org/liquidplayer/androidjscoreexample/ExceptionHandlingExample.java:
--------------------------------------------------------------------------------
1 | //
2 | // ExceptionHandlingExample.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2016 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.androidjscoreexample;
34 |
35 | import org.liquidplayer.webkit.javascriptcore.JSContext;
36 | import org.liquidplayer.webkit.javascriptcore.JSException;
37 | import org.liquidplayer.webkit.javascriptcore.JSValue;
38 |
39 | public class ExceptionHandlingExample implements IExample, JSContext.IJSExceptionHandler {
40 |
41 | public ExceptionHandlingExample(ExampleContext ctx) {
42 | context = ctx;
43 | }
44 | private final ExampleContext context;
45 |
46 | @Override
47 | public void handle(JSException exception) {
48 | context.log("Caught error in context's exception handler");
49 | context.log(exception.toString());
50 | }
51 |
52 | @Override
53 | public void run() throws JSException {
54 | final String naughtyFunctionCode =
55 | "function naughtyFunction() { \n" +
56 | " var access = nothing.prop; \n" +
57 | " return access; \n" +
58 | "} \n";
59 |
60 | context.clear();
61 | context.clearExceptionHandler();
62 |
63 | context.evaluateScript(naughtyFunctionCode, null, "source.js", 1);
64 |
65 | context.log("Handle exception with JavaScript try/catch block");
66 | context.log("------------------------------------------------");
67 | JSValue ret = context.evaluateScript(
68 | "try { naughtyFunction(); } catch(e) { log('Caught error in JS catch block'); log(e); }");
69 | context.log("return value should be undefined: " + ((ret==null)?"NULL":ret.toString()));
70 | context.log("");
71 |
72 | context.log("Handle exception with Java try/catch block");
73 | context.log("------------------------------------------");
74 | ret = null;
75 | try {
76 | ret = context.evaluateScript("naughtyFunction()");
77 | context.log("We really shouldn't get here");
78 | } catch (JSException e) {
79 | context.log("Caught error in Java catch block");
80 | context.log(e.toString());
81 | }
82 | context.log("return value should be unset (NULL): " + ((ret==null)?"NULL":ret.toString()));
83 | context.log("");
84 |
85 | context.log("Handle exception with context.setExceptionHandler()");
86 | context.log("---------------------------------------------------");
87 | context.setExceptionHandler(this);
88 | ret = context.evaluateScript("naughtyFunction()");
89 | context.log("return value should be undefined (not NULL): " + ((ret==null)?"NULL":ret.toString()));
90 | context.log("");
91 |
92 | context.log("Ignore Java try/catch block");
93 | context.log("---------------------------");
94 | ret = null;
95 | try {
96 | ret = context.evaluateScript("naughtyFunction()");
97 | context.log("Now we really SHOULD get here");
98 | } catch (JSException e) {
99 | context.log("And we shouldn't get here");
100 | context.log(e.toString());
101 | }
102 | context.log("return value should be undefined (not NULL): " + ((ret==null)?"NULL":ret.toString()));
103 | context.log("");
104 |
105 | context.clearExceptionHandler();
106 | }
107 | }
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/java/org/liquidplayer/androidjscoreexample/IExample.java:
--------------------------------------------------------------------------------
1 | //
2 | // IExample.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.androidjscoreexample;
34 |
35 | import org.liquidplayer.webkit.javascriptcore.JSException;
36 |
37 | public interface IExample {
38 | void run() throws JSException;
39 | }
40 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/java/org/liquidplayer/androidjscoreexample/IExampleContext.java:
--------------------------------------------------------------------------------
1 | //
2 | // IExampleContext.java
3 | // AndroidJSCore project
4 | //
5 | // https://github.com/ericwlange/AndroidJSCore/
6 | //
7 | // Created by Eric Lange
8 | //
9 | /*
10 | Copyright (c) 2014 Eric Lange. All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | - Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 |
18 | - Redistributions in binary form must reproduce the above copyright notice,
19 | this list of conditions and the following disclaimer in the documentation
20 | and/or other materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 | package org.liquidplayer.androidjscoreexample;
34 |
35 | public interface IExampleContext {
36 | void log(String msg);
37 | }
38 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
27 |
28 |
32 |
33 |
34 |
35 |
40 |
41 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/layout/example_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
36 |
37 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/examples/AndroidJSCoreExample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/examples/AndroidJSCoreExample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/examples/AndroidJSCoreExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/examples/AndroidJSCoreExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/examples/AndroidJSCoreExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 8dp
7 |
8 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidJSCoreExample
3 | Settings
4 | Hello World from section: %1$d
5 |
6 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/app/src/test/java/org/liquidplayer/androidjscoreexample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package org.liquidplayer.androidjscoreexample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 | // NOTE: Do not place your application dependencies here; they belong
10 | // in the individual module build.gradle files
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | maven { url "https://jitpack.io" }
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericwlange/AndroidJSCore/95181d19148b8c5a9dfb0e9fc3958f0731c842e0/examples/AndroidJSCoreExample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat May 14 08:59:48 IST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/examples/AndroidJSCoreExample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------