Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Commit

Permalink
Replaced tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwlange committed Jul 31, 2016
1 parent 6f9c932 commit 56d1b13
Show file tree
Hide file tree
Showing 7 changed files with 435 additions and 435 deletions.
22 changes: 11 additions & 11 deletions AndroidJSCore/AndroidJSCore-library/jni/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@

class Instance {
public:
Instance(JNIEnv *env, jobject thiz, JSContextRef ctx,
JSClassDefinition def = kJSClassDefinitionEmpty, JSStringRef name = NULL);
virtual ~Instance();
virtual long getObjRef() { return (long) objRef; }
Instance(JNIEnv *env, jobject thiz, JSContextRef ctx,
JSClassDefinition def = kJSClassDefinitionEmpty, JSStringRef name = NULL);
virtual ~Instance();
virtual long getObjRef() { return (long) objRef; }
static Instance* getInstance(JSObjectRef objref);

protected:
JavaVM *jvm;
jobject thiz;
JavaVM *jvm;
jobject thiz;

private:
JSObjectRef objRef;
JSClassRef classRef;
JSObjectRef objRef;
JSClassRef classRef;
JSClassDefinition definition;

static std::map<JSObjectRef,Instance *> objMap;
static std::mutex mutex;
static std::map<JSObjectRef,Instance *> objMap;
static std::mutex mutex;

static void StaticFinalizeCallback(JSObjectRef object);
static void StaticFinalizeCallback(JSObjectRef object);
};

#endif //ANDROIDJSCORE_INSTANCE_H
134 changes: 67 additions & 67 deletions AndroidJSCore/AndroidJSCore-library/jni/JSContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,129 +42,129 @@ static pthread_t thr;

static void *thread_func(void*)
{
ssize_t rdsz;
char buf[128];
while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
if(buf[rdsz - 1] == '\n') --rdsz;
buf[rdsz - 1] = 0; /* add null-terminator */
__android_log_write(ANDROID_LOG_DEBUG, "JavaScriptCore", buf);
}
return 0;
ssize_t rdsz;
char buf[128];
while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
if(buf[rdsz - 1] == '\n') --rdsz;
buf[rdsz - 1] = 0; /* add null-terminator */
__android_log_write(ANDROID_LOG_DEBUG, "JavaScriptCore", buf);
}
return 0;
}

NATIVE(JSContext,void,staticInit) (PARAMS) {
/* make stdout line-buffered and stderr unbuffered */
setvbuf(stdout, 0, _IOLBF, 0);
setvbuf(stderr, 0, _IONBF, 0);

/* create the pipe and redirect stdout and stderr */
pipe(pfd);
dup2(pfd[1], 1);
dup2(pfd[1], 2);

/* spawn the logging thread */
if(pthread_create(&thr, 0, thread_func, 0) == -1)
return; // fail silently
pthread_detach(thr);
/* make stdout line-buffered and stderr unbuffered */
setvbuf(stdout, 0, _IOLBF, 0);
setvbuf(stderr, 0, _IONBF, 0);

/* create the pipe and redirect stdout and stderr */
pipe(pfd);
dup2(pfd[1], 1);
dup2(pfd[1], 2);

/* spawn the logging thread */
if(pthread_create(&thr, 0, thread_func, 0) == -1)
return; // fail silently
pthread_detach(thr);
}

NATIVE(JSContextGroup,jlong,create) (PARAMS) {
JSContextGroupRef group = JSContextGroupCreate();
JSContextGroupRetain(group);
return (long)group;
JSContextGroupRef group = JSContextGroupCreate();
JSContextGroupRetain(group);
return (long)group;
}

NATIVE(JSContextGroup,jlong,retain) (PARAMS,jlong group) {
return (long) JSContextGroupRetain((JSContextGroupRef)group);
return (long) JSContextGroupRetain((JSContextGroupRef)group);
}

NATIVE(JSContextGroup,void,release) (PARAMS,jlong group) {
JSContextGroupRelease((JSContextGroupRef) group);
JSContextGroupRelease((JSContextGroupRef) group);
}

NATIVE(JSContext,jlong,create) (PARAMS) {
JSGlobalContextRef ref = JSGlobalContextCreate((JSClassRef) NULL);
//JSGlobalContextRetain(ref);
return (long)ref;
JSGlobalContextRef ref = JSGlobalContextCreate((JSClassRef) NULL);
//JSGlobalContextRetain(ref);
return (long)ref;
}

NATIVE(JSContext,jlong,createInGroup) (PARAMS,jlong group) {
JSGlobalContextRef ref = JSGlobalContextCreateInGroup((JSContextGroupRef)group,
(JSClassRef) NULL);
JSGlobalContextRef ref = JSGlobalContextCreateInGroup((JSContextGroupRef)group,
(JSClassRef) NULL);
//JSGlobalContextRetain(ref);
return (long)ref;
}

NATIVE(JSContext,jlong,retain) (PARAMS,jlong ctx) {
return (jlong) JSGlobalContextRetain((JSGlobalContextRef) ctx);
return (jlong) JSGlobalContextRetain((JSGlobalContextRef) ctx);
}

NATIVE(JSContext,void,release) (PARAMS,jlong ctx) {
JSGlobalContextRelease((JSGlobalContextRef) ctx);
JSGlobalContextRelease((JSGlobalContextRef) ctx);
}

NATIVE(JSContext,jlong,getGlobalObject) (PARAMS, jlong ctx) {
JSObjectRef ref = JSContextGetGlobalObject((JSContextRef) ctx);
JSValueProtect((JSContextRef)ctx,ref);
return (long)ref;
JSObjectRef ref = JSContextGetGlobalObject((JSContextRef) ctx);
JSValueProtect((JSContextRef)ctx,ref);
return (long)ref;
}

NATIVE(JSContext,jlong,getGroup) (PARAMS, jlong ctx) {
JSContextGroupRef group = JSContextGetGroup((JSContextRef) ctx);
JSContextGroupRetain(group);
return (long)group;
JSContextGroupRef group = JSContextGetGroup((JSContextRef) ctx);
JSContextGroupRetain(group);
return (long)group;
}

NATIVE(JSContext,jobject,evaluateScript) (PARAMS, jlong ctx, jlong script,
jlong thisObject, jlong sourceURL, int startingLineNumber) {
jlong thisObject, jlong sourceURL, int startingLineNumber) {

JSValueRef exception = NULL;
JSValueRef exception = NULL;

jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JSValue$JNIReturnObject");
jmethodID cid = env->GetMethodID(ret,"<init>","()V");
jobject out = env->NewObject(ret, cid);
jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JSValue$JNIReturnObject");
jmethodID cid = env->GetMethodID(ret,"<init>","()V");
jobject out = env->NewObject(ret, cid);

jfieldID fid = env->GetFieldID(ret , "reference", "J");
jfieldID fid = env->GetFieldID(ret , "reference", "J");

JSValueRef value = JSEvaluateScript(
(JSContextRef)ctx,
(JSStringRef)script,
JSValueRef value = JSEvaluateScript(
(JSContextRef)ctx,
(JSStringRef)script,
(JSObjectRef)thisObject,
(JSStringRef)sourceURL,
startingLineNumber,
&exception);
JSValueProtect((JSContextRef)ctx, value);

env->SetLongField( out, fid, (long)value);
env->SetLongField( out, fid, (long)value);

fid = env->GetFieldID(ret , "exception", "J");
env->SetLongField( out, fid, (jlong) exception);
fid = env->GetFieldID(ret , "exception", "J");
env->SetLongField( out, fid, (jlong) exception);

return out;
return out;
}

NATIVE(JSContext,jobject,checkScriptSyntax) (PARAMS, jlong ctx, jlong script,
jlong sourceURL, jint startingLineNumber) {
jlong sourceURL, jint startingLineNumber) {

JSValueRef exception = NULL;
JSValueRef exception = NULL;

jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JSValue$JNIReturnObject");
jmethodID cid = env->GetMethodID(ret,"<init>","()V");
jobject out = env->NewObject(ret, cid);
jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JSValue$JNIReturnObject");
jmethodID cid = env->GetMethodID(ret,"<init>","()V");
jobject out = env->NewObject(ret, cid);

jfieldID fid = env->GetFieldID(ret , "reference", "J");
jfieldID fid = env->GetFieldID(ret , "reference", "J");
bool value = JSCheckScriptSyntax(
(JSContextRef)ctx,
(JSStringRef)script,
(JSStringRef)sourceURL,
startingLineNumber,
&exception);
env->SetBooleanField( out, fid, value );
(JSContextRef)ctx,
(JSStringRef)script,
(JSStringRef)sourceURL,
startingLineNumber,
&exception);
env->SetBooleanField( out, fid, value );

fid = env->GetFieldID(ret , "exception", "J");
env->SetLongField( out, fid, (jlong) exception);
fid = env->GetFieldID(ret , "exception", "J");
env->SetLongField( out, fid, (jlong) exception);

return out;
return out;
}

NATIVE(JSContext,void,garbageCollect) (PARAMS, jlong ctx) {
Expand Down
40 changes: 20 additions & 20 deletions AndroidJSCore/AndroidJSCore-library/jni/JSFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@
#include "Instance.h"

class JSFunction : public Instance {
public:
JSFunction(JNIEnv *env, jobject thiz, JSContextRef ctx, JSStringRef name = NULL);
virtual ~JSFunction();
public:
JSFunction(JNIEnv *env, jobject thiz, JSContextRef ctx, JSStringRef name = NULL);
virtual ~JSFunction();

private:
static JSValueRef StaticFunctionCallback(JSContextRef ctx, JSObjectRef function,
JSObjectRef thisObject,size_t argumentCount, const JSValueRef arguments[],
JSValueRef* exception);
static JSObjectRef StaticConstructorCallback(JSContextRef ctx,
JSObjectRef constructor,size_t argumentCount,const JSValueRef arguments[],
JSValueRef* exception);
static bool StaticHasInstanceCallback(JSContextRef ctx, JSObjectRef constructor,
JSValueRef possibleInstance, JSValueRef* exception);
static JSClassDefinition JSFunctionClassDefinition();
private:
static JSValueRef StaticFunctionCallback(JSContextRef ctx, JSObjectRef function,
JSObjectRef thisObject,size_t argumentCount, const JSValueRef arguments[],
JSValueRef* exception);
static JSObjectRef StaticConstructorCallback(JSContextRef ctx,
JSObjectRef constructor,size_t argumentCount,const JSValueRef arguments[],
JSValueRef* exception);
static bool StaticHasInstanceCallback(JSContextRef ctx, JSObjectRef constructor,
JSValueRef possibleInstance, JSValueRef* exception);
static JSClassDefinition JSFunctionClassDefinition();

JSObjectRef ConstructorCallback(JSContextRef ctx, JSObjectRef constructor,
size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef FunctionCallback(JSContextRef ctx, JSObjectRef function,
JSObjectRef thisObject, size_t argumentCount,const JSValueRef arguments[],
JSValueRef* exception);
bool HasInstanceCallback(JSContextRef ctx, JSObjectRef constructor,
JSValueRef possibleInstance, JSValueRef* exception);
JSObjectRef ConstructorCallback(JSContextRef ctx, JSObjectRef constructor,
size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef FunctionCallback(JSContextRef ctx, JSObjectRef function,
JSObjectRef thisObject, size_t argumentCount,const JSValueRef arguments[],
JSValueRef* exception);
bool HasInstanceCallback(JSContextRef ctx, JSObjectRef constructor,
JSValueRef possibleInstance, JSValueRef* exception);
};

#endif //ANDROIDJSCORE_JSFUNCTION_H
2 changes: 1 addition & 1 deletion AndroidJSCore/AndroidJSCore-library/jni/JSJNI.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
#include "JavaScriptCore/JavaScript.h"

#define NATIVE(package,rt,f) extern "C" \
rt Java_org_liquidplayer_webkit_javascriptcore_##package##_##f
rt Java_org_liquidplayer_webkit_javascriptcore_##package##_##f
#define PARAMS __attribute__((unused))JNIEnv* env, __attribute__((unused))jobject thiz

Loading

0 comments on commit 56d1b13

Please sign in to comment.