/* @history_funcs{"go"} */ static JSBool history_go(JSContext *ctx, unsigned int argc, jsval *rval) { struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct document_view *doc_view = interpreter->vs->doc_view; struct session *ses = doc_view->session; jsval *argv = JS_ARGV(ctx, rval); int index; struct location *loc; if (argc != 1) return JS_TRUE; index = atol(jsval_to_string(ctx, &argv[0])); for (loc = cur_loc(ses); loc != (struct location *) &ses->history.history; loc = index > 0 ? loc->next : loc->prev) { if (!index) { go_history(ses, loc); break; } index += index > 0 ? -1 : 1; } JS_SET_RVAL(ctx, rval, JSVAL_NULL); return 2; }
/* @location_class.setProperty */ static JSBool location_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp) { JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; /* This can be called if @obj if not itself an instance of the * appropriate class but has one in its prototype chain. Fail * such calls. */ if (!JS_InstanceOf(ctx, obj, (JSClass *) &location_class, NULL)) return JS_FALSE; parent_win = JS_GetParent(ctx, obj); assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL)); if_assert_failed return JS_FALSE; vs = (struct view_state *)JS_GetInstancePrivate(ctx, parent_win, (JSClass *) &window_class, NULL); doc_view = vs->doc_view; if (!JSID_IS_INT(id)) return JS_TRUE; switch (JSID_TO_INT(id)) { case JSP_LOC_HREF: location_goto(doc_view, jsval_to_string(ctx, vp)); break; } return JS_TRUE; }
unsigned char * spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter, struct string *code) { JSBool ret; JSContext *ctx; jsval rval; assert(interpreter); if (!js_module_init_ok) return NULL; ctx = interpreter->backend_data; interpreter->ret = NULL; #if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT) interpreter->heartbeat = add_heartbeat(interpreter); #elif defined(HAVE_JS_SETBRANCHCALLBACK) setup_safeguard(interpreter, ctx); #endif ret = JS_EvaluateScript(ctx, JS_GetGlobalObject(ctx), code->source, code->length, "", 0, &rval); #if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT) done_heartbeat(interpreter->heartbeat); #endif if (ret == JS_FALSE) { return NULL; } if (JSVAL_IS_VOID(rval) || JSVAL_IS_NULL(rval)) { /* Undefined value. */ return NULL; } return stracpy(jsval_to_string(ctx, &rval)); }
SEXP js_to_R(SEXP ptr) { jsval *p = R_ExternalPtrAddr(ptr); if(JSVAL_IS_INT(*p)) return(ScalarInteger(JSVAL_TO_INT(*p))); else if(JSVAL_IS_BOOLEAN(*p)) return(ScalarLogical(JSVAL_TO_BOOLEAN(*p))); else if(JSVAL_IS_DOUBLE(*p)) return(ScalarReal( * JSVAL_TO_DOUBLE(*p))); else if(JSVAL_IS_STRING(*p)) { return(jsval_to_string(ptr)); } else return(R_NilValue); }
static JSBool location_set_property_href(JSContext *ctx, JSHandleObject hobj, JSHandleId hid, JSBool strict, JSMutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; /* This can be called if @obj if not itself an instance of the * appropriate class but has one in its prototype chain. Fail * such calls. */ if (!JS_InstanceOf(ctx, obj, &location_class, NULL)) return JS_FALSE; parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); if_assert_failed return JS_FALSE; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; location_goto(doc_view, jsval_to_string(ctx, vp)); return JS_TRUE; }