Пример #1
0
void
Function_dealloc(Function* self)
{
    if(self->parent != JSVAL_VOID)
    {
        JS_BeginRequest(self->obj.cx->cx);
        JS_RemoveRoot(self->obj.cx->cx, &(self->parent));
        JS_EndRequest(self->obj.cx->cx);
    }

    ObjectType->tp_dealloc((PyObject*) self);
}
CEXPORT bool def_timestep_image_map_get_url(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) {
	JS_BeginRequest(cx);
	timestep_image_map *thiz = (timestep_image_map*)JS_GetPrivate(obj.get());
	if (thiz) {
		
		vp.setString(JS_NewStringCopyZ(cx, thiz->url));

		
	}
	JS_EndRequest(cx);
	return true;
}
Пример #3
0
CEXPORT JSBool def_animate_resume(JSContext *cx, unsigned argc, jsval *vp) {
	JS_BeginRequest(cx);

	JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp));
	view_animation *anim = (view_animation *)JS_GetPrivate(thiz);
	view_animation_resume(anim);
	jsval thiz_val = OBJECT_TO_JSVAL(thiz);
	JS_SET_RVAL(cx, vp, thiz_val);

	JS_EndRequest(cx);
	return JS_TRUE;
}
nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length,
                                   const char *filename, PRBool bGlobalContext, 
                                   PRBool bCallbacks, PRBool skipFirstLine)
{
    JSBool ok;
    jsval result;

    if (skipFirstLine) {
        /* In order to protect the privacy of the JavaScript preferences file 
         * from loading by the browser, we make the first line unparseable
         * by JavaScript. We must skip that line here before executing 
         * the JavaScript code.
         */
        unsigned int i = 0;
        while (i < length) {
            char c = js_buffer[i++];
            if (c == '\r') {
                if (js_buffer[i] == '\n')
                    i++;
                break;
            }
            if (c == '\n')
                break;
        }

        length -= i;
        js_buffer += i;
    }

    nsresult rv;
    nsCOMPtr<nsIJSContextStack> cxstack = 
        do_GetService("@mozilla.org/js/xpc/ContextStack;1");
    rv = cxstack->Push(autoconfig_cx);
    if (NS_FAILED(rv)) {
        NS_ERROR("coudn't push the context on the stack");
        return rv;
    }

    JS_BeginRequest(autoconfig_cx);
    ok = JS_EvaluateScript(autoconfig_cx, autoconfig_glob,
                           js_buffer, length, filename, 0, &result);
    JS_EndRequest(autoconfig_cx);

    JS_MaybeGC(autoconfig_cx);

    JSContext *cx;
    cxstack->Pop(&cx);
    NS_ASSERTION(cx == autoconfig_cx, "AutoConfig JS contexts didn't match");

    if (ok)
        return NS_OK;
    return NS_ERROR_FAILURE;
}
Пример #5
0
nsresult
xgGtkElement::DefineProperties ()
{
    nsresult rv;

    JSContext *jscx;
    rv = GetJSContext (&jscx);
    NS_ENSURE_SUCCESS (rv, rv);

    nsCOMPtr<nsIXPConnect> xpc (do_GetService ("@mozilla.org/js/xpc/XPConnect;1", &rv));
    NS_ENSURE_SUCCESS (rv, rv);

    nsCOMPtr<nsIDOMElement> elem;
    rv = mWrapper->GetElementNode (getter_AddRefs (elem));
    NS_ENSURE_SUCCESS (rv, rv);

    nsCOMPtr<nsIXPConnectJSObjectHolder> jswrapper;
    rv = xpc->WrapNative (jscx, JS_GetGlobalObject (jscx), elem,
			  NS_GET_IID (nsISupports),
			  getter_AddRefs (jswrapper));
    NS_ENSURE_SUCCESS (rv, rv);

    JSObject *jsobj;
    rv = jswrapper->GetJSObject (&jsobj);
    NS_ENSURE_SUCCESS (rv, rv);

    g_message (GOM_LOC ("Got JSObject: %p"), (void *)jsobj);

    guint n_properties;
    GParamSpec **props = g_object_class_list_properties (G_OBJECT_GET_CLASS (mObject), &n_properties);
    g_message (GOM_LOC ("Adding %d properties from %s"), n_properties, G_OBJECT_TYPE_NAME (mObject));

    JS_BeginRequest (jscx);

    const char *camelName;
    for (guint i = 0; i < n_properties; i++) {
	camelName = gom_camel_case (props[i]->name);
	if (!JS_DefineProperty (jscx, jsobj, camelName, JSVAL_VOID,
				xgGObject::GetProperty,
				xgGObject::SetProperty,
				JSPROP_ENUMERATE | JSPROP_PERMANENT)) {
	    g_printerr ("Could not define a property for %s\n", camelName);
	} else {
	    g_print (GOM_LOC ("Defined property: %s.%s\n"),
		     G_OBJECT_TYPE_NAME (mObject), camelName);
	}
	GOM_CAMEL_FREE (camelName, props[i]->name);
    }

    JS_EndRequest (jscx);

    return NS_OK;
}
Пример #6
0
jsid
gjs_intern_string_to_id (JSContext  *context,
                         const char *string)
{
    JSString *str;
    jsid id;
    JS_BeginRequest(context);
    str = JS_InternString(context, string);
    id = INTERNED_STRING_TO_JSID(context, str);
    JS_EndRequest(context);
    return id;
}
Пример #7
0
AutoRoot::~AutoRoot() {
	if(count < 0)
	{
		fprintf(stderr, "AutoRoot failed: Count is still %i, but the root is being destroyed", count);
		DebugBreak();
		exit(3);
	}
	//JS_RemoveRoot(cx, &var);
	JS_BeginRequest(cx);
	JS_RemoveValueRoot(cx, &var);
	JS_EndRequest(cx);
}
Пример #8
0
CEXPORT JSBool def_animate_isPaused(JSContext *cx, unsigned argc, jsval *vp) {
	JS_BeginRequest(cx);

	JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp));
	view_animation *anim = (view_animation *)JS_GetPrivate(thiz);
	
	jsval val = BOOLEAN_TO_JSVAL(anim->is_paused);
	JS_SET_RVAL(cx, vp, val);

	JS_EndRequest(cx);
	return JS_TRUE;
}
Пример #9
0
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;
}
Пример #10
0
/* 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
}
Пример #11
0
JSBool round_js_sm_removeregistry(JSContext* cx, unsigned argc, jsval* vp)
{
  if (argc < 1)
    return JS_FALSE;

  RoundLocalNode* node = round_js_sm_getlocalnode();
  if (!node)
    return JS_FALSE;

  JS_BeginRequest(cx);

  jsval* argv = JS_ARGV(cx, vp);
  jsval param = argv[0];

#if defined(ROUND_USE_JS_JSON_PARAMS)
  char key[ROUND_SCRIPT_JS_SM_REGISTRY_KEY_MAX];
  if (!JSOBJECT_GET_GETPROPERTYSTRING(cx, param, ROUND_SYSTEM_METHOD_PARAM_KEY, key, sizeof(key)))
    return false;
#else
  char paramStr[ROUND_SCRIPT_JS_SM_REGISTRY_VALUE_MAX];
  if (!JSOBJECT_TO_CSTRING(param, paramStr, sizeof(paramStr)))
    return false;

  const char* key;
  RoundJSON* json = round_json_new();
  RoundError* err = round_error_new();
  if (json && err && round_json_parse(json, paramStr, err)) {
    RoundJSONObject* paramObj = round_json_getrootobject(json);
    if (round_json_object_ismap(paramObj)) {
      round_json_map_getstring(paramObj, ROUND_SYSTEM_METHOD_PARAM_KEY, &key);
    }
  }
#endif

  bool isSuccess = round_local_node_removeregistry(node, key);

#if !defined(ROUND_USE_JS_JSON_PARAMS)
  if (json) {
    round_json_delete(json);
  }

  if (err) {
    round_error_delete(err);
  }
#endif

  JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(isSuccess));

  JS_EndRequest(cx);

  return JS_TRUE;
}
Пример #12
0
NS_IMETHODIMP DOMEventListener::HandleEvent(nsIDOMEvent *aEvent)
{
	if(!active)
		return NS_OK;
	SetEvent(myHandle);
	if(callBack != NULL)
	{
		JS_BeginRequest(aOwner->mContext);
		JS_CallFunctionName(aOwner->mContext, JS_GetGlobalObject(aOwner->mContext), callBack, 0, NULL, NULL);
		JS_EndRequest(aOwner->mContext);
	}
	return NS_OK;
}
Пример #13
0
void def_animate_cb(void *view, void *cb, double tt, double t) {
	JSObject *js_view = (JSObject*)view;
	JSObject *js_cb = (JSObject*)cb;
	jsval args[2] = {DOUBLE_TO_JSVAL(tt),DOUBLE_TO_JSVAL(t)};
	JSContext *cx = get_js_context();

	JS_BeginRequest(cx);
	
	jsval ret;
	JS_CallFunctionValue(cx, js_view, OBJECT_TO_JSVAL(js_cb), 2, args, &ret);

	JS_EndRequest(cx);
}
Пример #14
0
void
TCP_finalize (JSContext* cx, JSObject* object)
{
    JS_BeginRequest(cx);

    TCPInformation* data = (TCPInformation*) JS_GetPrivate(cx, object);

    if (data) {
        delete data;
    }

    JS_EndRequest(cx);
}
Пример #15
0
JSBool wimg_apply_image(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
    DWORD applyFlags = 0;
    LPWSTR path = NULL;
    JS_BeginRequest(cx);
    if(!JS_ConvertArguments(cx, argc, argv, "W /u", &path, &applyFlags))
    {
        JS_ReportError(cx, "Error during argument parsing in WIMApplyImage");
        JS_EndRequest(cx);
        return JS_FALSE;
    }
    HANDLE imageHandle = JS_GetPrivate(cx, obj);
    jsrefcount rCount = JS_SuspendRequest(cx);
    *rval = WIMApplyImage(imageHandle, path, applyFlags) ? JSVAL_TRUE : JSVAL_FALSE;
    JS_ResumeRequest(cx, rCount);
    if(*rval == JSVAL_FALSE)
    {
        JS_EndRequest(cx);
        return JS_TRUE;
    }

    TCHAR volumeName[MAX_PATH + 1];
    memset(volumeName, 0, sizeof(TCHAR) * (MAX_PATH + 1));
    _tcscat_s(volumeName, MAX_PATH + 1, TEXT("\\\\.\\"));
    _tcscat_s(volumeName, (MAX_PATH + 1) - 4, path);

    if(!GetVolumePathName(volumeName, volumeName, MAX_PATH + 1))
    {
        JS_EndRequest(cx);
        *rval = JSVAL_FALSE;
        return JS_TRUE;
    }

    LPTSTR lastSlash = _tcsrchr(volumeName, _T('\\'));
    *lastSlash = '\0';

    HANDLE volumeHandle = CreateFile(volumeName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if(volumeHandle == INVALID_HANDLE_VALUE)
    {
        JS_EndRequest(cx);
        *rval = JSVAL_FALSE;
        return JS_TRUE;
    }

    rCount = JS_SuspendRequest(cx);
    if(!FlushFileBuffers(volumeHandle))
    {
        CloseHandle(volumeHandle);
        JS_ResumeRequest(cx, rCount);
        JS_EndRequest(cx);
        *rval = JSVAL_FALSE;
        return JS_TRUE;
    }
    CloseHandle(volumeHandle);
    JS_ResumeRequest(cx, rCount);
    *rval = JSVAL_TRUE;
    JS_EndRequest(cx);
    return JS_TRUE;
}
Пример #16
0
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;
}
Пример #17
0
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;
}
Пример #18
0
/* 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;
    }
}
Пример #19
0
void
gjs_closure_invoke(GClosure *closure,
                   int       argc,
                   jsval    *argv,
                   jsval    *retval)
{
    Closure *c;
    JSContext *context;

    c = (Closure*) closure;

    check_context_valid(c);

    if (c->obj == NULL) {
        /* We were destroyed; become a no-op */
        c->context = NULL;
        return;
    }

    context = gjs_runtime_get_context(c->runtime);
    JS_BeginRequest(context);

    if (JS_IsExceptionPending(context)) {
        gjs_debug_closure("Exception was pending before invoking callback??? "
                          "Not expected");
        gjs_log_exception(context, NULL);
    }

    if (!gjs_call_function_value(context,
                                 NULL, /* "this" object; NULL is some kind of default presumably */
                                 OBJECT_TO_JSVAL(c->obj),
                                 argc,
                                 argv,
                                 retval)) {
        /* Exception thrown... */
        gjs_debug_closure("Closure invocation failed (exception should "
                          "have been thrown) closure %p callable %p",
                          closure, c->obj);
        if (!gjs_log_exception(context, NULL))
            gjs_debug_closure("Closure invocation failed but no exception was set?");
        goto out;
    }

    if (gjs_log_exception(context, NULL)) {
        gjs_debug_closure("Closure invocation succeeded but an exception was set");
    }

 out:
    JS_EndRequest(context);
}
Пример #20
0
static bool
createMyObject(JSContext* context, unsigned argc, jsval *vp)
{
    JS_BeginRequest(context);

    //JS_GC(context); //<- if we make GC here, all is ok

    JSObject* myObject = JS_NewObject(context, &myClass, JS::NullPtr(), JS::NullPtr());
    *vp = OBJECT_TO_JSVAL(myObject);

    JS_EndRequest(context);

    return true;
}
Пример #21
0
JSBool win32_getlasterrormsg(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	LPWSTR buffer;
	DWORD errorCode = GetLastError();
	JS_BeginRequest(cx);
	if(argc > 0)
		JS_ValueToECMAUint32(cx, argv[0], (uint32*)&errorCode);
	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&buffer, 0, NULL);
	JSString * retStr = JS_NewUCStringCopyZ(cx, (jschar*)buffer);
	JS_EndRequest(cx);
	LocalFree(buffer);
	*rval = STRING_TO_JSVAL(retStr);
	return JS_TRUE;
}
Пример #22
0
JSBool
Window_printString (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
    if (argc < 1) {
        JS_ReportError(cx, "Not enough parameters.");
        return JS_FALSE;
    }

    WINDOW* win = (WINDOW*) JS_GetPrivate(cx, object);

    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    if (argc == 1){
        wprintw(win, JS_GetStringBytes(JS_ValueToString(cx, argv[0])));
    }
    else if (argc == 2) {
        JSObject* options; JS_ValueToObject(cx, argv[1], &options);

        jsval x, y;

        JS_GetProperty(cx, options, "x", &x);
        if (JSVAL_IS_VOID(x) || JSVAL_IS_NULL(x)) {
            JS_GetProperty(cx, options, "X", &x);
        }

        JS_GetProperty(cx, options, "y", &y);
        if (JSVAL_IS_VOID(y) || JSVAL_IS_NULL(y)) {
            JS_GetProperty(cx, options, "Y", &y);
        }

        __Window_options(cx, win, options, JS_TRUE);
        if (!JSVAL_IS_INT(x) && !JSVAL_IS_INT(y)) {
            wprintw(win, JS_GetStringBytes(JS_ValueToString(cx, argv[0])));
        }
        else {
            mvwprintw(win,
                JSVAL_IS_INT(y) ? JSVAL_TO_INT(y) : 0,
                JSVAL_IS_INT(x) ? JSVAL_TO_INT(x) : 0,
                JS_GetStringBytes(JS_ValueToString(cx, argv[0]))
            );
        }
        __Window_options(cx, win, options, JS_FALSE);
    }

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);

    return JS_TRUE;
}
Пример #23
0
NS_IMETHODIMP WebBrowserChrome::OnLocationChange(nsIWebProgress * /*aWebProgress*/,
                                                 nsIRequest * /*aRequest*/,
                                                 nsIURI *aLocation)
{
    NS_ENSURE_ARG_POINTER(aLocation);
    nsCString spec;
    aLocation->GetSpec(spec);
	JS_BeginRequest(cx);
	JSString * newLocation = JS_NewString(cx, (char*)spec.get(), spec.Length());
	jsval newLocationVal = STRING_TO_JSVAL(newLocation);
	JS_SetProperty(cx, mPrivate->obj, "location", &newLocationVal);
	JS_EndRequest(cx);
    return NS_OK;
}
Пример #24
0
JSBool replaceChild(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	JSObject * newChildObj, *refChildObj;
	nsCOMPtr<nsIDOMNode> newChild, refChild, mNode, outNode;

	JS_BeginRequest(cx);
	if(!JS_ConvertArguments(cx, argc, argv, "o o", &newChildObj, &refChildObj))
	{
		JS_ReportError(cx, "Error converting arguments in replaceChild");
		JS_EndRequest(cx);
		return JS_FALSE;
	}
	
	if(!JS_InstanceOf(cx, newChildObj, &lDOMNodeClass, NULL) || !JS_InstanceOf(cx, refChildObj, &lDOMNodeClass, NULL))
	{
		JS_ReportWarning(cx, "Arguments to replaceChild must both be DOMNode objects.");
		JS_EndRequest(cx);
		return JS_TRUE;
	}
	newChild = (nsIDOMNode*)JS_GetPrivate(cx, newChildObj);
	refChild = (nsIDOMNode*)JS_GetPrivate(cx, refChildObj);
	mNode = (nsIDOMNode*)JS_GetPrivate(cx, obj);
	
	EnterCriticalSection(&domStateLock);
	domState = 1;
	if(mNode->ReplaceChild(newChild, refChild, getter_AddRefs(outNode)) == NS_OK)
	{
		JSObject * retObj = JS_NewObject(cx, &lDOMNodeClass, lDOMNodeProto, obj);
		*rval = OBJECT_TO_JSVAL(retObj);
		JS_SetPrivate(cx, retObj, outNode);
	}
	else
		*rval = JSVAL_FALSE;
	LeaveCriticalSection(&domStateLock);
	JS_EndRequest(cx);
	return JS_TRUE;
}
Пример #25
0
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;
        proto = JS_GetPrototype(obj);
        if(!proto)
            return NULL;
        JS_BeginRequest(jsdc->dumbContext);
        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
        if(!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;
}
Пример #26
0
JSBool wimg_load_image(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
    DWORD imageIndex;
    JS_BeginRequest(cx);
    if(!JS_ConvertArguments(cx, argc, argv, "u", &imageIndex))
    {
        JS_ReportError(cx, "Error during argument parsing in WIMLoadImage");
        JS_EndRequest(cx);
        return JS_FALSE;
    }
    JS_YieldRequest(cx);
    HANDLE hImage = WIMLoadImage(JS_GetPrivate(cx, obj), imageIndex);
    if(hImage == NULL)
    {
        *rval = JSVAL_FALSE;
        JS_EndRequest(cx);
        return JS_TRUE;
    }
    JSObject * retObj = JS_NewObject(cx, &wimImageClass, wimImageProto, obj);
    *rval = OBJECT_TO_JSVAL(retObj);
    JS_SetPrivate(cx, retObj, hImage);
    JS_EndRequest(cx);
    return JS_TRUE;
}
Пример #27
0
JSBool
gjs_call_function_value(JSContext      *context,
                        JSObject       *obj,
                        jsval           fval,
                        uintN           argc,
                        jsval          *argv,
                        jsval          *rval)
{
    JSBool result;
    JSContext *call_context;

    JS_BeginRequest(context);

    call_context = gjs_runtime_get_call_context(JS_GetRuntime(context));
    JS_BeginRequest(call_context);

    result = JS_CallFunctionValue(call_context, obj, fval,
                                  argc, argv, rval);
    gjs_move_exception(call_context, context);

    JS_EndRequest(call_context);
    JS_EndRequest(context);
    return result;
}
Пример #28
0
const char*
jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval)
{
    jsval val = jsdval->val;
    JSCrossCompartmentCall *call = NULL;

    if(!jsdval->className && JSVAL_IS_OBJECT(val))
    {
        JSObject* obj;
        if(!(obj = JSVAL_TO_OBJECT(val)))
            return NULL;
        JS_BeginRequest(jsdc->dumbContext);
        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
        if(!call) {
            JS_EndRequest(jsdc->dumbContext);

            return NULL;
        }
        jsdval->className = JS_GetClass(obj)->name;
        JS_LeaveCrossCompartmentCall(call);
        JS_EndRequest(jsdc->dumbContext);
    }
    return jsdval->className;
}
Пример #29
0
bool
gjs_string_from_utf8(JSContext             *context,
                     const char            *utf8_string,
                     JS::MutableHandleValue value_p)
{
    JS_BeginRequest(context);

    JS::ConstUTF8CharsZ chars(utf8_string, strlen(utf8_string));
    JS::RootedString str(context, JS_NewStringCopyUTF8Z(context, chars));
    if (str)
        value_p.setString(str);

    JS_EndRequest(context);
    return str != nullptr;
}
Пример #30
0
CEXPORT JSBool def_animate_wait(JSContext *cx, unsigned argc, jsval *vp) {
	JS_BeginRequest(cx);

	jsval *vals = JS_ARGV(cx, vp);
	JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp));
	view_animation *anim = (view_animation *)JS_GetPrivate(thiz);
	double dt;
	JS_ValueToNumber(cx, *vals, &dt);
	view_animation_wait(anim, dt);
	jsval thiz_val = OBJECT_TO_JSVAL(thiz);
	JS_SET_RVAL(cx, vp, thiz_val);

	JS_EndRequest(cx);
	return JS_TRUE;
}