예제 #1
0
파일: utils.c 프로젝트: nucleus-js/seaduk
void duv_store_handle(duk_context *ctx, void *handle) {
  duk_push_heap_stash(ctx);
  duk_dup(ctx, -2);
  snprintf(key, KEYLEN, "%"PRIXPTR, (uintptr_t)handle);
  duk_put_prop_string(ctx, -2, key);
  duk_pop(ctx);
}
예제 #2
0
    static Box * PrivatePush( duk_context * ctx, const size_t class_index, const size_t object_size, finalizer_t finalizer )
    {
        duk_push_global_object( ctx );
        duk_get_prop_string( ctx, -1, "Proxy" );
        duk_remove( ctx, -2 );

        duk_push_object( ctx );

        size_t require_size = sizeof( Box ) + object_size;

        Box * box = reinterpret_cast<Box*>( duk_push_fixed_buffer( ctx, require_size ) );
        box->ClassIndex = class_index;
        box->Finalizer = finalizer;

        duk_put_prop_string( ctx, -2, "\xFF" "Box" );

        duk_push_c_function( ctx, &internal::ClassFinalizer, 1 );
        duk_set_finalizer( ctx, -2 );

        duk_push_heap_stash( ctx );
        duk_get_prop_string( ctx, -1, "InstanceHandler" );
        duk_remove( ctx, -2 );
        duk_new( ctx, 2 );

        return box;
    }
예제 #3
0
파일: utils.c 프로젝트: nucleus-js/seaduk
duk_ret_t duv_setup_request(duk_context *ctx, uv_req_t* req, int callback) {
  // Create a new container object for the request with request methods
  duk_push_object(ctx);
  duk_push_heap_stash(ctx);
  duk_get_prop_string(ctx, -1, "req-prototype");
  duk_remove(ctx, -2);
  duk_set_prototype(ctx, -2);

  // Set buffer as uv-data internal property.
  duk_insert(ctx, -2);
  duk_put_prop_string(ctx, -2, "\xff""uv-data");

  // Store the request type.
  duk_push_int(ctx, req->type);
  duk_put_prop_string(ctx, -2, "\xff""req-type");

  // Store a reference to the lua callback
  duk_dup(ctx, callback);
  duk_put_prop_string(ctx, -2, "\xff""uv-callback");

  // Store this object in the heap stack keyed by the request's pointer address.
  // This will prevent it from being garbage collected and allow us to find
  // it with nothing more than the request's address.
  duv_store_handle(ctx, req);

  // Store the context in the handle so it can use duktape APIs.
  req->data = ctx;

  // TODO: is this still on the stack?
  return 1;
}
예제 #4
0
void test(duk_context *ctx) {
	printf("top: %d\n", duk_get_top(ctx));
	duk_push_heap_stash(ctx);
	printf("top: %d\n", duk_get_top(ctx));

	duk_push_int(ctx, 123);
	duk_put_prop_string(ctx, -2, "myvalue");
	duk_pop(ctx);
	printf("top: %d\n", duk_get_top(ctx));

	duk_push_heap_stash(ctx);
	duk_get_prop_string(ctx, -1, "myvalue");
	printf("value: %d\n", duk_get_int(ctx, -1));
	duk_pop(ctx);
	duk_pop(ctx);
	printf("top: %d\n", duk_get_top(ctx));
}
예제 #5
0
void PushWeakObject(duk_context* ctx, Object* object)
{
    if (!object)
    {
        duk_push_null(ctx);
        return;
    }

    duk_push_heap_stash(ctx);

    // Check if the wrapper for the object already exists in stash
    // This is required so that comparisons of object references (e.g. against the me property) work properly
    if (duk_has_prop_index(ctx, -1, (size_t)object))
    {
        duk_get_prop_index(ctx, -1, (size_t)object);
        WeakPtr<Object>* oldPtr = GetWeakPtr(ctx, -1);
        if (oldPtr && oldPtr->Get() == object)
        {
            duk_remove(ctx, -2); // Remove stash
            return;
        }
        else
            duk_pop(ctx); // Valid existing wrapper not found
    }

    duk_push_object(ctx);
    WeakPtr<Object>* ptr = new WeakPtr<Object>(object);
    duk_push_pointer(ctx, ptr);
    duk_put_prop_string(ctx, -2, "\xff""weak");
    duk_push_c_function(ctx, WeakPtr_Finalizer, 1);
    duk_set_finalizer(ctx, -2);

    // Set prototype. If not found, use base class prototype (e.g. IComponent)
    duk_get_global_string(ctx, object->GetTypeName().CString());
    if (!duk_is_object(ctx, -1))
    {
        duk_pop(ctx);
        duk_get_global_string(ctx, object->GetTypeInfo()->GetBaseTypeInfo()->GetTypeName().CString());
    }
    duk_get_prop_string(ctx, -1, "prototype");
    duk_set_prototype(ctx, -3);
    duk_pop(ctx);

    // Proxied property access handling for scene, entity & component
    if (object->GetType() == Scene::GetTypeStatic())
        SetupProxy(ctx, SceneProxyFunctions);
    if (object->GetType() == Entity::GetTypeStatic())
        SetupProxy(ctx, EntityProxyFunctions);
    else if (dynamic_cast<IComponent*>(object))
        SetupProxy(ctx, ComponentProxyFunctions);

    // Store to stash
    duk_dup(ctx, -1);
    duk_put_prop_index(ctx, -3, (size_t)object);
    duk_remove(ctx, -2); // Remove stash
}
예제 #6
0
파일: ref.c 프로젝트: hypoalex/mininode
/*
 * Create a global array refs in the heap stash.
 */
void
mn_ref_setup(duk_context *ctx) {
	duk_push_heap_stash(ctx);

	/* Create a new array with one `0` at index `0`. */
	duk_push_array(ctx);
	duk_push_int(ctx, 0);
	duk_put_prop_index(ctx, -2, 0);
	/* Store it as "refs" in the heap stash */
	duk_put_prop_string(ctx, -2, "refs");

	duk_pop(ctx);
}
예제 #7
0
파일: ref.c 프로젝트: hypoalex/mininode
void
mn_push_ref(duk_context *ctx, int ref) {
	if (!ref) {
		duk_push_undefined(ctx);
		return;
	}
	/* Get the "refs" array in the heap stash */
	duk_push_heap_stash(ctx);
	duk_get_prop_string(ctx, -1, "refs");
	duk_remove(ctx, -2);

	duk_get_prop_index(ctx, -1, ref);

	duk_remove(ctx, -2);
}
예제 #8
0
파일: ref.c 프로젝트: hypoalex/mininode
void
mn_unref(duk_context *ctx, int ref) {
	if (!ref) return;

	/* Get the "refs" array in the heap stash */
	duk_push_heap_stash(ctx);
	duk_get_prop_string(ctx, -1, "refs");
	duk_remove(ctx, -2);

	/* Insert a new link in the freelist */

	/* refs[ref] = refs[0] */
	duk_get_prop_index(ctx, -1, 0);
	duk_put_prop_index(ctx, -2, ref);
	/* refs[0] = ref */
	duk_push_int(ctx, ref);
	duk_put_prop_index(ctx, -2, 0);

	duk_pop(ctx);
}
예제 #9
0
파일: ref.c 프로젝트: hypoalex/mininode
/*
 * like luaL_ref, but assumes storage in "refs" property of heap stash
 */
int
mn_ref(duk_context *ctx) {
	int ref;
	if (duk_is_undefined(ctx, -1)) {
		duk_pop(ctx);
		return 0;
	}
	/* Get the "refs" array in the heap stash */
	duk_push_heap_stash(ctx);
	duk_get_prop_string(ctx, -1, "refs");
	duk_remove(ctx, -2);

	/* ref = refs[0] */
	duk_get_prop_index(ctx, -1, 0);
	ref = duk_get_int(ctx, -1);
	duk_pop(ctx);

	/* If there was a free slot, remove it from the list */
	if (ref != 0) {
		/* refs[0] = refs[ref] */
		duk_get_prop_index(ctx, -1, ref);
		duk_put_prop_index(ctx, -2, 0);
	} else {
		/* Otherwise use the end of the list */
		ref = duk_get_length(ctx, -1);
	}

	/* Swap the array and the user value in the stack */
	duk_insert(ctx, -2);

	/* refs[ref] = value */
	duk_put_prop_index(ctx, -2, ref);

	/* Remove the refs array from the stack. */
	duk_pop(ctx);

	return ref;
}
예제 #10
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;
}
예제 #11
0
/*----------------------------------------------------------------------------*/
void
kbjs_register_PinIds(duk_context *context)
{
    /* Get kb.rpi2 object */
    /* STACK: [global] */
    duk_push_global_object(context);
    /* STACK: [global, kb] */
    duk_get_prop_string(context, (duk_idx_t)-1, "kb");
    /* STACK: [global, kb, rpi] */
    duk_get_prop_string(context, (duk_idx_t)-1, "rpi2");

    /* Create storage for enums on heap_stash */
    /* STACK: [global, kb, rpi, stash] */
    duk_push_heap_stash(context);
    /* STACK: [global, kb, rpi, stash, {} */
    duk_push_object(context);
    /* STACK: [global, kb, rpi, stash */
    duk_put_prop_string(context, (duk_idx_t)-2, kbjs_PIN_ID_PROTO_STASH_KEY);
    /* STACK: [global, kb, rpi */
    duk_pop(context);

    /* Create PinId enums */
    #define CREATE_ENUM_(INDEX)                                                \
        kbjs_PIN_IDS[kb_rpi2_PIN##INDEX] = (kbjs_PinId){kb_rpi2_PIN##INDEX,    \
                                                        "kb.rpi2.PIN" #INDEX,  \
                                                        context,               \
                                                        ""};                   \
        kbjs_get_stash_key(KBJS_TYPES_STASH_KEY_LENGTH,                        \
                           kbjs_PIN_IDS[kb_rpi2_PIN##INDEX].js_stash_key);     \
        /* STACK: [global, kb, rpi, "PIN*"] */                                 \
        duk_push_string(context, "PIN" #INDEX);                                \
        /* STACK: [global, kb, rpi, "PIN*", {}] */                             \
        duk_push_object(context);                                              \
        /* STACK: [global, kb, rpi, "PIN*", {}, "instance_ptr"] */             \
        duk_push_string(context, KBJS_INSTANCE_PTR);                           \
        /* STACK: [global, kb, rpi, "PIN*", {}, "instance_ptr", void*] */      \
        duk_push_pointer(context, kbjs_PIN_IDS + kb_rpi2_PIN##INDEX);          \
        /* STACK: [global, kb, rpi, "PIN*", {}] */                             \
        duk_put_prop(context, (duk_idx_t)-3);                                  \
        /* STACK: [global, kb, rpi, "PIN*", {}, "toString"] */                 \
        duk_push_string(context, "toString");                                  \
        /* STACK: [global, kb, rpi, "PIN*", {}, "toString", function] */       \
        duk_push_c_function(context, kbjs_PinId_str, (duk_idx_t)0);            \
        /* STACK: [global, kb, rpi, "PIN*", {}] */                             \
        duk_put_prop(context, (duk_idx_t)-3);                                  \
        /* STACK: [global, kb, rpi, "PIN*", {}, "INDEX"] */                    \
        duk_push_string(context, #INDEX);                                      \
        /* STACK: [global, kb, rpi, "PIN*", {}] */                             \
        duk_put_prop_string(context, (duk_idx_t)-2, kbjs_PIN_ID_VALUE_KEY);    \
        /* STACK: [global, kb, rpi, "PIN*", {}, stash] */                      \
        duk_push_heap_stash(context);                                          \
        /* STACK: [global, kb, rpi, "PIN*", {}, stash, {}] */                  \
        duk_get_prop_string(context,                                           \
                            (duk_idx_t)-1,                                     \
                            kbjs_PIN_ID_PROTO_STASH_KEY);                      \
        /* STACK: [global, kb, rpi, "PIN*", {}, stash, {}, {}] */              \
        duk_dup(context, (duk_idx_t)-3);                                       \
        /* STACK: [global, kb, rpi, "PIN*", {}, stash, {} */                   \
        duk_put_prop_string(context, (duk_idx_t)-2, #INDEX);                   \
        /* STACK: [global, kb, rpi, "PIN*", {} */                              \
        duk_pop_2(context);                                                    \
        /* STACK: [global, kb, rpi] */                                         \
        duk_put_prop(context, (duk_idx_t)-3);
    #define CREATE_ENUM(PREFIX1, PREFIX2)                                      \
        CREATE_ENUM_(PREFIX1##1)                                               \
        CREATE_ENUM_(PREFIX1##2)                                               \
        CREATE_ENUM_(PREFIX1##3)                                               \
        CREATE_ENUM_(PREFIX1##4)                                               \
        CREATE_ENUM_(PREFIX1##5)                                               \
        CREATE_ENUM_(PREFIX1##6)                                               \
        CREATE_ENUM_(PREFIX1##7)                                               \
        CREATE_ENUM_(PREFIX1##8)                                               \
        CREATE_ENUM_(PREFIX1##9)                                               \
        CREATE_ENUM_(PREFIX2##0)
    CREATE_ENUM( , 1)
    CREATE_ENUM(1, 2)
    CREATE_ENUM(2, 3)
    CREATE_ENUM(3, 4)
    #undef CREATE_ENUM_
    #undef CREATE_ENUM

    /* Clean up */
    /* STACK: [] */
    duk_pop_3(context);
}
예제 #12
0
    void Setup( duk_context * ctx, const BindingInfo & info, const char * module )
    {
        debug::StackMonitor monitor( ctx );
        duk_push_global_stash( ctx );
        void * info_buffer = duk_push_fixed_buffer( ctx, sizeof( BindingInfo * ) );
        *reinterpret_cast<const BindingInfo**>( info_buffer ) = &info; // :TODO: Ref count

        duk_put_prop_string( ctx, -2, DUKBIND_BINDING_NAME );
        duk_pop( ctx );

        if( module )
        {
            duk_push_global_object( ctx );
            duk_get_prop_string( ctx, -1, "Proxy" );
            duk_push_object( ctx );
            duk_push_object( ctx );

            duk_push_c_function( ctx, internal::BindingGet, 2 );
            duk_put_prop_string( ctx, -2, "get" );

            duk_push_c_function( ctx, internal::BindingHas, 1 );
            duk_put_prop_string( ctx, -2, "has" );

            duk_push_c_function( ctx, internal::ForbidSet, 3 );
            duk_put_prop_string( ctx, -2, "set" );

            duk_push_c_function( ctx, internal::ForbidDelete, 1 );
            duk_put_prop_string( ctx, -2, "deleteProperty" );
            duk_new( ctx, 2 );

            duk_put_prop_string( ctx, -2, module );
            duk_pop( ctx );
        }
        else
        {

            duk_push_global_object( ctx );

            duk_get_prop_string( ctx, -1, "Proxy" );

            duk_dup( ctx, -2 );
            duk_push_object( ctx );

            duk_push_c_function( ctx, internal::GlobalsGet, 2 );
            duk_put_prop_string( ctx, -2, "get" );

            duk_push_c_function( ctx, internal::GlobalsHas, 1 );
            duk_put_prop_string( ctx, -2, "has" );

            duk_new( ctx, 2 );
            duk_set_global_object( ctx );

            duk_pop( ctx );
        }

        duk_push_heap_stash( ctx );
        duk_push_object( ctx );

        duk_push_c_function( ctx, internal::ClassGet, 2 );
        duk_put_prop_string( ctx, -2, "get" );

        duk_push_c_function( ctx, internal::ClassHas, 1 );
        duk_put_prop_string( ctx, -2, "has" );

        duk_push_c_function( ctx, internal::ClassSet, 3 );
        duk_put_prop_string( ctx, -2, "set" );

        duk_push_c_function( ctx, internal::ForbidDelete, 1 );
        duk_put_prop_string( ctx, -2, "deleteProperty" );

        duk_put_prop_string( ctx, -2, "InstanceHandler" );

        duk_pop( ctx );
    }
예제 #13
0
파일: utils.c 프로젝트: nucleus-js/seaduk
void duv_push_handle(duk_context *ctx, void *handle) {
  duk_push_heap_stash(ctx);
  snprintf(key, KEYLEN, "%"PRIXPTR, (uintptr_t)handle);
  duk_get_prop_string(ctx, -1, key);
  duk_remove(ctx, -2);
}
예제 #14
0
//void duk_push_heap_stash(duk_context *ctx);
void aperl_duk_push_heap_stash(duk_context *ctx) {
	duk_push_heap_stash(ctx);
}