コード例 #1
0
ファイル: jsd_val.c プロジェクト: ThinkerYzu/mozilla-central
/*
 * Create a new JSD value referring to a jsval. Copy string values into the
 * JSD compartment. Leave all other GCTHINGs in their native compartments
 * and access them through cross-compartment calls.
 */
JSDValue*
jsd_NewValue(JSDContext* jsdc, jsval val)
{
    JSDValue* jsdval;
    JSCrossCompartmentCall *call = NULL;

    if(!(jsdval = (JSDValue*) calloc(1, sizeof(JSDValue))))
        return NULL;

    if(JSVAL_IS_GCTHING(val))
    {
        JSBool ok;
        JS_BeginRequest(jsdc->dumbContext);

        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
        if(!call) {
            JS_EndRequest(jsdc->dumbContext);
            free(jsdval);
            return NULL;
        }

        ok = JS_AddNamedValueRoot(jsdc->dumbContext, &jsdval->val, "JSDValue");
        if(ok && JSVAL_IS_STRING(val)) {
            if(!JS_WrapValue(jsdc->dumbContext, &val)) {
                ok = JS_FALSE;
            }
        }

        JS_LeaveCrossCompartmentCall(call);
        JS_EndRequest(jsdc->dumbContext);
        if(!ok)
        {
            free(jsdval);
            return NULL;
        }
    }
    jsdval->val  = val;
    jsdval->nref = 1;
    JS_INIT_CLIST(&jsdval->props);

    return jsdval;
}
コード例 #2
0
CEXPORT JSBool def_timestep_view_set_filterColor(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp) {
	JS_BeginRequest(cx);
	timestep_view *thiz = (timestep_view*)JS_GetPrivate(obj.get());
	if (thiz) {
		
		if (vp.isString()) {
	JSString *jstr = vp.toString();

	JSTR_TO_CSTR(cx, jstr, cstr);

	rgba color;
	rgba_parse(&color, cstr);
	thiz->filter_color = color;
}

		
	}
	JS_EndRequest(cx);
	return JS_TRUE;
}
コード例 #3
0
JSBool round_js_sm_removeregistry(JSContext *cx, unsigned argc, jsval *vp) {
  if (argc < 1)
    return JS_FALSE;
  
  Round::LocalNode *node = dynamic_cast<Round::LocalNode *>(round_js_sm_getlocalnode());
  if (!node)
    return JS_FALSE;
  
  JS_BeginRequest(cx);
  
  std::string key;
  JSSTRING_TO_STDSTRING(cx, vp, 0, &key);
  
  bool isSuccess = node->removeRegistry(key);
  JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(JSBool(isSuccess)));
  
  JS_EndRequest(cx);
  
  return JS_TRUE;
}
コード例 #4
0
ファイル: jsd_val.cpp プロジェクト: mvarie/Spidermonkey
void
jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval)
{
    JSCompartment* oldCompartment = NULL;

    JS_ASSERT(jsdval->nref > 0);
    if(0 == --jsdval->nref)
    {
        jsd_RefreshValue(jsdc, jsdval);
        if(JSVAL_IS_GCTHING(jsdval->val))
        {
            JS_BeginRequest(jsdc->dumbContext);
            oldCompartment = JS_EnterCompartment(jsdc->dumbContext, jsdc->glob);
            JS_RemoveValueRoot(jsdc->dumbContext, &jsdval->val);
            JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
            JS_EndRequest(jsdc->dumbContext);
        }
        free(jsdval);
    }
}
コード例 #5
0
ファイル: keep-alive.cpp プロジェクト: GNOME/gjs
void
gjs_keep_alive_remove_global_child(JSContext         *context,
                                   GjsUnrootedFunc  notify,
                                   JSObject          *child,
                                   void              *data)
{
    JSObject *keep_alive;

    JS_BeginRequest(context);

    keep_alive = gjs_keep_alive_get_global(context);

    if (!keep_alive)
        g_error("no keep_alive property on the global object, have you "
                "previously added this child?");

    gjs_keep_alive_remove_child(keep_alive, notify, child, data);

    JS_EndRequest(context);
}
コード例 #6
0
ファイル: js_sm_functions.c プロジェクト: cybergarage/round
JSBool round_js_sm_getnodestate(JSContext* cx, unsigned argc, jsval* vp)
{
  RoundLocalNode* node = round_js_sm_getlocalnode();
  if (!node)
    return JS_FALSE;

  JS_BeginRequest(cx);

  /*
  RoundLocalNodeResponse nodeRes;
  Round::SystemGetNodeInfoResponse sysRes(&nodeRes);
  sysRes.setNode(node);
  
  JS_SET_NODERESPONSE_RVAL(cx, vp, nodeRes);
  */

  JS_EndRequest(cx);

  return JS_TRUE;
}
コード例 #7
0
ファイル: jsd_val.c プロジェクト: MozillaOnline/gecko-dev
const char*
jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval)
{
    JSContext* cx = jsdc->dumbContext;
    JSFunction* fun;
    JSExceptionState* exceptionState;

    if(!jsdval->funName && jsd_IsValueFunction(jsdc, jsdval))
    {
        JS_BeginRequest(cx);
        exceptionState = JS_SaveExceptionState(cx);
        fun = JS_ValueToFunction(cx, jsdval->val);
        JS_RestoreExceptionState(cx, exceptionState);
        JS_EndRequest(cx);
        if(!fun)
            return NULL;
        jsdval->funName = JS_GetFunctionName(fun);
    }
    return jsdval->funName;
}
コード例 #8
0
ファイル: Core.cpp プロジェクト: mandrake/lulzjs
JSObject*
Core_initialize (JSContext *cx, const char* path)
{
    JS_BeginRequest(cx);
    JS_SetOptions(cx, JSOPTION_VAROBJFIX|JSOPTION_JIT|JSOPTION_XML);
    JS_SetVersion(cx, JS_StringToVersion("1.8"));

    JSObject* object = JS_NewObject(cx, &Core_class, NULL, NULL);

    if (object && JS_InitStandardClasses(cx, object)) {
        JS_DefineFunctions(cx, object, Core_methods);

        JS_EnterLocalRootScope(cx);

        // Properties
        jsval property;

        std::string rootPath = __Core_getRootPath(cx, path);
        jsval paths[] = {
            STRING_TO_JSVAL(JS_NewString(cx, JS_strdup(cx, rootPath.c_str()), rootPath.length())),
            STRING_TO_JSVAL(JS_NewString(cx, JS_strdup(cx, __LJS_LIBRARY_PATH__), strlen(__LJS_LIBRARY_PATH__)))
        };
        property = OBJECT_TO_JSVAL(JS_NewArrayObject(cx, 2, paths));
        JS_SetProperty(cx, object, "__PATH__", &property);

        property = STRING_TO_JSVAL(JS_NewString(cx, JS_strdup(cx, __LJS_VERSION__), strlen(__LJS_VERSION__)));
        JS_SetProperty(cx, object, "__VERSION__", &property);

        property = OBJECT_TO_JSVAL(object);
        JS_SetProperty(cx, object, "Program", &property);

        JS_LeaveLocalRootScope(cx);
        JS_EndRequest(cx);

        if (__Core_include(cx, __LJS_LIBRARY_PATH__ "/Core")) {
            return object;
        }
    }

    return NULL;
}
コード例 #9
0
ファイル: jsapi-util-string.cpp プロジェクト: victoryang/gjs
JSBool
gjs_string_from_utf8(JSContext  *context,
                     const char *utf8_string,
                     gssize      n_bytes,
                     jsval      *value_p)
{
    jschar *u16_string;
    glong u16_string_length;
    JSString *str;
    GError *error;

    /* intentionally using n_bytes even though glib api suggests n_chars; with
    * n_chars (from g_utf8_strlen()) the result appears truncated
    */

    error = NULL;
    u16_string = g_utf8_to_utf16(utf8_string,
                                 n_bytes,
                                 NULL,
                                 &u16_string_length,
                                 &error);
    if (!u16_string) {
        gjs_throw(context,
                  "Failed to convert UTF-8 string to "
                  "JS string: %s",
                  error->message);
                  g_error_free(error);
        return JS_FALSE;
    }

    JS_BeginRequest(context);

    /* Avoid a copy - assumes that g_malloc == js_malloc == malloc */
    str = JS_NewUCString(context, u16_string, u16_string_length);

    if (str && value_p)
        *value_p = STRING_TO_JSVAL(str);

    JS_EndRequest(context);
    return str != NULL;
}
コード例 #10
0
ファイル: Core.cpp プロジェクト: mandrake/lulzjs
std::string
__Core_getPath (JSContext* cx, std::string fileName)
{
    /*
     * Getting the dirname of the file from the other file is included
     * then copying it and getting the path to the dir.
     */
    const char* scriptName = __Core_getScriptName(cx);
    char* from             = strdup(scriptName ? scriptName : "");
    char* dir              = dirname(from);
    std::string path       = std::string(dir) + "/" + fileName;
    free(from);

    JS_BeginRequest(cx);
    
    struct stat test;
    if (stat(path.c_str(), &test) != 0) {
        JSObject* lPath; JS_ValueToObject(cx, JS_EVAL(cx, "Program.__PATH__"), &lPath);

        if (lPath) {
            jsuint length;
            JS_GetArrayLength(cx, lPath, &length);

            size_t i;
            for (i = 0; i < length; i++) {
                jsval pathFile;
                JS_GetElement(cx, lPath, i, &pathFile);

                path = std::string(JS_GetStringBytes(JSVAL_TO_STRING(pathFile))) + "/" + fileName;

                if (stat(path.c_str(), &test) == 0) {
                    break;
                }
            }
        }
    }

    JS_EndRequest(cx);

    return path;
}
コード例 #11
0
ファイル: jsd_val.c プロジェクト: moussa1/mozilla-central
JSDValue*
jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
{
    JSCrossCompartmentCall *call = NULL;

    if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_CTOR)))
    {
        JSObject* obj;
        JSObject* proto;
        JSObject* ctor;
        JS_ASSERT(!jsdval->ctor);
        SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
        if(!JSVAL_IS_OBJECT(jsdval->val))
            return NULL;
        if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
            return NULL;
        JS_BeginRequest(jsdc->dumbContext);
        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
        if(!call) {
            JS_EndRequest(jsdc->dumbContext);

            return NULL;
        }
        proto = JS_GetPrototype(jsdc->dumbContext,obj);
        if(!proto)
        {
            JS_LeaveCrossCompartmentCall(call);
            JS_EndRequest(jsdc->dumbContext);
            return NULL;
        }
        ctor = JS_GetConstructor(jsdc->dumbContext,proto);
        JS_LeaveCrossCompartmentCall(call);
        JS_EndRequest(jsdc->dumbContext);
        if(!ctor)
            return NULL;
        jsdval->ctor = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(ctor));
    }
    if(jsdval->ctor)
        jsdval->ctor->nref++;
    return jsdval->ctor;
}
コード例 #12
0
ファイル: dir2nvfs.cpp プロジェクト: nidium/Nidium
static int Embed(int argc, char **argv)
{
    Core::Context *ncx = initNidiumJS();
    JSContext *cx      = ncx->getNJS()->getJSContext();

    if (argc <= 1) {
        printf("$ %s <path> [prefix] [> out]\n", argv[0]);
        return 1;
    }

    DIR *dir = opendir(argv[1]);
    if (!dir) {
        fprintf(stderr, "Can't open dir %s\n", argv[1]);
    }

    JS_BeginRequest(cx);

    JSNFS *nfs = new JSNFS(cx);

    bool ok;
    if (argc == 3) {
        std::string prefix = "/";
        prefix += argv[2];

        fprintf(stderr, "Create prefix %s...\n", prefix.c_str());

        nfs->mkdir(prefix.c_str(), strlen(prefix.c_str()));

        ok = listdir(nfs, dir, argv[1], strlen(argv[1]));
    } else {
        ok = listdir(nfs, dir, argv[1], strlen(argv[1]));
    }

    nfs->save(DIR2NFS_OUTPUT);

    JS_EndRequest(cx);

    delete ncx;

    return ok ? 0 : 1;
}
コード例 #13
0
ファイル: jsd_stak.c プロジェクト: lofter2011/Icefox
JSDValue*
jsd_GetThisForStackFrame(JSDContext* jsdc, 
                         JSDThreadState* jsdthreadstate,
                         JSDStackFrameInfo* jsdframe)
{
    JSObject* obj;
    JSDValue* jsdval = NULL;
    JSD_LOCK_THREADSTATES(jsdc);

    if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
    {
        JS_BeginRequest(jsdthreadstate->context);
        obj = JS_GetFrameThis(jsdthreadstate->context, jsdframe->fp);
        JS_EndRequest(jsdthreadstate->context);
        if(obj)
            jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
    }

    JSD_UNLOCK_THREADSTATES(jsdc);
    return jsdval;
}
コード例 #14
0
ファイル: js_xdeploy.cpp プロジェクト: z4y4/njord
BOOL __declspec(dllexport) InitExports(JSContext * cx, JSObject * global)
{
	JSFunctionSpec xdeployFunctions[] = {
		{ "SetComputerName", setcomputername, 2, 0 },
		{ "NetJoinDomain", netjoindomain, 6, 0 },
		{ "NetLocalGroupAddMembers", netlocalgroupaddmembers, 2, 0 },
		{ "NetGetLastErrorMessage", GetLastNetErrorMessage, 1, 0 },
		{ "NetGetJoinableOUs", netgetjoinableous, 3, 0 },
		{ "HideFirstUXWnd", close_FirstUXWnd, 0, 0 },
		{ 0 },
	};

	JS_BeginRequest(cx);
	JS_DefineFunctions(cx, global, xdeployFunctions);
	JS_DefineConstDoubles(cx, global, xdeployConsts);
	InitCrypto(cx, global);
	InitMsi(cx, global);
	InitProgressDlg(cx, global);
	JS_EndRequest(cx);
	return TRUE;
}
コード例 #15
0
ファイル: TCP.cpp プロジェクト: mandrake/lulzjs
JSBool
TCP_initialize (JSContext* cx)
{
    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    JSObject* parent = JSVAL_TO_OBJECT(JS_EVAL(cx, "System.Network.Sockets"));

    JSObject* object = JS_InitClass(
        cx, parent, JSVAL_TO_OBJECT(JS_EVAL(cx, "System.Network.Sockets.prototype")), &TCP_class,
        TCP_constructor, 1, TCP_attributes, TCP_methods, NULL, TCP_static_methods
    );

    if (object) {
        JS_LeaveLocalRootScope(cx);
        JS_EndRequest(cx);
        return JS_TRUE;
    }

    return JS_FALSE;
}
コード例 #16
0
ファイル: controller.cpp プロジェクト: dewn49/FreeJ
/* JSCall function by name, cvalues will be converted
 *
 * deactivates controller if any script errors!
 *
 * format values:
 * case 'b': BOOLEAN_TO_JSVAL((JSBool) va_arg(ap, int));
 * case 'c': INT_TO_JSVAL((uint16) va_arg(ap, unsigned int));
 * case 'i':
 * case 'j': js_NewNumberValue(cx, (jsdouble) va_arg(ap, int32), sp)
 * case 'u': js_NewNumberValue(cx, (jsdouble) va_arg(ap, uint32), sp)
 * case 'd':
 * case 'I': js_NewDoubleValue(cx, va_arg(ap, jsdouble), sp)
 * case 's': JS_NewStringCopyZ(cx, va_arg(ap, char *))
 * case 'W': JS_NewUCStringCopyZ(cx, va_arg(ap, jschar *))
 * case 'S': va_arg(ap, JSString *)
 * case 'o': OBJECT_TO_JSVAL(va_arg(ap, JSObject *)
 * case 'f':
 * fun = va_arg(ap, JSFunction *);
 *       fun ? OBJECT_TO_JSVAL(fun->object) : JSVAL_NULL;
 * case 'v': va_arg(ap, jsval);
 */
bool ControllerListener::call(const char *funcname, int argc, const char *format, ...) {
    va_list ap;
    jsval fval = JSVAL_VOID;
    jsval ret = JSVAL_VOID;
    
    func("%s try calling method %s.%s(argc:%i)", __func__, name, funcname, argc);
    JS_SetContextThread(jsContext);
    JS_BeginRequest(jsContext);
    int res = JS_GetProperty(jsContext, jsObject, funcname, &fval);
    
    if(JSVAL_IS_VOID(fval)) {
        warning("method unresolved by JS_GetProperty");
    } else {
        jsval *argv;
        void *markp;
        
        va_start(ap, format);
        argv = JS_PushArgumentsVA(jsContext, &markp, format, ap);
        va_end(ap);
        
        res = JS_CallFunctionValue(jsContext, jsObject, fval, argc, argv, &ret);
        JS_PopArguments(jsContext, &markp);
        
        if (res) {
            if(!JSVAL_IS_VOID(ret)) {
                JSBool ok;
                JS_ValueToBoolean(jsContext, ret, &ok);
                if (ok) // JSfunc returned 'true', so event is done
                {
                    JS_EndRequest(jsContext);
                    JS_ClearContextThread(jsContext);
                    return true;
                }
            }
        }
    }
    JS_EndRequest(jsContext);
    JS_ClearContextThread(jsContext);
    return false; // no callback, redo on next controller
}
コード例 #17
0
ファイル: importer.c プロジェクト: KNOPOChKA2/gjs
/*
 * Like JSResolveOp, but flags provide contextual information as follows:
 *
 *  JSRESOLVE_QUALIFIED   a qualified property id: obj.id or obj[id], not id
 *  JSRESOLVE_ASSIGNING   obj[id] is on the left-hand side of an assignment
 *  JSRESOLVE_DETECTING   'if (o.p)...' or similar detection opcode sequence
 *  JSRESOLVE_DECLARING   var, const, or function prolog declaration opcode
 *  JSRESOLVE_CLASSNAME   class name used when constructing
 *
 * The *objp out parameter, on success, should be null to indicate that id
 * was not resolved; and non-null, referring to obj or one of its prototypes,
 * if id was resolved.
 */
static JSBool
importer_new_resolve(JSContext *context,
                     JSObject  *obj,
                     jsid       id,
                     uintN      flags,
                     JSObject **objp)
{
    Importer *priv;
    char *name;
    JSBool ret = JS_TRUE;

    *objp = NULL;

    if (!gjs_get_string_id(context, id, &name))
        return JS_FALSE;

    /* let Object.prototype resolve these */
    if (strcmp(name, "valueOf") == 0 ||
            strcmp(name, "toString") == 0 ||
            strcmp(name, "__iterator__") == 0)
        goto out;

    priv = priv_from_js(context, obj);
    gjs_debug_jsprop(GJS_DEBUG_IMPORTER, "Resolve prop '%s' hook obj %p priv %p", name, obj, priv);

    if (priv == NULL) /* we are the prototype, or have the wrong class */
        goto out;

    JS_BeginRequest(context);
    if (do_import(context, obj, priv, name)) {
        *objp = obj;
    } else {
        ret = JS_FALSE;
    }
    JS_EndRequest(context);

out:
    g_free(name);
    return ret;
}
コード例 #18
0
ファイル: win32s.cpp プロジェクト: z4y4/njord
JSBool win32_impersonateuser(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	JSString * username, * password, *domain = NULL;
	DWORD logonType = LOGON32_LOGON_INTERACTIVE;
	JS_BeginRequest(cx);
	if(!JS_ConvertArguments(cx, argc, argv, "S S /S u", &username, &password, &domain, &logonType))
	{
		JS_ReportError(cx, "Unable to parse arguments in ImpersonateUser");
		JS_EndRequest(cx);
		return JS_FALSE;
	}

	if(logonType == LOGON32_LOGON_NETWORK)
	{
		*rval = JSVAL_FALSE;
		JS_EndRequest(cx);
		return JS_TRUE;
	}

	LPWSTR domainName = NULL;
	if(domain != NULL)
		domainName = (LPWSTR)JS_GetStringChars(domain);

	HANDLE newToken = NULL;
	JS_YieldRequest(cx);
	if(!LogonUser((LPWSTR)JS_GetStringChars(username), domainName, (LPWSTR)JS_GetStringChars(password), logonType, LOGON32_PROVIDER_DEFAULT, &newToken))
	{
		*rval = JSVAL_FALSE;
		JS_EndRequest(cx);
		return JS_TRUE;
	}

	if(!ImpersonateLoggedOnUser(newToken))
		*rval = JSVAL_FALSE;
	else
		*rval = JSVAL_TRUE;
	CloseHandle(newToken);
	JS_EndRequest(cx);
	return JS_TRUE;
}
コード例 #19
0
ファイル: importer.cpp プロジェクト: invy/xpjs
/*
 * Like JSResolveOp, but flags provide contextual information as follows:
 *
 *  JSRESOLVE_QUALIFIED   a qualified property id: obj.id or obj[id], not id
 *  JSRESOLVE_ASSIGNING   obj[id] is on the left-hand side of an assignment
 *  JSRESOLVE_DETECTING   'if (o.p)...' or similar detection opcode sequence
 *  JSRESOLVE_DECLARING   var, const, or function prolog declaration opcode
 *  JSRESOLVE_CLASSNAME   class name used when constructing
 *
 * The *objp out parameter, on success, should be null to indicate that id
 * was not resolved; and non-null, referring to obj or one of its prototypes,
 * if id was resolved.
 */
static JSBool
importer_new_resolve(JSContext *context,
                     JS::HandleObject obj,
                     JS::HandleId id,
                     unsigned flags,
                     JS::MutableHandleObject objp)
{
    Importer *priv;
    std::string name;
    JSBool ret = JS_TRUE;
    jsid module_init_name;

    module_init_name = gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT);
    if (id == module_init_name)
        return JS_TRUE;

    if (!gjs_get_string_id(context, id, name))
        return JS_FALSE;

    /* let Object.prototype resolve these */
    if (name == "valueOf" ||
        name == "toString" ||
        name == "__iterator__")
        goto out;
    priv = priv_from_js(context, obj);

//    std::cout << "Resolve prop '" << name << "' hook obj " << (uint32_t)*obj << " priv " << (uint32_t)priv << "\n";
    if (priv == NULL) /* we are the prototype, or have the wrong class */
        goto out;
    JS_BeginRequest(context);
    if (do_import(context, obj, priv, name)) {
        objp.set(obj);
    } else {
        ret = JS_FALSE;
    }
    JS_EndRequest(context);

 out:
    return ret;
}
コード例 #20
0
ファイル: Core.cpp プロジェクト: mandrake/lulzjs
JSBool
Core_die (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    char* error;

    JS_BeginRequest(cx);

    if (argc) {
        error = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
    }
    else {
        error = strdup("Program died.");
    }

    JS_ReportError(cx, error);
    JS_ReportPendingException(cx);

    JS_EndRequest(cx);

    exit(EXIT_FAILURE);
    return JS_FALSE;
}
コード例 #21
0
ファイル: keep-alive.c プロジェクト: sjokkis/gjs
JSObject*
gjs_keep_alive_get_global(JSContext *context)
{
    jsval value;
    JSObject *global;
    JSObject *result;

    JS_BeginRequest(context);

    global = JS_GetGlobalObject(context);

    gjs_object_get_property(context, global, GLOBAL_KEEP_ALIVE_NAME, &value);

    if (JSVAL_IS_OBJECT(value))
        result = JSVAL_TO_OBJECT(value);
    else
        result = NULL;

    JS_EndRequest(context);

    return result;
}
CEXPORT JSBool def_timestep_image_map_set_url(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp) {
	JS_BeginRequest(cx);
	timestep_image_map *thiz = (timestep_image_map*)JS_GetPrivate(obj.get());
	if (thiz) {
		
		if (vp.isString()) {
	JSString *jstr = vp.toString();

	JSTR_TO_CSTR_PERSIST(cx, jstr, cstr);

	if (thiz->url) {
		free(thiz->url);
	}

	thiz->url = cstr;
}

		
	}
	JS_EndRequest(cx);
	return JS_TRUE;
}
コード例 #23
0
ファイル: Window.cpp プロジェクト: meh/lulzjs-ncurses
void
__Window_updatePosition (JSContext* cx, JSObject* object)
{
    int y, x;
    WINDOW* win = (WINDOW*) JS_GetPrivate(cx, object);
    getbegyx(win, y, x);

    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    jsval jsPosition; JS_GetProperty(cx, object, "Position", &jsPosition);
    JSObject* Position = JSVAL_TO_OBJECT(jsPosition);

    jsval property;
    property = INT_TO_JSVAL(y);
    JS_SetProperty(cx, Position, "Y", &property);
    property = INT_TO_JSVAL(x);
    JS_SetProperty(cx, Position, "X", &property);

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);
}
コード例 #24
0
ファイル: controller.cpp プロジェクト: dewn49/FreeJ
int Controller::JSCall(const char *funcname, int argc, const char *format, ...)
{
    int res;
    jsval *argv;
    va_list args;
    ControllerListener *listener = listeners.begin();
    va_start(args, format);
    va_end(args);
    while (listener) {
        void *markp = NULL;
        JS_SetContextThread(listener->context());
        JS_BeginRequest(listener->context());
        argv = JS_PushArgumentsVA(listener->context(), &markp, format, args);
        JS_EndRequest(listener->context());
        JS_ClearContextThread(listener->context());
        // TODO - unregister listener if returns false
        if (listener->call(funcname, argc, argv))
            res++;
        listener = (ControllerListener *)listener->next;
    }
    return res;
}
コード例 #25
0
ファイル: domnode.cpp プロジェクト: z4y4/njord
JSBool stringPropGetter(JSContext * cx, JSObject * obj, jsval idval, jsval * vp)
{
	JS_BeginRequest(cx);
	nsCOMPtr<nsIDOMNode> mNode = (nsIDOMNode*)JS_GetPrivate(cx, obj);
	nsCOMPtr<nsIDOMElement> mElement = do_QueryInterface(mNode);

	nsString value;
	switch(JSVAL_TO_INT(idval))
	{
	case NAME_PROP:
		mNode->GetNodeName(value);
		break;
	case VALUE_PROP:
		mNode->GetNodeValue(value);
		break;
	case TAGNAME_PROP:
		if(mElement)
			mElement->GetTagName(value);
		break;
	case TEXT_PROP:
		{
			nsCOMPtr<nsIDOM3Node> l3Node = do_QueryInterface(mNode);
			if(l3Node != NULL)
				l3Node->GetTextContent(value);
		}
		break;
	}

	if(value.IsEmpty())
		*vp = JSVAL_NULL;
	else
	{
		JSString * retVal = JS_NewUCStringCopyZ(cx, (jschar*)value.get());
		*vp = STRING_TO_JSVAL(retVal);
	}
	JS_EndRequest(cx);
	return JS_TRUE;
}
コード例 #26
0
ファイル: jsd_val.c プロジェクト: moussa1/mozilla-central
JSDScript*
jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval)
{
    JSContext* cx = jsdc->dumbContext;
    jsval val = jsdval->val;
    JSFunction* fun = NULL;
    JSExceptionState* exceptionState;
    JSScript* script = NULL;
    JSDScript* jsdscript;
    JSCrossCompartmentCall *call = NULL;

    if (!jsd_IsValueFunction(jsdc, jsdval))
        return NULL;

    JS_BeginRequest(cx);
    call = JS_EnterCrossCompartmentCall(cx, JSVAL_TO_OBJECT(val));
    if (!call) {
        JS_EndRequest(cx);

        return NULL;
    }

    exceptionState = JS_SaveExceptionState(cx);
    fun = JSD_GetValueFunction(jsdc, jsdval);
    JS_RestoreExceptionState(cx, exceptionState);
    if (fun)
        script = JS_GetFunctionScript(cx, fun);
    JS_LeaveCrossCompartmentCall(call);
    JS_EndRequest(cx);

    if (!script)
        return NULL;

    JSD_LOCK_SCRIPTS(jsdc);
    jsdscript = jsd_FindJSDScript(jsdc, script);
    JSD_UNLOCK_SCRIPTS(jsdc);
    return jsdscript;
}
コード例 #27
0
ファイル: context.c プロジェクト: Jonnyliu/phoneyc
PyObject*
Context_add_global(Context* self, PyObject* args, PyObject* kwargs)
{
    PyObject* pykey = NULL;
    PyObject* pyval = NULL;
    jsval jsk;
    jsid kid;
    jsval jsv;

    JS_BeginRequest(self->cx);

    if(!PyArg_ParseTuple(args, "OO", &pykey, &pyval)) goto error;

    jsk = py2js(self, pykey);
    if(jsk == JSVAL_VOID) goto error;

    if(!JS_ValueToId(self->cx, jsk, &kid))
    {
        PyErr_SetString(PyExc_AttributeError, "Failed to create key id.");
        goto error;
    }

    jsv = py2js(self, pyval);
    if(jsv == JSVAL_VOID) goto error;

    if(!js_SetProperty(self->cx, self->root, kid, &jsv))
    {
        PyErr_SetString(PyExc_AttributeError, "Failed to set global property.");
        goto error;
    }

    goto success;

error:
success:
    JS_EndRequest(self->cx);
    Py_RETURN_NONE;
}
コード例 #28
0
ファイル: js.c プロジェクト: Daisho/showtime
static int
js_init(void)
{
  JSContext *cx;
  jsval val;

  JS_SetCStringsAreUTF8();

  runtime = JS_NewRuntime(0x1000000);

  cx = js_newctx(err_reporter);

  JS_BeginRequest(cx);

  showtimeobj = JS_NewObject(cx, &showtime_class, NULL, NULL);
  JS_DefineFunctions(cx, showtimeobj, showtime_functions);

  val = INT_TO_JSVAL(showtime_get_version_int());
  JS_SetProperty(cx, showtimeobj, "currentVersionInt", &val);

  val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, htsversion));
  JS_SetProperty(cx, showtimeobj, "currentVersionString", &val);


  JSFunction *fn = JS_DefineFunction(cx, showtimeobj, "RichText",
				     js_RichText, 1, 0);
  RichText = JS_GetFunctionObject(fn);
	     
  JS_AddNamedRoot(cx, &showtimeobj, "showtime");

  js_global_cx = cx;
  JS_EndRequest(cx);
  JS_ClearContextThread(cx);
  js_global_pc = prop_courier_create_lockmgr("js", js_lockmgr, cx,
					     js_global_pc_prologue,
					     js_global_pc_epilogue);
  return 0;
}
コード例 #29
0
ファイル: jsapi-util.c プロジェクト: sjokkis/gjs
void*
gjs_get_instance_private_dynamic_with_typecheck(JSContext      *context,
                                                JSObject       *obj,
                                                JSClass        *static_clasp,
                                                jsval          *argv)
{
    RuntimeData *rd;
    JSClass *obj_class;
    void *instance;

    if (static_clasp->name != NULL) {
        g_warning("Dynamic class should not have a name in the JSClass struct");
        return NULL;
    }

    JS_BeginRequest(context);

    obj_class = JS_GET_CLASS(context, obj);
    g_assert(obj_class != NULL);

    rd = get_data_from_context(context);
    g_assert(rd != NULL);

    /* Check that it's safe to cast to DynamicJSClass */
    if (g_hash_table_lookup(rd->dynamic_classes, obj_class) == NULL) {
        JS_EndRequest(context);
        return NULL;
    }

    if (static_clasp != ((DynamicJSClass*) obj_class)->static_class) {
        JS_EndRequest(context);
        return NULL;
    }

    instance = JS_GetInstancePrivate(context, obj, obj_class, argv);
    JS_EndRequest(context);
    return instance;
}
コード例 #30
0
ファイル: jsapi-util.c プロジェクト: sjokkis/gjs
/* Returns whether the object had the property; if the object did
 * not have the property, always sets an exception. Treats
 * "the property's value is JSVAL_VOID" the same as "no such property,"
 * while JS_GetProperty() treats only "no such property" as an error.
 * Guarantees that *value_p is set to something, if only JSVAL_VOID,
 * even if an exception is set and false is returned.
 */
gboolean
gjs_object_require_property(JSContext       *context,
                            JSObject        *obj,
                            const char      *obj_description,
                            const char      *property_name,
                            jsval           *value_p)
{
    jsval value;

    JS_BeginRequest(context);

    value = JSVAL_VOID;
    JS_GetProperty(context, obj, property_name, &value);

    if (value_p)
        *value_p = value;

    if (value != JSVAL_VOID) {
        JS_ClearPendingException(context); /* in case JS_GetProperty() was on crack */
        JS_EndRequest(context);
        return TRUE;
    } else {
        /* remember gjs_throw() is a no-op if JS_GetProperty()
         * already set an exception
         */
        if (obj_description)
            gjs_throw(context,
                      "No property '%s' in %s (or its value was undefined)",
                      property_name, obj_description);
        else
            gjs_throw(context,
                      "No property '%s' in object %p (or its value was undefined)",
                      property_name, obj);

        JS_EndRequest(context);
        return FALSE;
    }
}