Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Duktape 2.2.1. #114

Merged
1 commit merged into from Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -2,7 +2,7 @@ ext {
compileSdkVersion = 26
buildToolsVersion = '26.0.2'
buildGradleVersion = '3.0.1'
ndkAbiFilters = ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64']
ndkAbiFilters = ['x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a']
}

allprojects {
Expand Down
6 changes: 3 additions & 3 deletions duktape/build.gradle
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
minSdkVersion 12
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
ndk {
Expand All @@ -15,7 +15,7 @@ android {
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
cFlags '-std=c99', '-fstrict-aliasing', '-DDUK_OPT_HAVE_CUSTOM_H'
cFlags '-std=c99', '-fstrict-aliasing'
cppFlags '-std=c++11', '-fstrict-aliasing', '-fexceptions'
}
}
Expand Down Expand Up @@ -47,7 +47,7 @@ android {
}

dependencies {
implementation 'com.android.support:support-annotations:27.1.0'
implementation 'com.android.support:support-annotations:27.1.1'
}

task sourcesJar(type: Jar) {
Expand Down
11 changes: 6 additions & 5 deletions duktape/src/main/jni/DuktapeContext.cpp
Expand Up @@ -59,7 +59,7 @@ JavaMethod* getJavaMethod(duk_context* ctx) {

duk_int_t eval_string_with_filename(duk_context *ctx, const char *src, const char *fileName) {
duk_push_string(ctx, fileName);
const int numArgs = 2; // source and file name
const int numArgs = 1;
return duk_eval_raw(ctx, src, 0, numArgs | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE |
DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN);
}
Expand All @@ -69,7 +69,7 @@ duk_ret_t javaMethodHandler(duk_context *ctx) {
JavaMethod* method = getJavaMethod(ctx);
return method != nullptr
? method->invoke(ctx, getJNIEnv(ctx), getJavaThis(ctx))
: DUK_RET_INTERNAL_ERROR;
: DUK_RET_ERROR;
}

// Called by Duktape to handle finalization of bound Java objects.
Expand Down Expand Up @@ -97,11 +97,12 @@ duk_ret_t javaObjectFinalizer(duk_context *ctx) {
return 0;
}

void fatalErrorHandler(duk_context* ctx, duk_errcode_t code, const char* msg) {
void fatalErrorHandler(void* udata, const char* msg) {
#ifndef NDEBUG
duk_context* ctx = *reinterpret_cast<duk_context**>(udata);
duk_push_context_dump(ctx);
const char* debugContext = duk_get_string(ctx, -1);
throw std::runtime_error(std::string(msg) + " (" + std::to_string(code) + ") - " + debugContext);
throw std::runtime_error(std::string(msg) + " - " + debugContext);
#else
throw std::runtime_error(msg);
#endif
Expand All @@ -110,7 +111,7 @@ void fatalErrorHandler(duk_context* ctx, duk_errcode_t code, const char* msg) {
} // anonymous namespace

DuktapeContext::DuktapeContext(JavaVM* javaVM)
: m_context(duk_create_heap(nullptr, nullptr, nullptr, nullptr, fatalErrorHandler))
: m_context(duk_create_heap(nullptr, nullptr, nullptr, &m_context, fatalErrorHandler))
, m_objectType(m_javaValues.getObjectType(getEnvFromJavaVM(javaVM))) {
if (!m_context) {
throw std::bad_alloc();
Expand Down