/*
 * Tests whether a JavaScript value is an array object
 * 
 * This invokes Array.isArray(value) and returns its result
 */
EXPORTAPI bool HyperloopJSValueIsArray(JSContextRef ctx, JSValueRef value) 
{
    if (JSValueIsObject(ctx, value)) 
    {
        JSObjectRef global = JSContextGetGlobalObject(ctx);
        JSValueRef exception = JSValueMakeNull(ctx);
        JSStringRef string = JSStringCreateWithUTF8CString("Array");
        JSObjectRef array = JSValueToObject(ctx, JSObjectGetProperty(ctx, global, string, &exception), &exception);
        JSStringRelease(string);
        if (!JSValueIsNull(ctx, exception)) 
        {
            return false;
        }

        string = JSStringCreateWithUTF8CString("isArray");
        JSObjectRef isArray = JSValueToObject(ctx, JSObjectGetProperty(ctx, array, string, &exception), &exception);
        JSStringRelease(string);
        if (!JSValueIsNull(ctx, exception))
        {
            return false;
        }

        JSValueRef result = JSObjectCallAsFunction(ctx, isArray, global, 1, &value, &exception);

        if (JSValueIsNull(ctx, exception) && JSValueIsBoolean(ctx, result)) 
        {
            return JSValueToBoolean(ctx, result);
        }
    }
    return false;
}
Exemple #2
0
Type GetType(JSValueRef value)
{
    if (JSValueIsNull(g_ctx, value))
        return VTYPE_NULL;
    if (JSValueIsBoolean(g_ctx, value))
        return VTYPE_BOOL;
    if (JSValueIsNumber(g_ctx, value))
        return VTYPE_DOUBLE;
    if (JSValueIsString(g_ctx, value))
        return VTYPE_STRING;

    if (JSValueIsObject(g_ctx, value))
    {
        JSObjectRef obj = JSValueToObject(g_ctx, value, NULL);

        if (JSObjectIsFunction(g_ctx, obj))
            return VTYPE_FUNCTION;
        if (IsArray(obj))
            return VTYPE_LIST;

        return VTYPE_DICTIONARY;
    }

    return VTYPE_INVALID;
}
bool WebViewTest::javascriptResultToBoolean(WebKitJavascriptResult* javascriptResult)
{
    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
    g_assert(context);
    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
    g_assert(value);
    g_assert(JSValueIsBoolean(context, value));

    return JSValueToBoolean(context, value);
}
Exemple #4
0
static bool console_setSharedBool(JSContextRef ctx, JSObjectRef thisObject, JSStringRef /*propertyName*/, JSValueRef value, JSValueRef* /*exception*/)
{
    if (!JSValueIsBoolean(ctx, value))
        return false;

    CallJSDlg* dlg = static_cast<CallJSDlg*>(JSObjectGetPrivate(thisObject));
    if (!dlg)
        return false;

    bool temp = JSValueToBoolean (ctx, value);
    dlg->setSharedBool(temp);

    return true;
}
/**
 * internal
 * 
 * implementation of console.log 
 */
static JSValueRef HyperloopLogger (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (argumentCount>0) 
    {
        std::ostringstream stream;
        for (size_t c=0;c<argumentCount;c++)
        {
            if (JSValueIsObject(ctx,arguments[c]) || JSValueIsString(ctx,arguments[c])) 
            {
                std::string str(HyperloopJSValueToStringCopy(ctx,arguments[c],exception));
                stream << str;
            }
            else if (JSValueIsNumber(ctx,arguments[c]))
            {
                double num = JSValueToNumber(ctx,arguments[c],exception);
                double intpart;
                if (modf(num, &intpart) == 0.0)
                {
                    stream << intpart;
                }
                else 
                {
                    stream << num;
                }
            }
            else if (JSValueIsBoolean(ctx,arguments[c]))
            {
                bool b = JSValueToBoolean(ctx,arguments[c]);
                stream << (b ? "true":"false");
            }
            else if (JSValueIsNull(ctx,arguments[c]))
            {
                stream << "null";
            }
            else if (JSValueIsUndefined(ctx,arguments[c]))
            {
                stream << "undefined";
            }
            if (c+1 < argumentCount) 
            {
                stream << " ";
            }
        }
        // call the platform adapter
        HyperloopNativeLogger(stream.str().c_str());
    }
    return JSValueMakeUndefined(ctx);
}
Exemple #6
0
static bool
gumjs_proxy_has_property (JSContextRef ctx,
                          JSObjectRef object,
                          JSStringRef property_name)
{
  GumJscProxy * self;
  GumJscCore * core;

  self = GUMJS_PROXY (object);
  if (self->has == NULL)
    return false;

  core = JSObjectGetPrivate (JSContextGetGlobalObject (ctx));

  {
    GumJscScope scope = GUM_JSC_SCOPE_INIT (core);
    JSValueRef * ex = &scope.exception;
    JSValueRef property_name_value, value;
    bool result = false;

    property_name_value = JSValueMakeString (ctx, property_name);
    value = JSObjectCallAsFunction (ctx, self->has, self->receiver,
        1, &property_name_value, ex);
    if (value == NULL)
      goto beach;

    if (!JSValueIsBoolean (ctx, value))
      goto invalid_result_type;

    result = JSValueToBoolean (ctx, value);

    goto beach;

invalid_result_type:
    {
      _gumjs_throw (ctx, ex, "expected has() to return a boolean");
      goto beach;
    }
beach:
    {
      _gum_jsc_scope_flush (&scope);
      return result;
    }
  }
}
static JSValueRef
JSOSInstaller_setRestart(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (!JSValueIsObjectOfClass(context, thisObject, JSOSInstaller_class(context))) {
        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: setRestart can only be called on JSOSInstaller");
        *exception = JSValueMakeString(context, message);
        JSStringRelease(message);
    } else if (argumentCount < 1 || !JSValueIsBoolean(context, arguments[0])) {
        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to setRestart must be a boolean");
        *exception = JSValueMakeString(context, message);
        JSStringRelease(message);
    } else {
        JSInstaller* jsinst = JSObjectGetPrivate(thisObject);
        jsinst->restart = JSValueToBoolean(context,arguments[0]);
    }

    return JSValueMakeUndefined(context);
}
Exemple #8
0
template<> bool RJSAccessor::to_bool(JSContextRef ctx, JSValueRef &val) {
    if (!JSValueIsBoolean(ctx, val)) {
        throw std::runtime_error("Property expected to be of type boolean");
    }
    return JSValueToBoolean(ctx, val);
}
Exemple #9
0
bool jsc::Value::isBoolean()   const {return JSValueIsBoolean(context, value);}