コード例 #1
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
/**
 *
 * performance tips
 * https://www.ibm.com/developerworks/library/j-jni/
 * */
jobject duk_to_java_object(duk_context *ctx, JNIEnv*  env, int i){
	int type = duk_get_type(ctx, i);
	if(type == DUK_TYPE_BOOLEAN){
		jboolean value = duk_to_boolean(ctx, i);
		DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to boolean %d", i, value);
		jmethodID methodID = (*env)->GetMethodID(env, java_boolean_class, "<init>", "(Z)V");
		jobject booleanObject = (*env)->NewObject(env, java_boolean_class, methodID, value);
		return  booleanObject;
	}else if(type == DUK_TYPE_NUMBER){
		jdouble value = duk_to_number(ctx, i);
		jclass doubleClass = (*env)->FindClass(env, "java/lang/Double");
		jmethodID methodID = (*env)->GetMethodID(env, doubleClass, "<init>", "(D)V");
		jobject numberObject = (*env)->NewObject(env, doubleClass, methodID, value);
		(*env)->DeleteLocalRef(env, doubleClass);
		DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to number %f", i, value);
		return numberObject;
	 }else if(type == DUK_TYPE_STRING){
		    const char*  chs = duk_to_string(ctx, i);
		    DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to string %s", i, chs);
		   return (*env)->NewStringUTF(env, chs);
	  }else if(type == DUK_TYPE_OBJECT){
		  if(duk_get_prop_string(ctx, i, JAVA_OBJECT_MARK)){
			    DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to java object", i);
		  		jobject  value = duk_to_pointer(ctx, -1);
		  	    duk_pop(ctx);
		  	    return (*env)->NewLocalRef(env, value);
		  }else{
			  duk_pop(ctx);
			  if(duk_get_prop_string(ctx, i, JS_REF_MARK)){
				  DEBUG_LOG("ScriptEngine","reuse javascript object's JSRef");
				  jweak  weakRef = duk_to_pointer(ctx, -1);
				  jobject jsRefObject = (*env)->NewLocalRef(env, weakRef);
				  duk_pop(ctx);
				  if(jsRefObject != NULL){
					  return jsRefObject;
				  }
			  }else{
				  duk_pop(ctx);
			  }
			  duk_dup(ctx, i);
			  jint ref = duk_js_ref(ctx);
			  if(ref != 0){
				  DEBUG_LOG("ScriptEngine","convert javascript object to JSRef Ref Value %d ", ref);
				  jobject engine = get_engine_from_context(ctx);
				  DEBUG_LOG("ScriptEngine","convert javascript object to JSRef Ref Value");
				  jobject jsRefObject = (*env)->NewObject(env, js_ref_class, js_ref_new_method, engine, ref);
				  jweak jsWeakRef = (*env)->NewWeakGlobalRef(env, jsRefObject);
				  duk_dup(ctx, i);
				  duk_push_pointer(ctx, jsWeakRef);
				  duk_put_prop_string(ctx, -2, JS_REF_MARK);
				  duk_pop(ctx);
				  DEBUG_LOG("ScriptEngine","convert javascript object to JSRef Ref Value Success");
				  return jsRefObject;
			  }
			  return NULL;
		  }
	  }
	  DEBUG_LOG("ScriptEngine","invoke_java_method call, unhandled type convert %d args to null %s", i, duk_to_string(ctx, i));
	  return NULL;
}
コード例 #2
0
ファイル: styleContext.cpp プロジェクト: xvilan/tangram-es
duk_ret_t StyleContext::jsPropertyGetter(duk_context *_ctx) {

    // Storing state for a Duktape/C function:
    // http://duktape.org/guide.html#programming.9
    duk_push_current_function(_ctx);
    duk_get_prop_string(_ctx, -1, ATTR_ID);
    auto* attr = static_cast<const Accessor*> (duk_to_pointer(_ctx, -1));

    if (!attr || !attr->ctx || !attr->ctx->m_feature) {
        logMsg("Error: no context set %p %p\n",
               attr,
               attr ? attr->ctx : nullptr);

        duk_pop(_ctx);
        return 0;
    }

    auto it = attr->ctx->m_feature->props.get(attr->key);

    if (it.is<std::string>()) {
        duk_push_string(_ctx, it.get<std::string>().c_str());
    } else if (it.is<float>()) {
        duk_push_number(_ctx, it.get<float>());
    } else {
        duk_push_undefined(_ctx);
    }

    return 1;
}
コード例 #3
0
// Implements Proxy handler.get(target_object, key)
duk_ret_t StyleContext::jsGetProperty(duk_context *_ctx) {

    // Get the StyleContext instance from JS Feature object (first parameter).
    duk_get_prop_string(_ctx, 0, INSTANCE_ID);
    auto* attr = static_cast<const StyleContext*> (duk_to_pointer(_ctx, -1));
    if (!attr || !attr->m_feature) {
        LOGE("Error: no context set %p %p",  attr, attr ? attr->m_feature : nullptr);
        duk_pop(_ctx);
        return 0;
    }

    // Get the property name (second parameter)
    const char* key = duk_require_string(_ctx, 1);

    auto it = attr->m_feature->props.get(key);
    if (it.is<std::string>()) {
        duk_push_string(_ctx, it.get<std::string>().c_str());
    } else if (it.is<double>()) {
        duk_push_number(_ctx, it.get<double>());
    } else {
        duk_push_undefined(_ctx);
    }

    return 1;
}
コード例 #4
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
JNIEXPORT void JNICALL Java_com_furture_react_DuktapeEngine_nativeDestory
  (JNIEnv * env, jobject thisObject, jlong ptr){
	duk_context *ctx  = convert_to_context(ptr);
	if(ctx){
        jobject enginePtr  = get_engine_from_context(ctx);
        int length = duk_js_ref_size(ctx);
		for(int i=1; i <= length; i++){
			duk_push_js_ref(ctx, i);
			if(duk_is_object(ctx, -1)){
				if(duk_get_prop_string(ctx, -1, JS_REF_MARK)){
					  jweak  weakRef = duk_to_pointer(ctx, -1);
					  if(weakRef != NULL){
					      (*env)->DeleteWeakGlobalRef(env, weakRef);
					  }
					  DEBUG_LOG("ScriptEngine", "Free jweak Ref onJSRef %d", i);
			     }
				 duk_pop(ctx);
			}
			duk_pop(ctx);
		}
		duk_destroy_heap(ctx);
		if(enginePtr != NULL){
		    (*env)->DeleteGlobalRef(env, enginePtr);
		}
	}
}
コード例 #5
0
ファイル: duk_bi_pointer.c プロジェクト: BpLife/duktape
int duk_bi_pointer_constructor(duk_context *ctx) {
	/* FIXME: this behavior is quite useless now; it would be nice to be able
	 * to create pointer values from e.g. numbers or strings.  Numbers are
	 * problematic on 64-bit platforms though.  Hex encoded strings?
	 */
	if (duk_get_top(ctx) == 0) {
		duk_push_pointer(ctx, NULL);
	} else {
		duk_to_pointer(ctx, 0);
	}
	DUK_ASSERT(duk_is_pointer(ctx, 0));
	duk_set_top(ctx, 1);

	if (duk_is_constructor_call(ctx)) {
		duk_push_object_helper(ctx,
		                       DUK_HOBJECT_FLAG_EXTENSIBLE |
		                       DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER),
		                       DUK_BIDX_POINTER_PROTOTYPE);

		/* Pointer object internal value is immutable */
		duk_dup(ctx, 0);
		duk_def_prop_stridx(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
	}
	/* Note: unbalanced stack on purpose */

	return 1;
}
コード例 #6
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
static int java_object_to_string(duk_context *ctx) {
	int n = duk_get_top(ctx);
	DEBUG_LOG("ScriptEngine",  "java_object_to_string enter %d", n);
	duk_push_this(ctx);
	if(duk_get_prop_string(ctx, -1, JAVA_OBJECT_MARK)){
		DEBUG_LOG("ScriptEngine",  "java_object_to_string enter java object ");
		jobject  ref = duk_to_pointer(ctx, -1);
		if(ref == NULL){
			 duk_push_null(ctx);
			 return 1;
		}
		JNIEnv*  env =  get_java_jni_env();
		DEBUG_LOG("ScriptEngine",  "java_object_to_string enter java end");
		jclass   refClass = (*env)->GetObjectClass(env, ref);
		jmethodID method = (*env)->GetMethodID(env, refClass, "toString", "()Ljava/lang/String;");
		jstring  value =  (*env)->CallObjectMethod(env, ref, method);
		jboolean iscopy = JNI_FALSE;
		const char* src =  ((*env)->GetStringUTFChars(env, value, &iscopy));
		DEBUG_LOG("ScriptEngine",  "java_object_to_string src %s", src );
        duk_push_string(ctx, src);
        (*env)->ReleaseStringUTFChars(env, value, src);
		(*env)->DeleteLocalRef(env, value);
		(*env)->DeleteLocalRef(env, refClass);
		DEBUG_LOG("ScriptEngine",  "java_object_to_string success");
		return 1;
	}else{
		DEBUG_LOG("ScriptEngine",  "java_object_to_string error");
	}
	return 0;
}
コード例 #7
0
ファイル: test-to-pointer.c プロジェクト: fatcerberus/duktape
static duk_ret_t test_2(duk_context *ctx, void *udata) {
	(void) udata;

	duk_set_top(ctx, 0);
	duk_to_pointer(ctx, 3);
	printf("index 3 OK\n");
	return 0;
}
コード例 #8
0
ファイル: engine.cpp プロジェクト: Censacrof/aseprite
void* Context::requireObject(index_t i, const char* className)
{
    duk_get_prop_string(m_handle, i, kPtrId);
    void* result = (void*)duk_to_pointer(m_handle, -1);
    // TODO check pointer type
    duk_pop(m_handle);
    return result;
}
コード例 #9
0
ファイル: engine.cpp プロジェクト: Doraenmon/aseprite
void* Context::getThis()
{
  duk_push_this(m_handle);
  duk_get_prop_string(m_handle, -1, "\xFF" "\xFF" "ptr");
  void* result = (void*)duk_to_pointer(m_handle, -1);
  duk_pop(m_handle);
  return result;
}
コード例 #10
0
ファイル: test-to-pointer.c プロジェクト: fatcerberus/duktape
static duk_ret_t test_3(duk_context *ctx, void *udata) {
	(void) udata;

	duk_set_top(ctx, 0);
	duk_to_pointer(ctx, DUK_INVALID_INDEX);
	printf("index DUK_INVALID_INDEX OK\n");
	return 0;
}
コード例 #11
0
ファイル: engine.cpp プロジェクト: Censacrof/aseprite
void* Context::getThis()
{
    duk_push_this(m_handle);
    duk_get_prop_string(m_handle, -1, kPtrId);
    void* result = (void*)duk_to_pointer(m_handle, -1);
    duk_pop_2(m_handle);
    return result;
}
コード例 #12
0
const char* GetValueObjectType(duk_context* ctx, duk_idx_t stackIndex)
{
    duk_get_prop_string(ctx, stackIndex, "\xff""type");
    const char* objTypeName = nullptr;
    if (duk_is_pointer(ctx, -1))
        objTypeName = (const char*)duk_to_pointer(ctx, -1);
    duk_pop(ctx);
    return objTypeName;
}
コード例 #13
0
ファイル: myPlugin.c プロジェクト: FreshXOpenSource/wallyd
duk_ret_t js_myPlugin_info(duk_context *ctx)
{
   duk_push_this(ctx);  /* -> stack: [ this ] */
   duk_get_prop_string(ctx, 0, "\xff""\xff""data");
   myPluginStructure *mps = duk_to_pointer(ctx, -1);
   duk_pop(ctx);
   duk_push_sprintf(ctx, "{ name : %s }",mps->name);
   return 1;
}
コード例 #14
0
ファイル: gpio.c プロジェクト: FreshXOpenSource/wallyd
duk_ret_t js_gpio_toString(duk_context *ctx)
{
   duk_push_this(ctx);  /* -> stack: [ this ] */
   duk_get_prop_string(ctx, 0, "\xff""\xff""data");
   myGPIO *mps = duk_to_pointer(ctx, -1);
   duk_pop(ctx);
   duk_push_sprintf(ctx, "%s",mps->name);
   return 1;
}
コード例 #15
0
ファイル: jsapi.c プロジェクト: rdrpenguin04/TIC-80
static tic_machine* getDukMachine(duk_context* duk)
{
	duk_push_global_stash(duk);
	duk_get_prop_string(duk, -1, TicMachine);
	tic_machine* machine = duk_to_pointer(duk, -1);
	duk_pop_2(duk);

	return machine;
}
コード例 #16
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
jobject get_engine_from_context(duk_context *ctx){
	    duk_push_global_object(ctx);
		if(duk_get_prop_string(ctx, -1, JAVA_ENGINE_MARK)){
			jobject  engine =  duk_to_pointer(ctx, -1);
		    duk_pop_2(ctx);
		    return engine;
		}
		duk_pop_2(ctx);
		return NULL;
}
コード例 #17
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
JNIEXPORT void JNICALL Java_com_furture_react_DuktapeEngine_nativeFinalizeJSRef
  (JNIEnv *env, jobject thisObject, jlong ptr, jint ref){
	 duk_context *ctx  = convert_to_context(ptr);
	 duk_push_js_ref(ctx, ref);
	 if(duk_get_prop_string(ctx, -1, JS_REF_MARK)){
	     jweak  weakRef = duk_to_pointer(ctx, -1);
	     (*env)->DeleteWeakGlobalRef(env, weakRef);
	 }
	 duk_pop_2(ctx);
	 duk_js_unref(ctx, ref);
}
コード例 #18
0
WeakPtr<Object>* GetWeakPtr(duk_context* ctx, duk_idx_t stackIndex)
{
    if (!duk_is_object(ctx, stackIndex))
        return nullptr;

    WeakPtr<Object>* ptr = nullptr;
    duk_get_prop_string(ctx, stackIndex, "\xff""weak");
    if (duk_is_pointer(ctx, -1))
        ptr = static_cast<WeakPtr<Object>*>(duk_to_pointer(ctx, -1));
    duk_pop(ctx);

    return ptr;
}
コード例 #19
0
// Implements Proxy handler.has(target_object, key)
duk_ret_t StyleContext::jsHasProperty(duk_context *_ctx) {

    duk_get_prop_string(_ctx, 0, INSTANCE_ID);
    auto* attr = static_cast<const StyleContext*> (duk_to_pointer(_ctx, -1));
    if (!attr || !attr->m_feature) {
        LOGE("Error: no context set %p %p", attr, attr ? attr->m_feature : nullptr);
        duk_pop(_ctx);
        return 0;
    }

    const char* key = duk_require_string(_ctx, 1);
    duk_push_boolean(_ctx, attr->m_feature->props.contains(key));

    return 1;
}
コード例 #20
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
static int java_object_finalizer(duk_context *ctx) {
	int n = duk_get_top(ctx);
	DEBUG_LOG("ScriptEngine",  "java_object_finalizer enter %d", n);
	if(duk_get_prop_string(ctx, -1, JAVA_OBJECT_MARK)){
		jobject  ref = duk_to_pointer(ctx, -1);
		if(ref != NULL){
			DEBUG_LOG("ScriptEngine",  "java_object_finalizer find free new_java_object");
			JNIEnv *env = get_java_jni_env();
			(*env)->DeleteGlobalRef(env, ref);
		}
	}else{
		DEBUG_LOG("ScriptEngine",  "java_object_finalizer error, none find free new_java_object");
	}
	return 0;
}
コード例 #21
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
int invoke_java_method_call(duk_context *ctx) {
    int num = duk_get_top(ctx);
	const char * method = duk_to_string(ctx, 0);
	DEBUG_LOG("ScriptEngine","invoke_java_method call, method name %s  args num %d",  method, (num - 1));
	duk_push_this(ctx);
	if(duk_get_prop_string(ctx, -1, JAVA_OBJECT_MARK)){
		jobject  ref = duk_to_pointer(ctx, -1);
		JNIEnv*  env =  get_java_jni_env();
		DEBUG_LOG("ScriptEngine","invoke_java_method call, method  new String  %s", method);
		jstring methodName = (*env)->NewStringUTF(env, method);
	    jobjectArray args = duk_to_java_object_array(ctx, 1, num-1, env);
	    DEBUG_LOG("ScriptEngine","invoke_java_method call, with args %p   %p", java_api_class,  java_function_method);
		jobject value =  (*env)->CallStaticObjectMethod(env, java_api_class, java_function_method, ref, methodName, args);
		jthrowable exp = ( *env)->ExceptionOccurred(env);
        if(exp != NULL){
        	      ( *env)->ExceptionClear(env);
        	      jstring exceptionMessage = (*env)->CallStaticObjectMethod(env, java_api_class, java_exception_get_stack_trace_method, exp);
              jboolean isCopy = JNI_FALSE;
        	      const char* cstrMessage = (*env)->GetStringUTFChars(env, exceptionMessage, &isCopy);
        	      duk_push_error_object(ctx, DUK_ERR_EVAL_ERROR, "invoke java method  %s exception \n %s",  method, cstrMessage);
        	      (*env)->ReleaseStringUTFChars(env, exceptionMessage, cstrMessage);
        	      ( *env)->DeleteLocalRef(env , exceptionMessage);
        	      (*env)->DeleteLocalRef(env, args);
        	      (*env)->DeleteLocalRef(env, methodName);
        	      duk_throw(ctx);
        	      return 0;
        }
		duk_push_java_object(ctx, env, value);
	    (*env)->DeleteLocalRef(env, value);
	    (*env)->DeleteLocalRef(env, args);
	    (*env)->DeleteLocalRef(env, methodName);
	    DEBUG_LOG("ScriptEngine","invoke_java_method call with args success ");
		return 1;
	}else{
		duk_pop(ctx);
		duk_insert(ctx, 0);
		DEBUG_LOG("ScriptEngine","invoke_script_prop call, with args  num %d ", duk_get_top(ctx));
		if(duk_pcall_prop(ctx, 0, num - 1) != DUK_EXEC_SUCCESS){
			LOGE("ScriptEngine","ScriptEngine call %s method %s error %s", duk_to_string(ctx, 0), method, duk_js_error_to_string(ctx, -1));
			duk_pop(ctx);
			duk_push_null(ctx);
		}
		DEBUG_LOG("ScriptEngine","invoke_script_prop call, duk_get_prop_string with args  num %d ", duk_get_top(ctx));
		return 1;
	}
}
コード例 #22
0
ファイル: test-to-pointer.c プロジェクト: fatcerberus/duktape
static duk_ret_t test_1(duk_context *ctx, void *udata) {
	duk_idx_t i, n;

	(void) udata;

	duk_set_top(ctx, 0);
	duk_push_undefined(ctx);
	duk_push_null(ctx);
	duk_push_true(ctx);
	duk_push_false(ctx);
	duk_push_int(ctx, 0);
	duk_push_int(ctx, 1);
	duk_push_nan(ctx);
	duk_push_number(ctx, INFINITY);
	duk_push_string(ctx, "");
	duk_push_string(ctx, "foo");
	duk_push_object(ctx);
	duk_push_thread(ctx);
	duk_push_fixed_buffer(ctx, 0);
	duk_push_fixed_buffer(ctx, 1024);
	duk_push_dynamic_buffer(ctx, 0);
	duk_push_dynamic_buffer(ctx, 1024);
	duk_push_pointer(ctx, (void *) NULL);
	duk_push_pointer(ctx, (void *) 0xdeadbeefUL);

	n = duk_get_top(ctx);
	printf("top: %ld\n", (long) n);
	for (i = 0; i < n; i++) {
		void *ptr;
		duk_int_t t1, t2;

		t1 = duk_get_type(ctx, i);
		ptr = duk_to_pointer(ctx, i);
		t2 = duk_get_type(ctx, i);

		printf("index %ld, ptr-is-NULL: %d, type: %ld -> %ld\n",
		       (long) i, (ptr == NULL ? 1 : 0), (long) t1, (long) t2);
		if (t1 == DUK_TYPE_POINTER) {
			/* check that pointer is retained as is (can safely print) */
			printf("pointer: %p\n", ptr);
		}
	}

	return 0;
}
コード例 #23
0
ファイル: myPlugin.c プロジェクト: FreshXOpenSource/wallyd
// the destructor
duk_ret_t js_myPlugin_dtor(duk_context *ctx)
{
    // The object to delete is passed as first argument instead
    duk_get_prop_string(ctx, 0, "\xff""\xff""deleted");

    bool deleted = duk_to_boolean(ctx, -1);
    duk_pop(ctx);

    // Get the pointer and free it
    if (!deleted) {
        duk_get_prop_string(ctx, 0, "\xff""\xff""data");
        void *freePtr = duk_to_pointer(ctx, -1);
        free(freePtr);
        duk_pop(ctx);

        // Mark as deleted
        duk_push_boolean(ctx, true);
        duk_put_prop_string(ctx, 0, "\xff""\xff""deleted");
    }
    return 0;
}
コード例 #24
0
ファイル: DuktapeEngine.c プロジェクト: ewrfedf/DuktapeJava
static duk_ret_t duk_java_property_set(duk_context *ctx) {
	 const char* key  = duk_to_string(ctx, 0);
	 DEBUG_LOG("ScriptEngine", "duk_java_property_set  key %s ", key);
	 duk_push_this(ctx);
     if(duk_get_prop_string(ctx, -1, JAVA_OBJECT_MARK)){
			jobject  ref = duk_to_pointer(ctx, -1);
			JNIEnv*  env =  get_java_jni_env();
			jstring fieldName = (*env)->NewStringUTF(env, key);
			jobject  fieldValue = duk_to_java_object(ctx, env, 1);
			DEBUG_LOG("ScriptEngine", "duk_java_property_set  call staticVoidMethod %s ", key);
			(*env)->CallStaticVoidMethod(env, java_api_class, java_field_set_method, ref, fieldName, fieldValue);
			DEBUG_LOG("ScriptEngine", "duk_java_property_set  call staticVoidMethod Success");
			jthrowable exp = ( *env)->ExceptionOccurred(env);
			if(exp != NULL){
					  (*env)->ExceptionClear(env);
					  jstring exceptionMessage = (*env)->CallStaticObjectMethod(env, java_api_class, java_exception_get_stack_trace_method, exp);
				      jboolean isCopy = JNI_FALSE;
					  const char* cstrMessage = (*env)->GetStringUTFChars(env, exceptionMessage, &isCopy);
					  duk_push_error_object(ctx, DUK_ERR_EVAL_ERROR, "get java property %s error \n %s",  key, cstrMessage);
					  (*env)->ReleaseStringUTFChars(env, exceptionMessage, cstrMessage);
					  ( *env)->DeleteLocalRef(env , exceptionMessage);
					  (*env)->DeleteLocalRef(env, fieldValue);
					  (*env)->DeleteLocalRef(env, fieldName);
					  duk_throw(ctx);
					  return 0;
			 }
			(*env)->DeleteLocalRef(env, fieldValue);
			(*env)->DeleteLocalRef(env, fieldName);
			return 0;
	 }else{
		  DEBUG_LOG("ScriptEngine", "duk_java_property_set  key %d ", duk_get_top(ctx));
		  duk_pop(ctx);
		  DEBUG_LOG("ScriptEngine", "duk_java_property_set  key %d ", duk_get_top(ctx));
		  duk_replace(ctx, 0);
		  DEBUG_LOG("ScriptEngine", "duk_java_property_set  key %d ", duk_get_top(ctx));
	      duk_put_prop_string(ctx, 0, key);
	      DEBUG_LOG("ScriptEngine", "duk_java_property_set  key %d ", duk_get_top(ctx));
		  return 0;
	 }
}
コード例 #25
0
static duk_ret_t test_func(duk_context *ctx, void *udata) {
	(void) udata;

	if (ctx) {
		printf("dummy - return here\n"); fflush(stdout);
		return 0;
	}

	/* Up-to-date for Duktape 1.3.0, alphabetical order:
	 * $ cd website/api; ls *.yaml
	 */

	(void) duk_alloc_raw(ctx, 0);
	(void) duk_alloc(ctx, 0);
	(void) duk_base64_decode(ctx, 0);
	(void) duk_base64_encode(ctx, 0);
	(void) duk_buffer_to_string(ctx, 0);
	(void) duk_call_method(ctx, 0);
	(void) duk_call_prop(ctx, 0, 0);
	(void) duk_call(ctx, 0);
	(void) duk_char_code_at(ctx, 0, 0);
	(void) duk_check_stack_top(ctx, 0);
	(void) duk_check_stack(ctx, 0);
	(void) duk_check_type_mask(ctx, 0, 0);
	(void) duk_check_type(ctx, 0, 0);
	(void) duk_compact(ctx, 0);
	(void) duk_compile_lstring_filename(ctx, 0, "dummy", 0);
	(void) duk_compile_lstring(ctx, 0, "dummy", 0);
	(void) duk_compile_string_filename(ctx, 0, "dummy");
	(void) duk_compile_string(ctx, 0, "dummy");
	(void) duk_compile(ctx, 0);
	(void) duk_concat(ctx, 0);
	(void) duk_config_buffer(ctx, 0, NULL, 0);
	(void) duk_copy(ctx, 0, 0);
	(void) duk_create_heap_default();
	(void) duk_create_heap(NULL, NULL, NULL, NULL, NULL);
	(void) duk_debugger_attach(ctx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	(void) duk_debugger_cooperate(ctx);
	(void) duk_debugger_detach(ctx);
	(void) duk_debugger_notify(ctx, 0);
	(void) duk_debugger_pause(ctx);
	(void) duk_decode_string(ctx, 0, NULL, NULL);
	(void) duk_def_prop(ctx, 0, 0);
	(void) duk_del_prop_index(ctx, 0, 0);
	(void) duk_del_prop_string(ctx, 0, "dummy");
	(void) duk_del_prop(ctx, 0);
	(void) duk_destroy_heap(ctx);
	(void) duk_dump_function(ctx);
	(void) duk_dup_top(ctx);
	(void) duk_dup(ctx, 0);
	(void) duk_enum(ctx, 0, 0);
	(void) duk_equals(ctx, 0, 0);
	duk_error_va(ctx, 0, NULL, NULL);
	duk_error(ctx, 0, "dummy");  /* (void) cast won't work without variadic macros */
	(void) duk_eval_lstring_noresult(ctx, "dummy", 0);
	(void) duk_eval_lstring(ctx, "dummy", 0);
	(void) duk_eval_noresult(ctx);
	(void) duk_eval_string_noresult(ctx, "dummy");
	(void) duk_eval_string(ctx, "dummy");
	(void) duk_eval(ctx);
	(void) duk_fatal(ctx, "dummy");
	(void) duk_free_raw(ctx, NULL);
	(void) duk_free(ctx, NULL);
	(void) duk_gc(ctx, 0);
	(void) duk_get_boolean(ctx, 0);
	(void) duk_get_buffer_data(ctx, 0, NULL);
	(void) duk_get_buffer(ctx, 0, NULL);
	(void) duk_get_c_function(ctx, 0);
	(void) duk_get_context(ctx, 0);
	(void) duk_get_current_magic(ctx);
	(void) duk_get_error_code(ctx, 0);
	(void) duk_get_finalizer(ctx, 0);
	(void) duk_get_global_string(ctx, 0);
	(void) duk_get_heapptr(ctx, 0);
	(void) duk_get_int(ctx, 0);
	(void) duk_get_length(ctx, 0);
	(void) duk_get_lstring(ctx, 0, NULL);
	(void) duk_get_magic(ctx, 0);
	(void) duk_get_memory_functions(ctx, NULL);
	(void) duk_get_number(ctx, 0);
	(void) duk_get_pointer(ctx, 0);
	(void) duk_get_prop_index(ctx, 0, 0);
	(void) duk_get_prop_string(ctx, 0, "dummy");
	(void) duk_get_prop(ctx, 0);
	(void) duk_get_prototype(ctx, 0);
	(void) duk_get_string(ctx, 0);
	(void) duk_get_top_index(ctx);
	(void) duk_get_top(ctx);
	(void) duk_get_type_mask(ctx, 0);
	(void) duk_get_type(ctx, 0);
	(void) duk_get_uint(ctx, 0);
	(void) duk_has_prop_index(ctx, 0, 0);
	(void) duk_has_prop_string(ctx, 0, "dummy");
	(void) duk_has_prop(ctx, 0);
	(void) duk_hex_decode(ctx, 0);
	(void) duk_hex_encode(ctx, 0);
	(void) duk_insert(ctx, 0);
	(void) duk_instanceof(ctx, 0, 0);
	(void) duk_is_array(ctx, 0);
	(void) duk_is_boolean(ctx, 0);
	(void) duk_is_bound_function(ctx, 0);
	(void) duk_is_buffer(ctx, 0);
	(void) duk_is_callable(ctx, 0);
	(void) duk_is_c_function(ctx, 0);
	(void) duk_is_constructor_call(ctx);
	(void) duk_is_dynamic_buffer(ctx, 0);
	(void) duk_is_ecmascript_function(ctx, 0);
	(void) duk_is_error(ctx, 0);
	(void) duk_is_eval_error(ctx, 0);
	(void) duk_is_fixed_buffer(ctx, 0);
	(void) duk_is_function(ctx, 0);
	(void) duk_is_lightfunc(ctx, 0);
	(void) duk_is_nan(ctx, 0);
	(void) duk_is_null_or_undefined(ctx, 0);
	(void) duk_is_null(ctx, 0);
	(void) duk_is_number(ctx, 0);
	(void) duk_is_object_coercible(ctx, 0);
	(void) duk_is_object(ctx, 0);
	(void) duk_is_pointer(ctx, 0);
	(void) duk_is_primitive(ctx, 0);
	(void) duk_is_range_error(ctx, 0);
	(void) duk_is_reference_error(ctx, 0);
	(void) duk_is_strict_call(ctx);
	(void) duk_is_string(ctx, 0);
	(void) duk_is_syntax_error(ctx, 0);
	(void) duk_is_thread(ctx, 0);
	(void) duk_is_type_error(ctx, 0);
	(void) duk_is_undefined(ctx, 0);
	(void) duk_is_uri_error(ctx, 0);
	(void) duk_is_valid_index(ctx, 0);
	(void) duk_join(ctx, 0);
	(void) duk_json_decode(ctx, 0);
	(void) duk_json_encode(ctx, 0);
	(void) duk_load_function(ctx);
	(void) duk_map_string(ctx, 0, NULL, NULL);
	(void) duk_new(ctx, 0);
	(void) duk_next(ctx, 0, 0);
	(void) duk_normalize_index(ctx, 0);
	(void) duk_pcall_method(ctx, 0);
	(void) duk_pcall_prop(ctx, 0, 0);
	(void) duk_pcall(ctx, 0);
	(void) duk_pcompile_lstring_filename(ctx, 0, "dummy", 0);
	(void) duk_pcompile_lstring(ctx, 0, "dummy", 0);
	(void) duk_pcompile_string_filename(ctx, 0, "dummy");
	(void) duk_pcompile_string(ctx, 0, "dummy");
	(void) duk_pcompile(ctx, 0);
	(void) duk_peval_lstring_noresult(ctx, "dummy", 0);
	(void) duk_peval_lstring(ctx, "dummy", 0);
	(void) duk_peval_noresult(ctx);
	(void) duk_peval_string_noresult(ctx, "dummy");
	(void) duk_peval_string(ctx, "dummy");
	(void) duk_peval(ctx);
	(void) duk_pnew(ctx, 0);
	(void) duk_pop_2(ctx);
	(void) duk_pop_3(ctx);
	(void) duk_pop_n(ctx, 0);
	(void) duk_pop(ctx);
	(void) duk_push_array(ctx);
	(void) duk_push_boolean(ctx, 0);
	(void) duk_push_buffer_object(ctx, 0, 0, 0, 0);
	(void) duk_push_buffer(ctx, 0, 0);
	(void) duk_push_c_function(ctx, NULL, 0);
	(void) duk_push_c_lightfunc(ctx, NULL, 0, 0, 0);
	(void) duk_push_context_dump(ctx);
	(void) duk_push_current_function(ctx);
	(void) duk_push_current_thread(ctx);
	(void) duk_push_dynamic_buffer(ctx, 0);
	(void) duk_push_error_object_va(ctx, 0, NULL, NULL);
	(void) duk_push_error_object(ctx, 0, "dummy");
	(void) duk_push_external_buffer(ctx);
	(void) duk_push_false(ctx);
	(void) duk_push_fixed_buffer(ctx, 0);
	(void) duk_push_global_object(ctx);
	(void) duk_push_global_stash(ctx);
	(void) duk_push_heap_stash(ctx);
	(void) duk_push_heapptr(ctx, NULL);
	(void) duk_push_int(ctx, 0);
	(void) duk_push_lstring(ctx, "dummy", 0);
	(void) duk_push_nan(ctx);
	(void) duk_push_null(ctx);
	(void) duk_push_number(ctx, 0.0);
	(void) duk_push_object(ctx);
	(void) duk_push_pointer(ctx, NULL);
	(void) duk_push_sprintf(ctx, "dummy");
	(void) duk_push_string(ctx, "dummy");
	(void) duk_push_this(ctx);
	(void) duk_push_thread_new_globalenv(ctx);
	(void) duk_push_thread_stash(ctx, NULL);
	(void) duk_push_thread(ctx);
	(void) duk_push_true(ctx);
	(void) duk_push_uint(ctx, 0);
	(void) duk_push_undefined(ctx);
	(void) duk_push_vsprintf(ctx, "dummy", NULL);
	(void) duk_put_function_list(ctx, 0, NULL);
	(void) duk_put_global_string(ctx, NULL);
	(void) duk_put_number_list(ctx, 0, NULL);
	(void) duk_put_prop_index(ctx, 0, 0);
	(void) duk_put_prop_string(ctx, 0, "dummy");
	(void) duk_put_prop(ctx, 0);
	(void) duk_realloc_raw(ctx, NULL, 0);
	(void) duk_realloc(ctx, NULL, 0);
	(void) duk_remove(ctx, 0);
	(void) duk_replace(ctx, 0);
	(void) duk_require_boolean(ctx, 0);
	(void) duk_require_buffer_data(ctx, 0, NULL);
	(void) duk_require_buffer(ctx, 0, NULL);
	(void) duk_require_c_function(ctx, 0);
	(void) duk_require_callable(ctx, 0);
	(void) duk_require_context(ctx, 0);
	(void) duk_require_function(ctx, 0);
	(void) duk_require_heapptr(ctx, 0);
	(void) duk_require_int(ctx, 0);
	(void) duk_require_lstring(ctx, 0, NULL);
	(void) duk_require_normalize_index(ctx, 0);
	(void) duk_require_null(ctx, 0);
	(void) duk_require_number(ctx, 0);
	(void) duk_require_object_coercible(ctx, 0);
	(void) duk_require_pointer(ctx, 0);
	(void) duk_require_stack_top(ctx, 0);
	(void) duk_require_stack(ctx, 0);
	(void) duk_require_string(ctx, 0);
	(void) duk_require_top_index(ctx);
	(void) duk_require_type_mask(ctx, 0, 0);
	(void) duk_require_uint(ctx, 0);
	(void) duk_require_undefined(ctx, 0);
	(void) duk_require_valid_index(ctx, 0);
	(void) duk_resize_buffer(ctx, 0, 0);
	(void) duk_safe_call(ctx, NULL, NULL, 0, 0);
	(void) duk_safe_to_lstring(ctx, 0, NULL);
	(void) duk_safe_to_string(ctx, 0);
	(void) duk_set_finalizer(ctx, 0);
	(void) duk_set_global_object(ctx);
	(void) duk_set_magic(ctx, 0, 0);
	(void) duk_set_prototype(ctx, 0);
	(void) duk_set_top(ctx, 0);
	(void) duk_steal_buffer(ctx, 0, NULL);
	(void) duk_strict_equals(ctx, 0, 0);
	(void) duk_substring(ctx, 0, 0, 0);
	(void) duk_swap_top(ctx, 0);
	(void) duk_swap(ctx, 0, 0);
	(void) duk_throw(ctx);
	(void) duk_to_boolean(ctx, 0);
	(void) duk_to_buffer(ctx, 0, NULL);
	(void) duk_to_defaultvalue(ctx, 0, 0);
	(void) duk_to_dynamic_buffer(ctx, 0, NULL);
	(void) duk_to_fixed_buffer(ctx, 0, NULL);
	(void) duk_to_int32(ctx, 0);
	(void) duk_to_int(ctx, 0);
	(void) duk_to_lstring(ctx, 0, NULL);
	(void) duk_to_null(ctx, 0);
	(void) duk_to_number(ctx, 0);
	(void) duk_to_object(ctx, 0);
	(void) duk_to_pointer(ctx, 0);
	(void) duk_to_primitive(ctx, 0, 0);
	(void) duk_to_string(ctx, 0);
	(void) duk_to_uint16(ctx, 0);
	(void) duk_to_uint32(ctx, 0);
	(void) duk_to_uint(ctx, 0);
	(void) duk_to_undefined(ctx, 0);
	(void) duk_trim(ctx, 0);
	(void) duk_xcopy_top(ctx, NULL, 0);
	(void) duk_xmove_top(ctx, NULL, 0);

	printf("never here\n"); fflush(stdout);
	return 0;
}
コード例 #26
0
//void *duk_to_pointer(duk_context *ctx, duk_idx_t index);
void *aperl_duk_to_pointer(duk_context *ctx, duk_idx_t index) {
	void *ret = duk_to_pointer(ctx, index);
	return ret;
}
コード例 #27
0
ファイル: test-to-pointer.c プロジェクト: OakLabsInc/duktape
static duk_ret_t test_2(duk_context *ctx) {
	duk_set_top(ctx, 0);
	duk_to_pointer(ctx, 3);
	printf("index 3 OK\n");
	return 0;
}