void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message)
{
    ASSERT_ARG(message, message);

    JSStringRef messageConstructorString = JSStringCreateWithUTF8CString("ConsoleMessage");
    JSObjectRef messageConstructor = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, messageConstructorString, 0), 0);
    JSStringRelease(messageConstructorString);

    JSStringRef addMessageString = JSStringCreateWithUTF8CString("addMessageToConsole");
    JSObjectRef addMessage = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, addMessageString, 0), 0);
    JSStringRelease(addMessageString);

    JSValueRef sourceValue = JSValueMakeNumber(m_scriptContext, message->source);
    JSValueRef levelValue = JSValueMakeNumber(m_scriptContext, message->level);
    JSStringRef messageString = JSStringCreateWithCharacters(message->message.characters(), message->message.length());
    JSValueRef messageValue = JSValueMakeString(m_scriptContext, messageString);
    JSValueRef lineValue = JSValueMakeNumber(m_scriptContext, message->line);
    JSStringRef urlString = JSStringCreateWithCharacters(message->url.characters(), message->url.length());
    JSValueRef urlValue = JSValueMakeString(m_scriptContext, urlString);

    JSValueRef args[] = { sourceValue, levelValue, messageValue, lineValue, urlValue };
    JSObjectRef messageObject = JSObjectCallAsConstructor(m_scriptContext, messageConstructor, 5, args, 0);
    JSStringRelease(messageString);
    JSStringRelease(urlString);

    JSObjectCallAsFunction(m_scriptContext, addMessage, m_scriptObject, 1, &messageObject, 0);
}
Example #2
0
/*
 * 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;
}
JSObjectRef InspectorController::addScriptResource(InspectorResource* resource)
{
    ASSERT_ARG(resource, resource);

    // This happens for pages loaded from the back/forward cache.
    if (resource->scriptObject)
        return resource->scriptObject;

    ASSERT(m_scriptContext);
    ASSERT(m_scriptObject);
    if (!m_scriptContext || !m_scriptObject)
        return 0;

    JSStringRef resourceString = JSStringCreateWithUTF8CString("Resource");
    JSObjectRef resourceConstructor = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, resourceString, 0), 0);
    JSStringRelease(resourceString);

    String urlString = resource->requestURL.url();
    JSStringRef url = JSStringCreateWithCharacters(urlString.characters(), urlString.length());
    JSValueRef urlValue = JSValueMakeString(m_scriptContext, url);
    JSStringRelease(url);

    urlString = resource->requestURL.host();
    JSStringRef domain = JSStringCreateWithCharacters(urlString.characters(), urlString.length());
    JSValueRef domainValue = JSValueMakeString(m_scriptContext, domain);
    JSStringRelease(domain);

    urlString = resource->requestURL.path();
    JSStringRef path = JSStringCreateWithCharacters(urlString.characters(), urlString.length());
    JSValueRef pathValue = JSValueMakeString(m_scriptContext, path);
    JSStringRelease(path);

    urlString = resource->requestURL.lastPathComponent();
    JSStringRef lastPathComponent = JSStringCreateWithCharacters(urlString.characters(), urlString.length());
    JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, lastPathComponent);
    JSStringRelease(lastPathComponent);

    JSValueRef identifier = JSValueMakeNumber(m_scriptContext, resource->identifier);
    JSValueRef mainResource = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource);
    JSValueRef cached = JSValueMakeBoolean(m_scriptContext, resource->cached);

    JSValueRef arguments[] = { scriptObjectForRequest(m_scriptContext, resource), urlValue, domainValue, pathValue, lastPathComponentValue, identifier, mainResource, cached };
    JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, resourceConstructor, 8, arguments, 0);

    resource->setScriptObject(m_scriptContext, result);

    ASSERT(result);

    JSStringRef addResourceString = JSStringCreateWithUTF8CString("addResource");
    JSObjectRef addResourceFunction = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, addResourceString, 0), 0);
    JSStringRelease(addResourceString);

    JSValueRef addArguments[] = { result };
    JSObjectCallAsFunction(m_scriptContext, addResourceFunction, m_scriptObject, 1, addArguments, 0);

    return result;
}
static JSValueRef search(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/)
{
    InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
    if (!controller)
        return JSValueMakeUndefined(ctx);

    if (argumentCount < 2 || !JSValueIsString(ctx, arguments[1]))
        return JSValueMakeUndefined(ctx);

    Node* node = toNode(toJS(arguments[0]));
    if (!node)
        return JSValueMakeUndefined(ctx);

    JSStringRef string = JSValueToStringCopy(ctx, arguments[1], 0);
    String target(JSStringGetCharactersPtr(string), JSStringGetLength(string));
    JSStringRelease(string);

    JSObjectRef globalObject = JSContextGetGlobalObject(ctx);
    JSStringRef constructorString = JSStringCreateWithUTF8CString("Array");
    JSObjectRef arrayConstructor = JSValueToObject(ctx, JSObjectGetProperty(ctx, globalObject, constructorString, 0), 0);
    JSStringRelease(constructorString);
    JSObjectRef array = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, 0);

    JSStringRef pushString = JSStringCreateWithUTF8CString("push");
    JSValueRef pushValue = JSObjectGetProperty(ctx, array, pushString, 0);
    JSStringRelease(pushString);
    JSObjectRef push = JSValueToObject(ctx, pushValue, 0);

    RefPtr<Range> searchRange(rangeOfContents(node));

    int exception = 0;
    do {
        RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false));
        if (resultRange->collapsed(exception))
            break;

        // A non-collapsed result range can in some funky whitespace cases still not
        // advance the range's start position (4509328). Break to avoid infinite loop.
        VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM);
        if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM))
            break;

        KJS::JSLock lock;
        JSValueRef arg0 = toRef(toJS(toJS(ctx), resultRange.get()));
        JSObjectCallAsFunction(ctx, push, array, 1, &arg0, 0);

        setStart(searchRange.get(), newStart);
    } while (true);

    return array;
}
Example #5
0
bool TestRunner::findString(JSContextRef context, JSStringRef string, JSObjectRef optionsArray)
{
    JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
    JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
    if (!JSValueIsNumber(context, lengthValue))
        return false;

    QWebPage::FindFlags findFlags = QWebPage::FindCaseSensitively;

    int length = static_cast<int>(JSValueToNumber(context, lengthValue, 0));
    for (int i = 0; i < length; ++i) {
        JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
        if (!JSValueIsString(context, value))
            continue;

        JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
        if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
            findFlags &= ~QWebPage::FindCaseSensitively;
        else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
            findFlags |= QWebPage::FindAtWordBeginningsOnly;
        else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
            findFlags |=  QWebPage::TreatMedialCapitalAsWordBeginning;
        else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
            findFlags |=  QWebPage::FindBackward;
        else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
            findFlags |=  QWebPage::FindWrapsAroundDocument;
        else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection"))
            findFlags |=  QWebPage::FindBeginsInSelection;
    }

    DumpRenderTree* drt = DumpRenderTree::instance();
    return drt->webPage()->findText(JSStringCopyQString(string), findFlags);
}
Example #6
0
static guint gdkModifersFromJSValue(JSContextRef context, const JSValueRef modifiers)
{
    JSObjectRef modifiersArray = JSValueToObject(context, modifiers, 0);
    if (!modifiersArray)
        return 0;

    guint gdkModifiers = 0;
    int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, JSStringCreateWithUTF8CString("length"), 0), 0);
    for (int i = 0; i < modifiersCount; ++i) {
        JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0);
        JSStringRef string = JSValueToStringCopy(context, value, 0);
        if (JSStringIsEqualToUTF8CString(string, "ctrlKey")
            || JSStringIsEqualToUTF8CString(string, "addSelectionKey"))
            gdkModifiers |= GDK_CONTROL_MASK;
        else if (JSStringIsEqualToUTF8CString(string, "shiftKey")
                 || JSStringIsEqualToUTF8CString(string, "rangeSelectionKey"))
            gdkModifiers |= GDK_SHIFT_MASK;
        else if (JSStringIsEqualToUTF8CString(string, "altKey"))
            gdkModifiers |= GDK_MOD1_MASK;

        // Currently the metaKey as defined in WebCore/platform/gtk/MouseEventGtk.cpp
        // is GDK_MOD2_MASK. This code must be kept in sync with that file.
        else if (JSStringIsEqualToUTF8CString(string, "metaKey"))
            gdkModifiers |= GDK_MOD2_MASK;

        JSStringRelease(string);
    }
    return gdkModifiers;
}
Example #7
0
static JSValueRef EvilExceptionObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
{
    UNUSED_PARAM(object);
    UNUSED_PARAM(exception);
    JSStringRef funcName;
    switch (type) {
    case kJSTypeNumber:
        funcName = JSStringCreateWithUTF8CString("toNumber");
        break;
    case kJSTypeString:
        funcName = JSStringCreateWithUTF8CString("toStringExplicit");
        break;
    default:
        return NULL;
        break;
    }
    
    JSValueRef func = JSObjectGetProperty(context, object, funcName, exception);
    JSStringRelease(funcName);    
    JSObjectRef function = JSValueToObject(context, func, exception);
    if (!function)
        return NULL;
    JSValueRef value = JSObjectCallAsFunction(context, function, object, 0, NULL, exception);
    if (!value)
        return (JSValueRef)JSStringCreateWithUTF8CString("convertToType failed");
    return value;
}
Example #8
0
unsigned JSArray::length() {
  JSValueRef val = JSObjectGetProperty(ctx_, instance_, JSString("length"), nullptr);
  if (JSValueIsNumber(ctx_, val))
    return static_cast<unsigned>(JSValueToNumber(ctx_, val, nullptr));

  return 0;
}
Example #9
0
VJSValue VJSObject::GetProperty( const VString& inPropertyName, JS4D::ExceptionRef *outException) const
{
	JSStringRef jsName = JS4D::VStringToString( inPropertyName);
	JSValueRef valueRef = JSObjectGetProperty( fContext, fObject, jsName, outException);
	JSStringRelease( jsName);
	return VJSValue( fContext, valueRef);
}
Example #10
0
bool JS4D::DateObjectToVTime( ContextRef inContext, ObjectRef inObject, VTime& outTime, ExceptionRef *outException)
{
	// it's caller responsibility to check inObject is really a Date using ValueIsInstanceOf
	
	// call getTime()
	bool ok = false;
    JSStringRef jsString = JSStringCreateWithUTF8CString( "getTime");
	JSValueRef getTime = JSObjectGetProperty( inContext, inObject, jsString, outException);
	JSObjectRef getTimeFunction = JSValueToObject( inContext, getTime, outException);
    JSStringRelease( jsString);
	JSValueRef result = (getTime != NULL) ? JSObjectCallAsFunction( inContext, getTimeFunction, inObject, 0, NULL, outException) : NULL;
	if (result != NULL)
	{
		// The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
		double r = JSValueToNumber( inContext, result, outException);
		sLONG8 n = (sLONG8) r;
		if (n == r)
		{
			outTime.FromUTCTime( 1970, 1, 1, 0, 0, 0, 0);
			outTime.AddMilliseconds( n);
			ok = true;
		}
		else
		{
			outTime.SetNull( true);
		}
	}
	else
	{
		outTime.SetNull( true);
	}
	return ok;
}
Example #11
0
JS4D::ObjectRef JS4D::VTimeToObject( ContextRef inContext, const VTime& inTime, ExceptionRef *outException)
{
	if (inTime.IsNull())
		return NULL;	// can't return JSValueMakeNull as an object
	
	sWORD year, month, day, hour, minute, second, millisecond;
	
	inTime.GetLocalTime( year, month, day, hour, minute, second, millisecond);

	JSValueRef	args[6];
	args[0] = JSValueMakeNumber( inContext, year);
	args[1] = JSValueMakeNumber( inContext, month-1);
	args[2] = JSValueMakeNumber( inContext, day);
	args[3] = JSValueMakeNumber( inContext, hour);
	args[4] = JSValueMakeNumber( inContext, minute);
	args[5] = JSValueMakeNumber( inContext, second);

	#if NEW_WEBKIT
	JSObjectRef date = JSObjectMakeDate( inContext, 6, args, outException);
	#else
    JSStringRef jsClassName = JSStringCreateWithUTF8CString("Date");
    JSObjectRef constructor = JSValueToObject( inContext, JSObjectGetProperty( inContext, JSContextGetGlobalObject( inContext), jsClassName, NULL), NULL);
    JSStringRelease( jsClassName);
    JSObjectRef date = JSObjectCallAsConstructor( inContext, constructor, 6, args, outException);
	#endif

	return date;
}
void InspectorController::scriptObjectReady()
{
    ASSERT(m_scriptContext);
    if (!m_scriptContext)
        return;

    JSObjectRef global = JSContextGetGlobalObject(m_scriptContext);
    ASSERT(global);

    JSStringRef inspectorString = JSStringCreateWithUTF8CString("WebInspector");
    JSValueRef inspectorValue = JSObjectGetProperty(m_scriptContext, global, inspectorString, 0);
    JSStringRelease(inspectorString);

    ASSERT(inspectorValue);
    if (!inspectorValue)
        return;

    m_scriptObject = JSValueToObject(m_scriptContext, inspectorValue, 0);
    ASSERT(m_scriptObject);

    JSValueProtect(m_scriptContext, m_scriptObject);

    // Make sure our window is visible now that the page loaded
    m_client->showWindow();
}
void InspectorController::focusNode()
{
    if (!enabled())
        return;

    ASSERT(m_scriptContext);
    ASSERT(m_scriptObject);
    ASSERT(m_nodeToFocus);

    JSValueRef arg0;

    {
        KJS::JSLock lock;
        arg0 = toRef(toJS(toJS(m_scriptContext), m_nodeToFocus.get()));
    }

    m_nodeToFocus = 0;

    JSStringRef functionProperty = JSStringCreateWithUTF8CString("updateFocusedNode");
    JSObjectRef function = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, functionProperty, 0), 0);
    JSStringRelease(functionProperty);
    ASSERT(function);

    JSObjectCallAsFunction(m_scriptContext, function, m_scriptObject, 1, &arg0, 0);
}
Example #14
0
static JSValueRef propertyValue(JSContextRef context, JSObjectRef object, const char* propertyName)
{
    if (!object)
        return 0;
    JSRetainPtr<JSStringRef> propertyNameString(Adopt, JSStringCreateWithUTF8CString(propertyName));
    return JSObjectGetProperty(context, object, propertyNameString.get(), 0);
}
JNIEXPORT void JNICALL
Java_com_appcelerator_hyperloop_HyperloopJNI_HyperloopCallActivityOnCreate
(JNIEnv *env, jobject thiz, jlong jsContextRef, jobject activity, jobject savedInstanceState)
{
    JSContextRef context = (JSContextRef)jsContextRef;
    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    
    JSStringRef onCreate = JSStringCreateWithUTF8CString("onCreate");
    JSObjectRef onCreateFunc = JSValueToObject(context,
                    JSObjectGetProperty(context, globalObject, onCreate, NULL), NULL);
    JSStringRelease(onCreate);
    
    // save current Activity
    JSObjectRef activityObj = MakeObjectForJava_android_app_Activity(context, activity);
    
    // save parameter
    JSValueRef args[1];
    args[0] = MakeObjectForJava_android_os_Bundle(context, savedInstanceState);

    JSValueRef exception = JSValueMakeNull(context);
    
    // Call onCreate function
    if (JSObjectIsFunction(context, onCreateFunc)) {
        JSObjectCallAsFunction(context, onCreateFunc, activityObj, 1, args, &exception);
    }
    if (!JSValueIsNull(context, exception)) {
        JSStringRef string = JSValueToStringCopy(context, exception, NULL);
        CCHAR_FROM_JSSTRINGREF(string, cstring);
        LOGD("Java_com_appcelerator_hyperloop_HyperloopJNI_HyperloopCallActivityOnCreate '%s'", cstring);
        free(cstring);
        JSStringRelease(string);
    }
    
}
Example #16
0
bool LayoutTestController::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray)
{
    JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
    JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
    if (!JSValueIsNumber(context, lengthValue))
        return false;

    WebCore::FindOptions options = 0;

    const size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0));
    for (size_t i = 0; i < length; ++i) {
        JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
        if (!JSValueIsString(context, value))
            continue;

        JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));

        if (equals(optionName, "CaseInsensitive"))
            options |= WebCore::CaseInsensitive;
        else if (equals(optionName, "AtWordStarts"))
            options |= WebCore::AtWordStarts;
        else if (equals(optionName, "TreatMedialCapitalAsWordStart"))
            options |= WebCore::TreatMedialCapitalAsWordStart;
        else if (equals(optionName, "Backwards"))
            options |= WebCore::Backwards;
        else if (equals(optionName, "WrapAround"))
            options |= WebCore::WrapAround;
        else if (equals(optionName, "StartInSelection"))
            options |= WebCore::StartInSelection;
    }

    return DumpRenderTreeSupportEfl::findString(browser->mainView(), target->ustring().utf8().data(), options);
}
static unsigned arrayLength(JSContextRef context, JSObjectRef array)
{
    JSRetainPtr<JSStringRef> lengthString(Adopt, JSStringCreateWithUTF8CString("length"));
    JSValueRef lengthValue = JSObjectGetProperty(context, array, lengthString.get(), 0);
    if (!lengthValue)
        return 0;
    return static_cast<unsigned>(JSValueToNumber(context, lengthValue, 0));
}
Example #18
0
VJSObject VJSObject::GetPropertyAsObject( const VString& inPropertyName, JS4D::ExceptionRef *outException) const
{
	JSStringRef jsName = JS4D::VStringToString( inPropertyName);
	JSValueRef value = JSObjectGetProperty( fContext, fObject, jsName, outException);
	JSObjectRef objectRef = ((value != NULL) && JSValueIsObject( fContext, value)) ? JSValueToObject( fContext, value, outException) : NULL;
	JSStringRelease( jsName);
	return VJSObject( fContext, objectRef);
}
Example #19
0
JSValueRef ObjectWrapper::GetValue(const KeyType key)
{
    JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
    JSValueRef value = JSObjectGetProperty(g_ctx, m_obj, strKey, NULL);
    JSStringRelease(strKey);

    return value;
}
Example #20
0
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
    KJS::JSLock lock(false);

    if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
        return JSValueMakeUndefined(ctx);

    ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
    const Vector<RefPtr<ProfileNode> >& children = profileNode->children();

    JSObjectRef global = JSContextGetGlobalObject(ctx);

    JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array"));

    JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push"));
    
    JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception);
    if (exception && *exception)
        return JSValueMakeUndefined(ctx);

    for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) {
        JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() ));
        JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
        if (exception && *exception)
            return JSValueMakeUndefined(ctx);
    }

    return result;
}
Example #21
0
Value Object::getProperty(const String& propName) const {
  JSValueRef exn;
  JSValueRef property = JSObjectGetProperty(m_context, m_obj, propName, &exn);
  if (!property) {
    std::string exceptionText = Value(m_context, exn).toString().str();
    throwJSExecutionException("Failed to get property: %s", exceptionText.c_str());
  }
  return Value(m_context, property);
}
Example #22
0
JS4D::ValueRef VJSPropertyIterator::_GetProperty( JS4D::ExceptionRef *outException) const
{
	JSValueRef value;
	if (testAssert( fIndex < fCount))
		value = JSObjectGetProperty( fObject.GetContextRef(), fObject, JSPropertyNameArrayGetNameAtIndex( fNameArray, fIndex), outException);
	else
		value = NULL;
	return value;
}
pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop)
{
	JSStringRef jprop = JSStringCreateWithUTF8CString(prop);
	JSValueRef jval = JSObjectGetProperty(imp->jscore_ctx, JSValueToObject(imp->jscore_ctx, obj->ref, NULL), jprop, NULL);

	JSStringRelease(jprop);

	return wrap_val(imp, jval);
}
Example #24
0
size_t ArrayWrapper::GetSize()
{
    JSStringRef strLength = JSStringCreateWithUTF8CString("length");
    JSValueRef valLength = JSObjectGetProperty(g_ctx, m_arr, strLength, NULL);
    size_t len = (size_t) JSValueToNumber(g_ctx, valLength, NULL);
    JSStringRelease(strLength);

    return len;
}
Example #25
0
static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
{
    UNUSED_PARAM(context);

    JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
    JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, NULL), NULL);
    JSStringRelease(numberString);

    return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, NULL);
}
Example #26
0
gboolean jsvalue_instanceof(JSContextRef ctx, JSValueRef test, const char *klass)
{
  JSStringRef property = JSStringCreateWithUTF8CString(klass);
  JSObjectRef ctor = JSValueToObject(ctx,
                         JSObjectGetProperty(ctx, JSContextGetGlobalObject(ctx),
                             property, NULL),
                         NULL);
  JSStringRelease(property);
  return JSValueIsInstanceOfConstructor(ctx, test, ctor, NULL);
}
Example #27
0
bool JS4D::ValueIsInstanceOf( ContextRef inContext, ValueRef inValue, const VString& inConstructorName, ExceptionRef *outException)
{
	JSStringRef jsString = JS4D::VStringToString( inConstructorName);
	JSObjectRef globalObject = JSContextGetGlobalObject( inContext);
	JSObjectRef constructor = JSValueToObject( inContext, JSObjectGetProperty( inContext, globalObject, jsString, outException), outException);
	xbox_assert( constructor != NULL);
	JSStringRelease( jsString);

	return (constructor != NULL) && (inValue != NULL) && JSValueIsInstanceOfConstructor( inContext, inValue, constructor, outException);
}
Example #28
0
void JSArray::push(const JSValue& val) {
  JSValueRef prop = JSObjectGetProperty(ctx_, instance_, JSString("push"), nullptr);
  if (JSValueIsObject(ctx_, prop)) {
    JSObjectRef func = JSValueToObject(ctx_, prop, nullptr);
    if (JSObjectIsFunction(ctx_, func)) {
      JSValueRef arg = val;
      JSObjectCallAsFunction(ctx_, func, instance_, 1, &arg, nullptr);
    }
  }
}
Example #29
0
bool
web_view_callback (struct js_callback_data *data) {
	unsigned short i;

	JSValueRef js_args[data->args_len];
	for (i = 0; i < data->args_len; i++) {
		switch (data->args[i].type) {
		case kJSTypeBoolean:
			js_args[i] = JSValueMakeBoolean(data->widget->js_context, data->args[i].value.boolean);
			break;
		case kJSTypeNull:
			js_args[i] = JSValueMakeNull(data->widget->js_context);
			break;
		case kJSTypeNumber:
			js_args[i] = JSValueMakeNumber(data->widget->js_context, data->args[i].value.number);
			break;
		case kJSTypeObject:
			js_args[i] = data->args[i].value.object;
			break;
		case kJSTypeString: {
			JSStringRef str = JSStringCreateWithUTF8CString(data->args[i].value.string);
			js_args[i] = JSValueMakeString(data->widget->js_context, str);
			JSStringRelease(str);
			break;
		}
		case kJSTypeUndefined:
			js_args[i] = JSValueMakeUndefined(data->widget->js_context);
			break;
		}
	}

	if (!data->widget->js_context || !data->widget->js_object) {
		LOG_ERR("missing JS context or object!");

		return false;
	}

	JSStringRef str_ondatachanged = JSStringCreateWithUTF8CString("onDataChanged");
	JSValueRef func = JSObjectGetProperty(data->widget->js_context, data->widget->js_object, str_ondatachanged, NULL);
	JSObjectRef function = JSValueToObject(data->widget->js_context, func, NULL);
	JSStringRelease(str_ondatachanged);

	/* let the thread know we're done with the data so it can cleanup */
	pthread_cond_signal(&update_cond);

	if (!JSObjectIsFunction(data->widget->js_context, function)) {
		LOG_DEBUG("onDataChanged callback for 'widget_%s' with type '%s' is not a function or is not set", data->widget->name, data->widget->type);

		return false; /* only run once */
	}

	JSObjectCallAsFunction(data->widget->js_context, function, NULL, data->args_len, js_args, NULL);

	return false; /* only run once */
}
Example #30
0
static void dumpException (JSContextRef context, JSValueRef exception) {
  // description
  char *description = JSValueToCString(context, exception, NULL);
  fprintf(stderr, "%s", description);
  free(description);

  // line
  JSStringRef lineProperty = JSStringCreateWithUTF8CString("line");
  JSValueRef lineValue =
    JSObjectGetProperty(context, (JSObjectRef)exception, lineProperty, NULL);
  int line = JSValueToNumber(context, lineValue, NULL);
  fprintf(stderr, " on line %d", line);
  JSStringRelease(lineProperty);

  // source
  JSStringRef sourceProperty = JSStringCreateWithUTF8CString("sourceURL");
  if (JSObjectGetProperty(context, (JSObjectRef)exception, sourceProperty, NULL)) {
    JSValueRef sourceValue =
      JSObjectGetProperty(context, (JSObjectRef)exception, sourceProperty, NULL);
    char *sourceString = JSValueToCString(context, sourceValue, NULL);
    fprintf(stderr, " in %s", sourceString);
    free(sourceString);
  }
  JSStringRelease(sourceProperty);

  JSStringRef stackProperty = JSStringCreateWithUTF8CString("stack");
  if (JSObjectGetProperty(context, (JSObjectRef)exception, stackProperty, NULL)) {
    fprintf(stderr, ":\n");
    JSValueRef stackValue =
      JSObjectGetProperty(context, (JSObjectRef)exception, stackProperty, NULL);
    char *stack = JSValueToCString(context, stackValue, NULL);
    char *line = strtok(stack, "\n");
    while (line != NULL) {
      if (line[0] == '(')
        fprintf(stderr, "%s\n", line);
      line = strtok(NULL, "\n");
    }
  } else {
    fprintf(stderr, "\n");
  }
  JSStringRelease(stackProperty);
}