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; }
int main (int argc, char **argv) { JSGlobalContextRef ctx; JSStringRef script; bool isOk; JSValueRef result; char *js; if (argc <= 1) { printf("Usage: JavaScript\n"); return 0; } js = argv[1]; ctx = JSGlobalContextCreate(NULL); printf("Checking: %s\n", js); script = JSStringCreateWithUTF8CString(js); isOk = JSCheckScriptSyntax(ctx, script, NULL, 1, NULL); printf("is ok? %s\n", isOk ? "TRUE" : "FALSE"); result = JSEvaluateScript(ctx, script, NULL, NULL, 1, NULL); JSStringRelease(script); printf("Value %.2f\n", JSValueToNumber(ctx, result, NULL)); JSGarbageCollect(ctx); JSGlobalContextRelease(ctx); printf("Ok\n"); return 0; }
bool TestRunner::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->string(), options); }
static JSValueRef getResourceDocumentNode(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) { JSValueRef undefined = JSValueMakeUndefined(ctx); InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject)); if (!argumentCount || argumentCount > 1 || !controller) return undefined; JSValueRef identifierValue = arguments[0]; if (!JSValueIsNumber(ctx, identifierValue)) return undefined; unsigned long identifier = static_cast<unsigned long>(JSValueToNumber(ctx, identifierValue, 0)); RefPtr<InspectorResource> resource = controller->resources().get(identifier); ASSERT(resource); if (!resource) return undefined; FrameLoader* frameLoader = resource->loader->frameLoader(); if (!frameLoader) return undefined; Document* document = frameLoader->frame()->document(); if (!document) return undefined; if (document->isPluginDocument() || document->isImageDocument()) return undefined; KJS::JSLock lock; JSValueRef documentValue = toRef(toJS(toJS(controller->scriptContext()), document)); return documentValue; }
JSValueRef JSCExecutor::nativeRequire( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { if (argumentCount != 1) { *exception = makeJSCException(ctx, "Got wrong number of args"); return JSValueMakeUndefined(ctx); } JSCExecutor *executor; try { executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx)); } catch (std::out_of_range& e) { *exception = makeJSCException(ctx, "Global JS context didn't map to a valid executor"); return JSValueMakeUndefined(ctx); } double moduleId = JSValueToNumber(ctx, arguments[0], exception); if (moduleId <= (double) std::numeric_limits<uint32_t>::max() && moduleId >= 0.0) { try { executor->loadModule(moduleId); } catch (JSModulesUnbundle::ModuleNotFound&) { *exception = makeInvalidModuleIdJSCException(ctx, arguments[0], exception); } } else { *exception = makeInvalidModuleIdJSCException(ctx, arguments[0], exception); } return JSValueMakeUndefined(ctx); }
JSValueRef JSCExecutor::nativePostMessageToWorker( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { if (argumentCount != 2) { *exception = createErrorString(ctx, "Got wrong number of args"); return JSValueMakeUndefined(ctx); } double workerDouble = JSValueToNumber(ctx, arguments[0], exception); if (workerDouble != workerDouble) { *exception = createErrorString(ctx, "Got invalid worker id"); return JSValueMakeUndefined(ctx); } JSCExecutor *executor; try { executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx)); } catch (std::out_of_range& e) { *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor"); return JSValueMakeUndefined(ctx); } executor->postMessageToOwnedWebWorker((int) workerDouble, arguments[1], exception); return JSValueMakeUndefined(ctx); }
bool S_CCLabelTTF::initWithContext(JSContextRef ctx, JSObjectRef obj, size_t argumentCount, const JSValueRef arguments[]) { bool result = true; if (argumentCount == 3) { char *buffText = (char *)malloc(128); char *buffFont = (char *)malloc(128); JSStringRef jsLabelText = JSValueToStringCopy(ctx, arguments[0], NULL); JSStringRef jsFontName = JSValueToStringCopy(ctx, arguments[1], NULL); float fontSize = JSValueToNumber(ctx, arguments[2], NULL); JSStringGetUTF8CString(jsLabelText, buffText, 128); JSStringGetUTF8CString(jsFontName, buffFont, 128); if (!CCLabelTTF::initWithString(buffText, buffFont, fontSize)) { return false; } free(buffText); free(buffFont); } else { if (!CCLabelTTF::init()) { result = false; } } if (result) { setUserData(obj); } return result; }
JSValueRef JSCCharacterData::insertDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj); if (false) { } else if (argumentCount == 2 && JSValueIsNumber(ctx, arguments[0]) && JSValueIsString(ctx, arguments[1])) { unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[1], exception); size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); char* localArgBuffer = new char[localArgMaxSize]; JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); std::string localArg(localArgBuffer); JSStringRelease(stringReflocalArg); free(localArgBuffer); privData->nativeObj->insertData(localOffset, localArg); JSValueRef jscRetVal = JSValueMakeUndefined(ctx); return jscRetVal; } JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling insertData"); *exception = JSValueMakeString(ctx, exceptionString); JSStringRelease(exceptionString); return JSValueMakeUndefined(ctx); }
JSObjectRef MakeInstance (JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { size_t length = 1; if (argumentCount > 0) { *exception = nullptr; if (!JSValueIsNumber(ctx,arguments[0])) { JSStringRef string = JSStringCreateWithUTF8CString("required first argument to be a number which is the size of the buffer requested"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return nullptr; } length = JSValueToNumber(ctx, arguments[0], exception); CHECK_BUF_EXCEPTION(nullptr); } JSBuffer *buffer = (JSBuffer *)malloc(sizeof(JSBuffer)); buffer->buffer = malloc(length); buffer->length = length; buffer->type = JSBufferTypePointer; memset(buffer->buffer, 0, length); // by default, let's set the value to NAN float *p = (float*)buffer->buffer; p[0] = NAN; JSObjectRef object = MakeObjectForJSBuffer(ctx,buffer); return object; }
static JSValueRef continuousMouseScrollBy(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); double deltaX = JSValueToNumber(context, arguments[0], exception); double deltaY = 0; if (argumentCount >= 2) deltaY = JSValueToNumber(context, arguments[1], exception); mouseScrollBy(deltaX, deltaY, true); return JSValueMakeUndefined(context); }
static JSValueRef mouseDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { int button = 0; if (argumentCount == 1) { button = static_cast<int>(JSValueToNumber(context, arguments[0], exception)); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); } guint modifiers = argumentCount >= 2 ? gdkModifersFromJSValue(context, arguments[1]) : 0; GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); if (!prepareMouseButtonEvent(event, button, modifiers)) return JSValueMakeUndefined(context); buttonCurrentlyDown = event->button.button; // Normally GDK will send both GDK_BUTTON_PRESS and GDK_2BUTTON_PRESS for // the second button press during double-clicks. WebKit GTK+ selectively // ignores the first GDK_BUTTON_PRESS of that pair using gdk_event_peek. // Since our events aren't ever going onto the GDK event queue, WebKit won't // be able to filter out the first GDK_BUTTON_PRESS, so we just don't send // it here. Eventually this code should probably figure out a way to get all // appropriate events onto the event queue and this work-around should be // removed. updateClickCount(event->button.button); if (clickCount == 2) event->type = GDK_2BUTTON_PRESS; else if (clickCount == 3) event->type = GDK_3BUTTON_PRESS; sendOrQueueEvent(event); return JSValueMakeUndefined(context); }
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); }
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; }
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; }
JSValueRef function_set_exit_value(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef* exception) { if (argc == 1 && JSValueGetType (ctx, args[0]) == kJSTypeNumber) { exit_value = JSValueToNumber(ctx, args[0], NULL); } return JSValueMakeNull(ctx); }
JSValueRef function_file_output_stream_write(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { if (argc == 2 && JSValueGetType(ctx, args[0]) == kJSTypeString && JSValueGetType(ctx, args[1]) == kJSTypeObject) { char *descriptor = value_to_c_string(ctx, args[0]); unsigned int count = (unsigned int) array_get_count(ctx, (JSObjectRef) args[1]); uint8_t buf[count]; for (unsigned int i = 0; i < count; i++) { JSValueRef v = array_get_value_at_index(ctx, (JSObjectRef) args[1], i); if (JSValueIsNumber(ctx, v)) { double n = JSValueToNumber(ctx, v, NULL); if (0 <= n && n <= 255) { buf[i] = (uint8_t) n; } else { fprintf(stderr, "Output stream value out of range %f", n); } } else { fprintf(stderr, "Output stream value not a number"); } } file_write(descriptor_str_to_int(descriptor), count, buf); free(descriptor); } return JSValueMakeNull(ctx); }
static JSValueRef mouseMoveToCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); if (argumentCount < 2) return JSValueMakeUndefined(context); lastMousePositionX = (int)JSValueToNumber(context, arguments[0], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); lastMousePositionY = (int)JSValueToNumber(context, arguments[1], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); GdkEvent event; memset(&event, 0, sizeof(event)); event.type = GDK_MOTION_NOTIFY; event.motion.x = lastMousePositionX; event.motion.y = lastMousePositionY; event.motion.time = GDK_CURRENT_TIME; event.motion.window = GTK_WIDGET(view)->window; event.motion.device = gdk_device_get_core_pointer(); int x_root, y_root; #if GTK_CHECK_VERSION(2,17,3) gdk_window_get_root_coords(GTK_WIDGET(view)->window, lastMousePositionX, lastMousePositionY, &x_root, &y_root); #else getRootCoords(GTK_WIDGET(view), &x_root, &y_root); #endif event.motion.x_root = x_root; event.motion.y_root = y_root; event.motion.state = getStateFlags(); if (dragMode && down && !replayingSavedEvents) { msgQueue[endOfQueue].event = event; msgQueue[endOfQueue++].isDragEvent = true; } else { webkit_web_frame_layout(mainFrame); gboolean return_val; g_signal_emit_by_name(view, "motion_notify_event", &event, &return_val); } return JSValueMakeUndefined(context); }
static JSValueRef childAtIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { int indexNumber = -1; if (argumentCount == 1) indexNumber = JSValueToNumber(context, arguments[0], exception); return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->getChildAtIndex(indexNumber)); }
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)); }
static JSValueRef lineForIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { int indexNumber = -1; if (argumentCount == 1) indexNumber = JSValueToNumber(context, arguments[0], exception); return JSValueMakeNumber(context, toAXElement(thisObject)->lineForIndex(indexNumber)); }
static JSValueRef mouseWheelToCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); if (argumentCount < 2) return JSValueMakeUndefined(context); int horizontal = (int)JSValueToNumber(context, arguments[0], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); int vertical = (int)JSValueToNumber(context, arguments[1], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); // GTK+ doesn't support multiple direction scrolls in the same event! g_return_val_if_fail((!vertical || !horizontal), JSValueMakeUndefined(context)); GdkEvent event; event.type = GDK_SCROLL; event.scroll.x = lastMousePositionX; event.scroll.y = lastMousePositionY; event.scroll.time = GDK_CURRENT_TIME; event.scroll.window = GTK_WIDGET(view)->window; if (horizontal < 0) event.scroll.direction = GDK_SCROLL_LEFT; else if (horizontal > 0) event.scroll.direction = GDK_SCROLL_RIGHT; else if (vertical < 0) event.scroll.direction = GDK_SCROLL_UP; else if (vertical > 0) event.scroll.direction = GDK_SCROLL_DOWN; else g_assert_not_reached(); if (dragMode && down && !replayingSavedEvents) { msgQueue[endOfQueue].event = event; msgQueue[endOfQueue++].isDragEvent = true; } else { webkit_web_frame_layout(mainFrame); gtk_main_do_event(&event); } return JSValueMakeUndefined(context); }
static JSValueRef leapForwardCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount > 0) { msgQueue[endOfQueue].delay = JSValueToNumber(context, arguments[0], exception); ASSERT(!exception || !*exception); } return JSValueMakeUndefined(context); }
static JSValueRef rangeForLineCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { int indexNumber = -1; if (argumentCount == 1) indexNumber = JSValueToNumber(context, arguments[0], exception); JSRetainPtr<JSStringRef> rangeLine(Adopt, toAXElement(thisObject)->rangeForLine(indexNumber)); return JSValueMakeString(context, rangeLine.get()); }
static double numericWindowPropertyValue(WKBundleFrameRef frame, const char* propertyName) { JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); JSValueRef value = propertyValue(context, JSContextGetGlobalObject(context), propertyName); if (!value) return 0; JSValueRef exception; return JSValueToNumber(context, value, &exception); }
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; }
JSValueRef JSCArrayBuffer::sliceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj); if (false) { } else if (argumentCount == 2 && JSValueIsNumber(ctx, arguments[0]) && JSValueIsNumber(ctx, arguments[1])) { long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception); long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); JSClassRef retClass = JSCArrayBuffer::getTmpl(); struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); return retObj; } else if (argumentCount == 1 && JSValueIsNumber(ctx, arguments[0])) { long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception); uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin)); JSClassRef retClass = JSCArrayBuffer::getTmpl(); struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); return retObj; } JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling slice"); *exception = JSValueMakeString(ctx, exceptionString); JSStringRelease(exceptionString); return JSValueMakeUndefined(ctx); }
double WebViewTest::javascriptResultToNumber(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(JSValueIsNumber(context, value)); return JSValueToNumber(context, value, 0); }
JSValueRef setMarginsForJava_android_widget_FrameLayout_LayoutParams(JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { JSPrivateObject* p = (JSPrivateObject*)JSObjectGetPrivate(object); if (p && p->object && argumentCount >= 4) { int arg0 = JSValueToNumber(ctx, arguments[0], exception); int arg1 = JSValueToNumber(ctx, arguments[1], exception); int arg2 = JSValueToNumber(ctx, arguments[2], exception); int arg3 = JSValueToNumber(ctx, arguments[3], exception); JNI_ENV_ENTER jclass javaClass = (*env)->FindClass(env, "android/widget/FrameLayout$LayoutParams"); if (javaClass == NULL) return HyperloopMakeException(ctx, "Class not found: android.widget.FrameLayout$LayoutParams", exception); jmethodID methodId = (*env)->GetMethodID(env, javaClass, "setMargins", "(IIII)V"); if (methodId == NULL) return HyperloopMakeException(ctx, "Method not found: android.widget.FrameLayout$LayoutParams#setMargins", exception); (*env)->DeleteLocalRef(env, javaClass); (*env)->CallVoidMethod(env, p->object, methodId, arg0, arg1, arg2, arg3); JNI_ENV_EXIT }
static void assertEqualsAsNumber(JSValueRef value, double expectedValue) { double number = JSValueToNumber(context, value, NULL); // FIXME <rdar://4668451> - On i386 the isnan(double) macro tries to map to the isnan(float) function, // causing a build break with -Wshorten-64-to-32 enabled. The issue is known by the appropriate team. // After that's resolved, we can remove these casts if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue))) fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue); }
static JSValueRef mouseDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); down = true; GdkEvent event; memset(&event, 0, sizeof(event)); event.type = GDK_BUTTON_PRESS; event.button.button = 1; if (argumentCount == 1) { event.button.button = (int)JSValueToNumber(context, arguments[0], exception) + 1; g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); } currentEventButton = event.button.button; event.button.x = lastMousePositionX; event.button.y = lastMousePositionY; event.button.window = GTK_WIDGET(view)->window; event.button.time = GDK_CURRENT_TIME; event.button.device = gdk_device_get_core_pointer(); int x_root, y_root; #if GTK_CHECK_VERSION(2,17,3) gdk_window_get_root_coords(GTK_WIDGET(view)->window, lastMousePositionX, lastMousePositionY, &x_root, &y_root); #else getRootCoords(GTK_WIDGET(view), &x_root, &y_root); #endif event.button.x_root = x_root; event.button.y_root = y_root; updateClickCount(event.button.button); if (!msgQueue[endOfQueue].delay) { webkit_web_frame_layout(mainFrame); gboolean return_val; g_signal_emit_by_name(view, "button_press_event", &event, &return_val); if (clickCount == 2) { event.type = GDK_2BUTTON_PRESS; g_signal_emit_by_name(view, "button_press_event", &event, &return_val); } } else { // replaySavedEvents should have the required logic to make leapForward delays work msgQueue[endOfQueue++].event = event; replaySavedEvents(); } return JSValueMakeUndefined(context); }