void JSArmatureWrapper::addArmatureFileInfoAsyncCallbackFunc(float percent)
{
    JSContext *cx = ScriptingCore::getInstance()->getGlobalContext();
    JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj);
    jsval retval;
    if (_jsCallback != JSVAL_VOID)
    {
        jsval percentVal = DOUBLE_TO_JSVAL(percent);

        JS_AddValueRoot(cx, &percentVal);
        
        JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
        
        JS_CallFunctionValue(cx, thisObj, _jsCallback, 1, &percentVal, &retval);
        JS_RemoveValueRoot(cx, &percentVal);
    }
}
/**
 * Get a field of an object as an object.
 *
 * If the field does not exist, create it. If it exists but is not an
 * object, throw a JS error.
 */
JSObject *GetOrCreateObjectProperty(JSContext *cx, JSObject *aObject,
                                    const char *aProperty)
{
  jsval val;
  if (JS_GetProperty(cx, aObject, aProperty, &val)
      && !JSVAL_IS_VOID(val)) {
    if (JSVAL_IS_OBJECT(val)) {
      return JSVAL_TO_OBJECT(val);
    }
    else {
      JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
         JSMSG_UNEXPECTED_TYPE, aProperty, "not an object");
      return NULL;
    }
  }
  return JS_DefineObject(cx, aObject, aProperty, NULL, NULL, JSPROP_ENUMERATE);
}
Exemplo n.º 3
0
void CConsole::ProcessBuffer(const wchar_t* szLine)
{
	if (szLine == NULL) return;
	if (wcslen(szLine) <= 0) return;

	ENSURE(wcslen(szLine) < CONSOLE_BUFFER_SIZE);

	m_deqBufHistory.push_front(szLine);
	SaveHistory(); // Do this each line for the moment; if a script causes
	               // a crash it's a useful record.

	// Process it as JavaScript

	jsval rval = g_ScriptingHost.ExecuteScript(szLine, L"Console");
	if (!JSVAL_IS_VOID(rval))
		InsertMessage(L"%ls", g_ScriptingHost.GetScriptInterface().ToString(rval).c_str());
}
Exemplo n.º 4
0
SV* PJS_GetPassport(
    pTHX_
    JSContext *cx,
    JSObject *thing
) {
    jsval temp;
    SV *box;
    SV *tref;
    JSObject *inboxed;
    if(!JS_LookupPropertyWithFlags(cx, thing, PJS_PASSPORT_PROP, 0, &temp)
       || JSVAL_IS_VOID(temp) || JSVAL_IS_NULL(temp))
	croak("Can't get passport");
    box = (SV *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(temp));
    tref = *av_fetch((AV *)SvRV(box), 0, 0);
    inboxed = INT2PTR(JSObject *, SvIV((SV *)SvRV(tref)));
    assert(inboxed == thing);
    return box;
}
Exemplo n.º 5
0
static JSBool
propertyOp(const char *name, JSContext *cx, JSObject *obj, jsval id,
           jsval *vp)
{
  if (resolverHasMethod(cx, obj, name)) {
    jsval rval;
    jsval args[2];
    args[0] = id;
    args[1] = *vp;
    if (!delegateToResolver(cx, obj, name, 2, args, &rval))
      return JS_FALSE;

    if (!JSVAL_IS_VOID(rval))
      *vp = rval;
    return JS_TRUE;
  }
  return JS_PropertyStub(cx, obj, id, vp);
}
Exemplo n.º 6
0
// static
nsresult
IDBKeyRange::FromJSVal(JSContext* aCx,
                       const jsval& aVal,
                       IDBKeyRange** aKeyRange)
{
  nsresult rv;
  nsRefPtr<IDBKeyRange> keyRange;

  if (JSVAL_IS_VOID(aVal) || JSVAL_IS_NULL(aVal)) {
    // undefined and null returns no IDBKeyRange.
  }
  else if (JSVAL_IS_PRIMITIVE(aVal) ||
           JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(aVal)) ||
           JS_ObjectIsDate(aCx, JSVAL_TO_OBJECT(aVal))) {
    // A valid key returns an 'only' IDBKeyRange.
    keyRange = new IDBKeyRange(false, false, true);

    rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower());
    if (NS_FAILED(rv)) {
      return rv;
    }
  }
  else {
    // An object is not permitted unless it's another IDBKeyRange.
    nsIXPConnect* xpc = nsContentUtils::XPConnect();
    NS_ASSERTION(xpc, "This should never be null!");

    nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
    rv = xpc->GetWrappedNativeOfJSObject(aCx, JSVAL_TO_OBJECT(aVal),
                                         getter_AddRefs(wrapper));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);

    nsCOMPtr<nsIIDBKeyRange> iface;
    if (!wrapper || !(iface = do_QueryInterface(wrapper->Native()))) {
      // Some random JS object?
      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
    }

    keyRange = static_cast<IDBKeyRange*>(iface.get());
  }

  keyRange.forget(aKeyRange);
  return NS_OK;
}
Exemplo n.º 7
0
NS_IMETHODIMP
LockedFile::GetMetadata(const jsval& aParameters,
                        JSContext* aCx,
                        nsIDOMFileRequest** _retval)
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

  if (!IsOpen()) {
    return NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR;
  }

  // Do nothing if the window is closed
  if (!GetOwner()) {
    return NS_OK;
  }

  nsRefPtr<MetadataParameters> params = new MetadataParameters();

  // Get optional arguments.
  if (!JSVAL_IS_VOID(aParameters) && !JSVAL_IS_NULL(aParameters)) {
    nsresult rv = params->Init(aCx, &aParameters);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);

    if (!params->IsConfigured()) {
      return NS_ERROR_TYPE_ERR;
    }
  }
  else {
    params->Init(true, true);
  }

  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
  NS_ENSURE_TRUE(fileRequest, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);

  nsRefPtr<MetadataHelper> helper =
    new MetadataHelper(this, fileRequest, params);

  nsresult rv = helper->Enqueue();
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);

  fileRequest.forget(_retval);
  return NS_OK;
}
Exemplo n.º 8
0
void
IDBRequest::NotifyHelperSentResultsToChildProcess(nsresult aRv)
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
  NS_ASSERTION(!mHaveResultOrErrorCode, "Already called!");
  NS_ASSERTION(JSVAL_IS_VOID(mResultVal), "Should be undefined!");

  // See if our window is still valid. If not then we're going to pretend that
  // we never completed.
  if (NS_FAILED(CheckInnerWindowCorrectness())) {
    return;
  }

  mHaveResultOrErrorCode = true;

  if (NS_FAILED(aRv)) {
    SetError(aRv);
  }
}
Exemplo n.º 9
0
void
js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value)
{
  JSBool b;
  if(JSVAL_IS_INT(value)) {
    prop_set_int(p, JSVAL_TO_INT(value));
  } else if(JSVAL_IS_BOOLEAN(value)) {
    prop_set_int(p, JSVAL_TO_BOOLEAN(value));
  } else if(JSVAL_IS_NULL(value) || JSVAL_IS_VOID(value)) {
    prop_set_void(p);
  } else if(JSVAL_IS_DOUBLE(value)) {
    double d;
    if(JS_ValueToNumber(cx, value, &d))
      prop_set_float(p, d);
  } else if(JS_HasInstance(cx, RichText, value, &b) && b) {
    JSObject *o = JSVAL_TO_OBJECT(value);
    jsval v2;

    if(!JS_EnterLocalRootScope(cx))
      return;

    if(!JS_GetProperty(cx, o, "text", &v2)) {
      JS_LeaveLocalRootScope(cx);
      return;
    }

    prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)),
		       PROP_STR_RICH);
    JS_LeaveLocalRootScope(cx);
  } else if(JSVAL_IS_STRING(value)) {
    js_prop_from_str(cx, p, value);
  } else if(JSVAL_IS_OBJECT(value)) {
    JSObject *obj = JSVAL_TO_OBJECT(value);
    JSClass *c = JS_GetClass(cx, obj);

    if(!strcmp(c->name, "XML"))   // Treat some classes special
      js_prop_from_str(cx, p, value);
    else
      js_prop_from_object(cx, obj, p);
  } else {
    prop_set_void(p);
  }
}
Exemplo n.º 10
0
GF_EXPORT
GF_Err gf_webvtt_js_addCue(GF_Node *node, const char *id,
                           const char *start, const char *end,
                           const char *settings,
                           const char *payload)
{
	GF_Err e;
	JSBool found;
	JSContext *c = node->sgprivate->scenegraph->svg_js->js_ctx;
	JSObject *global = node->sgprivate->scenegraph->svg_js->global;
	jsval fun_val;

	gf_sg_lock_javascript(c, GF_TRUE);
	found = JS_LookupProperty(c, global, "addCue", &fun_val);
	if (!found || JSVAL_IS_VOID(fun_val) || !JSVAL_IS_OBJECT(fun_val) ) {
		e = GF_BAD_PARAM;
	} else {
		JSBool ret;
		uintN attr;
		ret = JS_GetPropertyAttributes(c, global, "addCue", &attr, &found);
		if (ret == JS_TRUE && found == JS_TRUE) {
			jsval rval;
			jsval argv[5];
			argv[0] = STRING_TO_JSVAL( JS_NewStringCopyZ(c, (id ? id : "")) );
			argv[1] = STRING_TO_JSVAL( JS_NewStringCopyZ(c, (start ? start : "")) );
			argv[2] = STRING_TO_JSVAL( JS_NewStringCopyZ(c, (end ? end : "")) );
			argv[3] = STRING_TO_JSVAL( JS_NewStringCopyZ(c, (settings ? settings : "")) );
			argv[4] = STRING_TO_JSVAL( JS_NewStringCopyZ(c, (payload ? payload : "")) );

			ret = JS_CallFunctionValue(c, global, fun_val, 5, argv, &rval);
			//ret = JS_CallFunctionName(c, global, "addCue", 5, argv, &rval);
			if (ret == JS_TRUE) {
				e = GF_OK;
			} else {
				e = GF_BAD_PARAM;
			}
		} else {
			e = GF_BAD_PARAM;
		}
	}
	gf_sg_lock_javascript(c, GF_FALSE);
	return e;
}
Exemplo n.º 11
0
int
js_prop_from_object(JSContext *cx, JSObject *obj, prop_t *p)
{
  JSIdArray *ida;
  int i, r = 0;
  const char *n;
  int array_zapped = 0;

  if((ida = JS_Enumerate(cx, obj)) == NULL)
    return -1;
  
  for(i = 0; i < ida->length; i++) {
    jsval name, value;

    if(!JS_IdToValue(cx, ida->vector[i], &name))
      continue;

    if(JSVAL_IS_STRING(name)) {
      n = JS_GetStringBytes(JSVAL_TO_STRING(name));
      if(!JS_GetProperty(cx, obj, n, &value))
	continue;
    } else if(JSVAL_IS_INT(name)) {
      if(!JS_GetElement(cx, obj, JSVAL_TO_INT(name), &value) ||
	 JSVAL_IS_VOID(value))
	continue;
      if(!array_zapped) {
	array_zapped = 1;
	prop_destroy_by_name(p, NULL);
      }
      n = NULL;
    } else {
      continue;
    }

    if(JSVAL_TO_OBJECT(value) == obj)
      continue;

    js_prop_set_from_jsval(cx, prop_create(p, n), value);
  }
  JS_DestroyIdArray(cx, ida);
  return r;
}
Exemplo n.º 12
0
void CancelLoad(const CStrW& message)
{
	// Cancel loader
	LDR_Cancel();

	// Call the cancelOnError GUI function, defined in ..gui/common/functions_utility_error.js
	// So all GUI pages that load games should include this script
	if (g_GUI && g_GUI->HasPages())
	{
		JSContext* cx = g_ScriptingHost.getContext();
		jsval fval, rval;
		JSBool ok = JS_GetProperty(cx, g_GUI->GetScriptObject(), "cancelOnError", &fval);
		ENSURE(ok);

		jsval msgval = ToJSVal(message);

		if (ok && !JSVAL_IS_VOID(fval))
			JS_CallFunctionValue(cx, g_GUI->GetScriptObject(), fval, 1, &msgval, &rval);
	}
}
Exemplo n.º 13
0
static void
ValueToString(JSContext *cx, jsval aJSValue, nsString& aString)
{
	if (JSVAL_IS_VOID(aJSValue)) {
		aString.Assign(kUndefined, STRLEN_ARRAY(kUndefined));
	} else if (JSVAL_IS_NULL(aJSValue)) {
		aString.Assign(kNull, STRLEN_ARRAY(kNull));
	} else if (JSVAL_IS_INT(aJSValue)) {
		jsint i = JSVAL_TO_INT(aJSValue);
		char buf[20];
		PR_snprintf(buf, sizeof(buf), "%d", i);
		aString.Assign(NS_ConvertASCIItoUTF16(buf));
	} else if (JSVAL_IS_DOUBLE(aJSValue)) {
		jsdouble d = JSVAL_TO_DOUBLE(aJSValue);
		char buf[50];
		PR_snprintf(buf, sizeof(buf), "%f", d);
		aString.Assign(NS_ConvertASCIItoUTF16(buf));
	} else if (JSVAL_IS_BOOLEAN(aJSValue)) {
		JSBool b = JSVAL_TO_BOOLEAN(aJSValue);
		if (b)
			aString.Assign(kTrue, STRLEN_ARRAY(kTrue));
		else
			aString.Assign(kFalse, STRLEN_ARRAY(kFalse));
	} else if (JSVAL_IS_STRING(aJSValue)) {
		JSString *str = JSVAL_TO_STRING(aJSValue);
		size_t len;
		const jschar *chars = JS_GetStringCharsAndLength(cx, str, &len);
		NS_ASSERTION(chars, "out of memory");
		if (chars) {
			NS_ASSERTION(sizeof(jschar) == sizeof(PRUnichar),
						 "char size mismatch");
			aString.Assign(reinterpret_cast<const PRUnichar*>(chars), len);
		}
	} else {
		JSObject *obj = JSVAL_TO_OBJECT(aJSValue);
		JSClass *clazz = JS_GetClass(cx, obj);
		aString.Assign(PRUnichar('['));
		aString.Append(NS_ConvertASCIItoUTF16(clazz->name));
		aString.Append(PRUnichar(']'));
	}
}
Exemplo n.º 14
0
JSBool
js_AtomizePrimitiveValue(JSContext *cx, jsval v, JSAtom **atomp)
{
    JSAtom *atom;

    if (JSVAL_IS_STRING(v)) {
        atom = js_AtomizeString(cx, JSVAL_TO_STRING(v), 0);
        if (!atom)
            return JS_FALSE;
    } else if (JSVAL_IS_DOUBLE(v)) {
        atom = js_AtomizeDouble(cx, *JSVAL_TO_DOUBLE(v));
        if (!atom)
            return JS_FALSE;
    } else {
        JS_ASSERT(JSVAL_IS_INT(v) || JSVAL_IS_BOOLEAN(v) ||
                  JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v));
        atom = (JSAtom *)v;
    }
    *atomp = atom;
    return JS_TRUE;
}
Exemplo n.º 15
0
JSBool
Library::Open(JSContext* cx, uintN argc, jsval *vp)
{
  JSObject* ctypesObj = JS_THIS_OBJECT(cx, vp);
  if (!ctypesObj || !IsCTypesGlobal(cx, ctypesObj)) {
    JS_ReportError(cx, "not a ctypes object");
    return JS_FALSE;
  }

  if (argc != 1 || JSVAL_IS_VOID(JS_ARGV(cx, vp)[0])) {
    JS_ReportError(cx, "open requires a single argument");
    return JS_FALSE;
  }

  JSObject* library = Create(cx, JS_ARGV(cx, vp)[0], GetCallbacks(cx, ctypesObj));
  if (!library)
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(library));
  return JS_TRUE;
}
Exemplo n.º 16
0
int
spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
			   struct string *code)
{
	JSContext *ctx;
	JSFunction *fun;
	jsval rval;
	int ret;

	assert(interpreter);
	if (!js_module_init_ok) return 0;
	ctx = interpreter->backend_data;
	interpreter->ret = NULL;
	fun = JS_CompileFunction(ctx, NULL, "", 0, NULL, code->source,
				 code->length, "", 0);
	if (!fun)
		return -1;

#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
	interpreter->heartbeat = add_heartbeat(interpreter);
#elif defined(HAVE_JS_SETBRANCHCALLBACK)
	setup_safeguard(interpreter, ctx);
#endif
	ret = JS_CallFunction(ctx, NULL, fun, 0, NULL, &rval);
#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
	done_heartbeat(interpreter->heartbeat);
#endif
	if (ret == 2) { /* onClick="history.back()" */
		return 0;
	}
	if (ret == JS_FALSE) {
		return -1;
	}
	if (JSVAL_IS_VOID(rval)) {
		/* Undefined value. */
		return -1;
	}

	return jsval_to_boolean(ctx, &rval);
}
js::ValueRef wrap(JSContext *cx, jsval val) {

    if ( JSVAL_IS_BOOLEAN(val)) {
        return JSVAL_TO_BOOLEAN(val) ? true : false;
    }
    if ( JSVAL_IS_NULL(val)){
     fprintf(stderr, "is null\n");
     }
    if ( JSVAL_IS_VOID(val)){
     fprintf(stderr, "is void\n");
     }
    if ( JSVAL_IS_INT (val)){
     fprintf(stderr, "is int\n");
     }
    if ( JSVAL_IS_STRING(val)) {
        JSString *str = JSVAL_TO_STRING(val);
        //todo: memory leak is my middle name
        js::String *jsstr = new js::String((std::string)JS_EncodeString(cx, str));

        return *jsstr;
    }
    if ( !JSVAL_IS_PRIMITIVE(val)) {
        JSObject* obj=JSVAL_TO_OBJECT(val);
        if (JS_IsArrayObject(cx, obj)){
            std::vector<js::ValueRef> els;
            jsuint length;
            JS_GetArrayLength(cx, obj, &length);
            for (int i = 0; i < length; i++){
                jsval ret;
                JS_GetElement(cx, obj, i, &ret);
                els.push_back(wrap(cx, ret));
            }
            // leaking memory
            js::Array *array=new js::Array(els);
            return (*array);
        }
    }
    return (std::string)"<unknown type>";
}
Exemplo n.º 18
0
JSErrorReport *
js_ErrorFromException(JSContext *cx, jsval exn)
{
    JSObject *obj;
    JSExnPrivate *privateData;
    jsval privateValue;

    if (JSVAL_IS_PRIMITIVE(exn))
        return NULL;
    obj = JSVAL_TO_OBJECT(exn);
    if (OBJ_GET_CLASS(cx, obj) != &ExceptionClass)
        return NULL;
    privateValue = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
    if (JSVAL_IS_VOID(privateValue))
        return NULL;
    privateData = (JSExnPrivate*) JSVAL_TO_PRIVATE(privateValue);
    if (!privateData)
        return NULL;

    JS_ASSERT(privateData->errorReport);
    return privateData->errorReport;
}
Exemplo n.º 19
0
static void
vfw_setval(void *opaque, prop_event_t event, ...)
{
  wfv_t *wfv = opaque;
  va_list ap;
  rstr_t *r;
  const char *s;
  va_start(ap, event);

  switch(event) {
  case PROP_SET_VOID:
    if(JSVAL_IS_NULL(wfv->value) || JSVAL_IS_VOID(wfv->value))
      break;
    return;

  case PROP_SET_RSTRING:
    if(!JSVAL_IS_STRING(wfv->value))
      return;

    r = va_arg(ap, rstr_t *);
    if(strcmp(JS_GetStringBytes(JSVAL_TO_STRING(wfv->value)), rstr_get(r)))
      return;
    break;

  case PROP_SET_CSTRING:
    if(!JSVAL_IS_STRING(wfv->value))
      return;

    s = va_arg(ap, const char *);
    if(strcmp(JS_GetStringBytes(JSVAL_TO_STRING(wfv->value)), s))
      return;
    break;

  default:
    return;
  }
  wfv->done = 1;
}
Exemplo n.º 20
0
VARTYPE XPCDispConvert::JSTypeToCOMType(XPCCallContext& ccx, jsval val)
{
    if(JSVAL_IS_PRIMITIVE(val))
    {
        if(JSVAL_IS_STRING(val))
        {
            return VT_BSTR;
        }
        if(JSVAL_IS_INT(val))
        {
            return VT_I4;
        }
        if(JSVAL_IS_DOUBLE(val))
        {
            return VT_R8;
        }
        if(JSVAL_IS_BOOLEAN(val))
        {
            return VT_BOOL;
        }
        if(JSVAL_IS_VOID(val))
        {
            return VT_EMPTY;
        }
        if(JSVAL_IS_NULL(val))
        {
            return VT_NULL;
        }
    }
    else
    {
        if(JS_IsArrayObject(ccx, JSVAL_TO_OBJECT(val)))
            return VT_ARRAY | VT_VARIANT;
        return VT_DISPATCH;
    }
    NS_ERROR("XPCDispConvert::JSTypeToCOMType was unable to identify the type of the jsval");
    return VT_EMPTY;
}
Exemplo n.º 21
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 (!JSVAL_IS_VOID(value)) {
        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;
    }
}
Exemplo n.º 22
0
xpc_qsAString::xpc_qsAString(JSContext *cx, jsval *pval)
{
    // From the T_ASTRING case in XPCConvert::JSData2Native.
    typedef implementation_type::char_traits traits;
    jsval v;
    JSString *s;
    const PRUnichar *chars;
    size_t len;

    v = *pval;
    if(JSVAL_IS_STRING(v))
    {
        s = JSVAL_TO_STRING(v);
    }
    else
    {
        if(JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
        {
            (new(mBuf) implementation_type(
                traits::sEmptyBuffer, PRUint32(0)))->SetIsVoid(PR_TRUE);
            mValid = JS_TRUE;
            return;
        }

        s = JS_ValueToString(cx, v);
        if(!s)
        {
            mValid = JS_FALSE;
            return;
        }
        *pval = STRING_TO_JSVAL(s);  // Root the new string.
    }

    len = JS_GetStringLength(s);
    chars = (len == 0 ? traits::sEmptyBuffer : (const PRUnichar*)JS_GetStringChars(s));
    new(mBuf) implementation_type(chars, len);
    mValid = JS_TRUE;
}
Exemplo n.º 23
0
void SG_jscore__check_module_dags(SG_context *pCtx, JSContext *cx, JSObject *glob, const char *reponame)
{
	jsval args[2];
	JSBool js_ok;
	jsval rval;
	JSString *pjs;
	jsval fo = JSVAL_VOID;

	if (gpJSCoreGlobalState->bSkipModules || (! gpJSCoreGlobalState->pPathToModules))
		return;

	SG_ERR_CHECK(  _sg_jscore__install_modules(pCtx, cx, glob, NULL)  );

	SG_JS_NULL_CHECK(  (pjs = JS_NewStringCopyZ(cx, reponame))  );

	args[0] = STRING_TO_JSVAL(pjs);

	SG_JS_NULL_CHECK(  (pjs = JS_NewStringCopyZ(cx, SG_pathname__sz(gpJSCoreGlobalState->pPathToModules)))  );

	args[1] = STRING_TO_JSVAL(pjs);

	if (! JS_LookupProperty(cx, glob, "checkModuleDags", &fo))
	{
		SG_ERR_CHECK_CURRENT;
		SG_ERR_THROW2(SG_ERR_JS, (pCtx, "lookup of checkModuleDags failed"));
	}

	if (!JSVAL_IS_VOID(fo))
	{
		js_ok = JS_CallFunctionName(cx, glob, "checkModuleDags", SG_NrElements(args), args, &rval);
		SG_ERR_CHECK_CURRENT;
		if(!js_ok)
			SG_ERR_THROW2(SG_ERR_JS, (pCtx, "An error occurred initializing modules: call to JavaScript checkModuleDags() failed"));
	}

 fail:
	;
}
Exemplo n.º 24
0
/* Checks whether an object has a property; unlike JS_GetProperty(),
 * never sets an exception. Treats a property with a value of JSVAL_VOID
 * the same as an absent property and returns false in both cases.
 * Always initializes *value_p, if only to JSVAL_VOID, even if it
 * returns FALSE.
 */
gboolean
gjs_object_get_property(JSContext  *context,
                        JSObject   *obj,
                        const char *property_name,
                        jsval      *value_p)
{
    jsval value;
    JSExceptionState *state;

    JS_BeginRequest(context);

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

    if (value_p)
        *value_p = value;

    JS_EndRequest(context);

    return !JSVAL_IS_VOID(value);
}
Exemplo n.º 25
0
SV *
PrimJSVALToSV(
    pTHX_
    JSContext *cx,
    jsval v
) {
    SV *sv = NULL;
    if(JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
	sv = newSV(0);
    else if(JSVAL_IS_BOOLEAN(v)) {
	sv = newSV(0);
	sv_setref_iv(sv, PJS_BOOLEAN, (IV)JSVAL_TO_BOOLEAN(v));
    }
    else if(JSVAL_IS_INT(v)) 
	sv = newSViv((IV)JSVAL_TO_INT(v));
    else if(JSVAL_IS_DOUBLE(v))
	sv = newSVnv(*JSVAL_TO_DOUBLE(v));
    else if(JSVAL_IS_STRING(v)) 
	sv = PJS_JSString2SV(aTHX_ JSVAL_TO_STRING(v));
    else croak("PJS_Assert: Unknown primitive type");
    
    return sv;
}
ScriptValuePtr TraceMonkeyEngine::runScript(std::string script)
{
//    printf("Running script: \r\n%s\r\n", script.c_str());

    jsval ret;
    JS_EvaluateScript(context, global, script.c_str(), script.length(), "TraceMonkeyEngine", 0, &ret);
    bool success = JS_AddNamedRoot(context, &ret, "TraceMonkeyEngine::runScript temp val");; // Ensure our value won't be GCed
    assert(success);

//    printf("Script completed\r\n");

    printJSVAL(ret);

    ScriptValuePtr retValue;

    if ( !JSVAL_IS_VOID(ret) )
        retValue = ScriptValuePtr( new TraceMonkeyValue(this, true, ret) );

    success = JS_RemoveRoot(context, &ret);
    assert(success);

    return retValue;
}
Exemplo n.º 27
0
static JSBool
OnUpdateSettings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
    try {
        WMTouchPlugin* myPlugin = GetInstance();

        if (argc != 1) {
            JS_ReportError(cx, "WMTouchPlugin::onUpdateSettings(): Wrong number of arguments. One (ConfigNode) expected");
            return JS_FALSE;
        }

        dom::NodePtr myConfigNode;
        if (JSVAL_IS_VOID(argv[0]) || !jslib::convertFrom(cx, argv[0], myConfigNode)) {
            JS_ReportError(cx, "WMTouchPlugin::onUpdateSettings(): Argument #1 must be a node");
            return JS_FALSE;
        }

        myPlugin->onUpdateSettings(myConfigNode);

        return JS_TRUE;
    } HANDLE_CPP_EXCEPTION;

    return JS_TRUE;
}
Exemplo n.º 28
0
//---------------------------------------------------------------------------
void JS_TO_CONCEPT(void *member, jsval rval) {
    INVOKE_CALL            InvokePtr   = 0;
    CALL_BACK_VARIABLE_SET SetVariable = _SetVariable;
    void *HANDLER = CONCEPT_HANDLER;

    if (JSVAL_IS_DOUBLE(rval)) {
        SET_NUMBER_VARIABLE(member, *JSVAL_TO_DOUBLE(rval));
    } else
    if (JSVAL_IS_INT(rval)) {
        SET_NUMBER_VARIABLE(member, JSVAL_TO_INT(rval));
    } else
    if (JSVAL_IS_STRING(rval)) {
        struct JSString *str = JSVAL_TO_STRING(rval);
        SET_BUFFER_VARIABLE(member, JS_GetStringBytes(str), str->length);
    } else
    if (JSVAL_IS_BOOLEAN(rval)) {
        SET_NUMBER_VARIABLE(member, (NUMBER)JSVAL_TO_BOOLEAN(rval));
    } else
    if ((JSVAL_IS_NULL(rval)) || (JSVAL_IS_VOID(rval))) {
        SET_NUMBER_VARIABLE(member, 0);
    } else
        SET_NUMBER_VARIABLE(member, 1);
}
Exemplo n.º 29
0
static JSBool xgg_label_propop_innertext_set(JSContext *pcxa, JSObject *pobja, jsval id, jsval *vp)
{
	XGG_LABEL_PRIV*	pv0 = JS_GetPrivate(pcxa, pobja);
	//XJSEXADGELEM*	pe0 = pv0->hdr.pxadgelem;
	//XJSECTX*		pjsectx = (XJSECTX*)JS_GetContextPrivate(pcxa);

	if(JSVAL_IS_VOID(vp[0])) {
		XJSE_TRACE("(X) assigning non-text to innerText prop. (%d)",
			JS_TypeOfValue(pcxa, vp[0]));
		goto	cleanup;
	}

	char		*psz1 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
	//XJSE_TRACE("(X) label.innerText: [%s]", psz1);
	xjse_int_t	n0 = xjse_strlen(0, psz1);
	XJSE_SAFENNP(pv0->pszinnertext, free);
	pv0->pszinnertext = (char*)malloc(n0 + 1);
	memcpy(pv0->pszinnertext, psz1, n0);
	pv0->pszinnertext[n0] = 0;

cleanup:
	return	JS_TRUE;
}
Exemplo n.º 30
0
void
js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value, int recurse)
{
  JSBool b;
  if(JSVAL_IS_INT(value)) {
    prop_set_int(p, JSVAL_TO_INT(value));
  } else if(JSVAL_IS_BOOLEAN(value)) {
    prop_set_int(p, JSVAL_TO_BOOLEAN(value));
  } else if(JSVAL_IS_DOUBLE(value)) {
    double d;
    if(JS_ValueToNumber(cx, value, &d))
      prop_set_float(p, d);
  } else if(JS_HasInstance(cx, RichText, value, &b) && b) {
    JSObject *o = JSVAL_TO_OBJECT(value);
    jsval v2;

    if(!JS_EnterLocalRootScope(cx))
      return;

    if(!JS_GetProperty(cx, o, "text", &v2)) {
      JS_LeaveLocalRootScope(cx);
      return;
    }

    prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)),
		       PROP_STR_RICH);
    JS_LeaveLocalRootScope(cx);

  } else if(JSVAL_IS_VOID(value) || JSVAL_IS_NULL(value)) {
    prop_set_void(p);
  } else if(recurse && JSVAL_IS_OBJECT(value)) {
    js_prop_from_object(cx, JSVAL_TO_OBJECT(value), p, recurse);
  } else {
    prop_set_string(p, JS_GetStringBytes(JS_ValueToString(cx, value)));
  }
}