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; }
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); }
gboolean filter_function_child(JSContextRef ctx, JSValueRef jsvalue, int i) { JSObjectRef p =JSValueToObject(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), NULL); if (p == NULL) { return FALSE; } return JSObjectIsFunction(ctx, p); }
Value Object::getPropertyAtIndex(unsigned index) const { JSValueRef exn; JSValueRef property = JSObjectGetPropertyAtIndex(m_context, m_obj, index, &exn); if (!property) { std::string exceptionText = Value(m_context, exn).toString().str(); throwJSExecutionException("Failed to get property at index %u: %s", index, exceptionText.c_str()); } return Value(m_context, property); }
// // Returns the contents of the array as an array of JSValueRef. // The caller is responsible for deleting the array returned by this method. // JSValueRef* ArrayWrapper::AsArray() { size_t len = GetSize(); JSValueRef* array = new JSValueRef[len]; for (size_t i = 0; i < len; ++i) { array[i] = JSObjectGetPropertyAtIndex(g_ctx, m_arr, (int) i, NULL); JSValueProtect(g_ctx, array[i]); } return array; }
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(JSObjectGetPropertyAtIndex) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2, jintLongArray arg3) { jintLong *lparg3=NULL; jintLong rc = 0; WebKit_win32_NATIVE_ENTER(env, that, JSObjectGetPropertyAtIndex_FUNC); if (arg3) if ((lparg3 = env->GetIntLongArrayElements(arg3, NULL)) == NULL) goto fail; rc = (jintLong)JSObjectGetPropertyAtIndex((JSContextRef)arg0, (JSObjectRef)arg1, (unsigned)arg2, (JSValueRef*)lparg3); fail: if (arg3 && lparg3) env->ReleaseIntLongArrayElements(arg3, lparg3, 0); WebKit_win32_NATIVE_EXIT(env, that, JSObjectGetPropertyAtIndex_FUNC); return rc; }
template<> std::string RJSAccessor::to_binary(JSContextRef ctx, JSValueRef &val) { static JSStringRef arrayBufferString = JSStringCreateWithUTF8CString("ArrayBuffer"); static JSStringRef bufferString = JSStringCreateWithUTF8CString("buffer"); static JSStringRef byteLengthString = JSStringCreateWithUTF8CString("byteLength"); static JSStringRef byteOffsetString = JSStringCreateWithUTF8CString("byteOffset"); static JSStringRef isViewString = JSStringCreateWithUTF8CString("isView"); static JSStringRef uint8ArrayString = JSStringCreateWithUTF8CString("Uint8Array"); JSObjectRef arrayBufferConstructor = RJSValidatedObjectProperty(ctx, JSContextGetGlobalObject(ctx), arrayBufferString); JSObjectRef uint8ArrayContructor = RJSValidatedObjectProperty(ctx, JSContextGetGlobalObject(ctx), uint8ArrayString); JSValueRef uint8ArrayArguments[3]; size_t uint8ArrayArgumentsCount = 0; // Value should either be an ArrayBuffer or ArrayBufferView (i.e. TypedArray or DataView). if (JSValueIsInstanceOfConstructor(ctx, val, arrayBufferConstructor, NULL)) { uint8ArrayArguments[0] = val; uint8ArrayArgumentsCount = 1; } else if (JSObjectRef object = JSValueToObject(ctx, val, NULL)) { // Check if value is an ArrayBufferView by calling ArrayBuffer.isView(val). JSObjectRef isViewMethod = RJSValidatedObjectProperty(ctx, arrayBufferConstructor, isViewString); JSValueRef isView = JSObjectCallAsFunction(ctx, isViewMethod, arrayBufferConstructor, 1, &val, NULL); if (isView && JSValueToBoolean(ctx, isView)) { uint8ArrayArguments[0] = RJSValidatedObjectProperty(ctx, object, bufferString); uint8ArrayArguments[1] = RJSValidatedPropertyValue(ctx, object, byteOffsetString); uint8ArrayArguments[2] = RJSValidatedPropertyValue(ctx, object, byteLengthString); uint8ArrayArgumentsCount = 3; } } if (!uint8ArrayArgumentsCount) { throw std::runtime_error("Can only convert ArrayBuffer and TypedArray objects to binary"); } JSValueRef exception = NULL; JSObjectRef uint8Array = JSObjectCallAsConstructor(ctx, uint8ArrayContructor, uint8ArrayArgumentsCount, uint8ArrayArguments, &exception); if (exception) { throw RJSException(ctx, exception); } size_t byteCount = RJSValidatedListLength(ctx, uint8Array); std::string bytes(byteCount, 0); for (size_t i = 0; i < byteCount; i++) { JSValueRef byteValue = JSObjectGetPropertyAtIndex(ctx, uint8Array, (unsigned)i, NULL); bytes[i] = JSValueToNumber(ctx, byteValue, NULL); } return bytes; }
JSValue JSObject::GetProperty(unsigned property_index) const { HAL_JSOBJECT_LOCK_GUARD; JSValueRef exception { nullptr }; JSValueRef js_value_ref = JSObjectGetPropertyAtIndex(static_cast<JSContextRef>(js_context__), js_object_ref__, property_index, &exception); if (exception) { // If this assert fails then we need to JSValueUnprotect // js_value_ref. assert(!js_value_ref); detail::ThrowRuntimeError("JSObject", JSValue(js_context__, exception)); } assert(js_value_ref); return JSValue(js_context__, js_value_ref); }
static JSValueRef js_cb_launcher_submit(JSContextRef context, JSObjectRef function, JSObjectRef self, size_t argc, const JSValueRef argv[], JSValueRef* exception) { if (argc != 2) return JSValueMakeNull(context); int len = JSValueToNumber(context, argv[0], NULL); JSObjectRef arr = JSValueToObject(context, argv[1], NULL); static const int CMD_LINE_SIZE = 4096; static const int CMD_ARGS_SIZE = 256; char cmd_str_buf[CMD_LINE_SIZE]; int cmd_str_buf_cur = 0; char *cmd_idx_buf[CMD_ARGS_SIZE]; if (len == 0 || len >= CMD_ARGS_SIZE) return JSValueMakeNull(context); int i; for (i = 0; i < len; ++ i) { JSValueRef cur = JSObjectGetPropertyAtIndex(context, arr, i, NULL); JSStringRef str = JSValueToStringCopy(context, cur, NULL); size_t l = JSStringGetUTF8CString(str, cmd_str_buf + cmd_str_buf_cur, CMD_LINE_SIZE - cmd_str_buf_cur); cmd_idx_buf[i] = cmd_str_buf + cmd_str_buf_cur; cmd_str_buf_cur += l; JSStringRelease(str); JSValueUnprotect(context, cur); } cmd_idx_buf[i] = 0; if (fork() == 0) { /* Redirect I/O streams */ freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); execvp(cmd_idx_buf[0], cmd_idx_buf); fprintf(stderr, "RETURNED"); exit(1); } return JSValueMakeNull(context); }
NATIVE(JSObject,jobject,getPropertyAtIndex) (PARAMS, jlong ctx, jlong object, jint propertyIndex) { JSValueRef exception = NULL; jclass ret = env->FindClass("org/liquidplayer/webkit/javascriptcore/JNIReturnObject"); jmethodID cid = env->GetMethodID(ret,"<init>","()V"); jobject out = env->NewObject(ret, cid); jfieldID fid = env->GetFieldID(ret , "reference", "J"); env->SetLongField( out, fid, (long) JSObjectGetPropertyAtIndex((JSContextRef) ctx, (JSObjectRef)object, (unsigned)propertyIndex, &exception)); fid = env->GetFieldID(ret , "exception", "J"); env->SetLongField( out, fid, (long) exception); return out; }
static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue) { if (!arrayValue) return 0; if (!JSValueIsObject(context, arrayValue)) return 0; JSObjectRef array = const_cast<JSObjectRef>(arrayValue); unsigned length = arrayLength(context, array); WKEventModifiers modifiers = 0; for (unsigned i = 0; i < length; i++) { JSValueRef exception = 0; JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception); if (exception) continue; JSRetainPtr<JSStringRef> string(Adopt, JSValueToStringCopy(context, value, &exception)); if (exception) continue; modifiers |= parseModifier(string.get()); } return modifiers; }
bool TestRunner::findString(JSStringRef target, JSValueRef optionsArrayAsValue) { WKFindOptions options = 0; auto& injectedBundle = InjectedBundle::singleton(); WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length")); JSObjectRef optionsArray = JSValueToObject(context, optionsArrayAsValue, 0); JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); if (!JSValueIsNumber(context, lengthValue)) return false; 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 (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive")) options |= kWKFindOptionsCaseInsensitive; else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts")) options |= kWKFindOptionsAtWordStarts; else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart")) options |= kWKFindOptionsTreatMedialCapitalAsWordStart; else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards")) options |= kWKFindOptionsBackwards; else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround")) options |= kWKFindOptionsWrapAround; else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) { // FIXME: No kWKFindOptionsStartInSelection. } } return WKBundlePageFindString(injectedBundle.page()->page(), toWK(target).get(), options); }
static WPARAM buildModifierFlags(JSContextRef context, const JSValueRef modifiers) { JSObjectRef modifiersArray = JSValueToObject(context, modifiers, 0); if (!modifiersArray) return 0; WPARAM flags = 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")) flags |= MK_CONTROL; else if (JSStringIsEqualToUTF8CString(string, "shiftKey") || JSStringIsEqualToUTF8CString(string, "rangeSelectionKey")) flags |= MK_SHIFT; // No way to specifiy altKey in a MSG. JSStringRelease(string); } return flags; }
bool LayoutTestController::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray) { WebKitFindOptions findOptions = 0; WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); ASSERT(webView); JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length")); JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); if (!JSValueIsNumber(context, lengthValue)) return false; GOwnPtr<gchar> targetString(JSStringCopyUTF8CString(target)); 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 (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive")) findOptions |= WebKit::WebFindOptionsCaseInsensitive; else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts")) findOptions |= WebKit::WebFindOptionsAtWordStarts; else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart")) findOptions |= WebKit::WebFindOptionsTreatMedialCapitalAsWordStart; else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards")) findOptions |= WebKit::WebFindOptionsBackwards; else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround")) findOptions |= WebKit::WebFindOptionsWrapAround; else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) findOptions |= WebKit::WebFindOptionsStartInSelection; } return DumpRenderTreeSupportGtk::findString(webView, targetString.get(), findOptions); }
static JSValueRef beginDragWithFilesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); JSObjectRef filesArray = JSValueToObject(context, arguments[0], 0); if (!filesArray) return JSValueMakeUndefined(context); JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); Vector<UChar> files; int filesCount = JSValueToNumber(context, JSObjectGetProperty(context, filesArray, lengthProperty, 0), 0); for (int i = 0; i < filesCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, filesArray, i, 0); JSStringRef file = JSValueToStringCopy(context, value, 0); files.append(JSStringGetCharactersPtr(file), JSStringGetLength(file)); files.append(0); JSStringRelease(file); } if (files.isEmpty()) return JSValueMakeUndefined(context); // We should append "0" in the end of |files| so that |DragQueryFileW| retrieved the number of files correctly from Ole Clipboard. files.append(0); STGMEDIUM hDropMedium = {0}; hDropMedium.tymed = TYMED_HGLOBAL; SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * files.size()); hDropMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, dropFilesSize); DROPFILES* dropFiles = reinterpret_cast<DROPFILES*>(GlobalLock(hDropMedium.hGlobal)); memset(dropFiles, 0, sizeof(DROPFILES)); dropFiles->pFiles = sizeof(DROPFILES); dropFiles->fWide = TRUE; UChar* data = reinterpret_cast<UChar*>(reinterpret_cast<BYTE*>(dropFiles) + sizeof(DROPFILES)); for (size_t i = 0; i < files.size(); ++i) data[i] = files[i]; GlobalUnlock(hDropMedium.hGlobal); STGMEDIUM hFileNameMedium = {0}; hFileNameMedium.tymed = TYMED_HGLOBAL; SIZE_T hFileNameSize = sizeof(WCHAR) * files.size(); hFileNameMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, hFileNameSize); WCHAR* hFileName = static_cast<WCHAR*>(GlobalLock(hFileNameMedium.hGlobal)); for (size_t i = 0; i < files.size(); i++) hFileName[i] = files[i]; GlobalUnlock(hFileNameMedium.hGlobal); if (draggingInfo) { delete draggingInfo; draggingInfo = 0; } COMPtr<DRTDataObject> dataObeject; COMPtr<IDropSource> source; if (FAILED(DRTDataObject::createInstance(&dataObeject))) dataObeject = 0; if (FAILED(DRTDropSource::createInstance(&source))) source = 0; if (dataObeject && source) { draggingInfo = new DraggingInfo(dataObeject.get(), source.get()); draggingInfo->setPerformedDropEffect(DROPEFFECT_COPY); } if (draggingInfo) { draggingInfo->dataObject()->SetData(cfHDropFormat(), &hDropMedium, FALSE); draggingInfo->dataObject()->SetData(cfFileNameWFormat(), &hFileNameMedium, FALSE); draggingInfo->dataObject()->SetData(cfUrlWFormat(), &hFileNameMedium, FALSE); OleSetClipboard(draggingInfo->dataObject()); down = true; } JSStringRelease(lengthProperty); return JSValueMakeUndefined(context); }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static const JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); COMPtr<IWebFramePrivate> framePrivate; if (SUCCEEDED(frame->QueryInterface(&framePrivate))) framePrivate->layout(); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); ASSERT(!*exception); int virtualKeyCode; int charCode = 0; int keyData = 1; bool needsShiftKeyModifier = false; if (JSStringIsEqualToUTF8CString(character, "leftArrow")) { virtualKeyCode = VK_LEFT; keyData += KF_EXTENDED << 16; // In this case, extended means "not keypad". } else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) { virtualKeyCode = VK_RIGHT; keyData += KF_EXTENDED << 16; } else if (JSStringIsEqualToUTF8CString(character, "upArrow")) { virtualKeyCode = VK_UP; keyData += KF_EXTENDED << 16; } else if (JSStringIsEqualToUTF8CString(character, "downArrow")) { virtualKeyCode = VK_DOWN; keyData += KF_EXTENDED << 16; } else if (JSStringIsEqualToUTF8CString(character, "pageUp")) virtualKeyCode = VK_PRIOR; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) virtualKeyCode = VK_NEXT; else if (JSStringIsEqualToUTF8CString(character, "home")) virtualKeyCode = VK_HOME; else if (JSStringIsEqualToUTF8CString(character, "end")) virtualKeyCode = VK_END; else if (JSStringIsEqualToUTF8CString(character, "insert")) virtualKeyCode = VK_INSERT; else if (JSStringIsEqualToUTF8CString(character, "delete")) virtualKeyCode = VK_DELETE; else if (JSStringIsEqualToUTF8CString(character, "printScreen")) virtualKeyCode = VK_SNAPSHOT; else if (JSStringIsEqualToUTF8CString(character, "menu")) virtualKeyCode = VK_APPS; else if (JSStringIsEqualToUTF8CString(character, "leftControl")) { virtualKeyCode = VK_CONTROL; keyData += makeKeyDataForScanCode(VK_LCONTROL); } else if (JSStringIsEqualToUTF8CString(character, "leftShift")) { virtualKeyCode = VK_SHIFT; keyData += makeKeyDataForScanCode(VK_LSHIFT); } else if (JSStringIsEqualToUTF8CString(character, "leftAlt")) { virtualKeyCode = VK_MENU; keyData += makeKeyDataForScanCode(VK_LMENU); } else if (JSStringIsEqualToUTF8CString(character, "rightControl")) { virtualKeyCode = VK_CONTROL; keyData += makeKeyDataForScanCode(VK_RCONTROL); } else if (JSStringIsEqualToUTF8CString(character, "rightShift")) { virtualKeyCode = VK_SHIFT; keyData += makeKeyDataForScanCode(VK_RSHIFT); } else if (JSStringIsEqualToUTF8CString(character, "rightAlt")) { virtualKeyCode = VK_MENU; keyData += makeKeyDataForScanCode(VK_RMENU); } else { charCode = JSStringGetCharactersPtr(character)[0]; virtualKeyCode = LOBYTE(VkKeyScan(charCode)); if (WTF::isASCIIUpper(charCode)) needsShiftKeyModifier = true; } JSStringRelease(character); BYTE keyState[256]; if (argumentCount > 1 || needsShiftKeyModifier) { ::GetKeyboardState(keyState); BYTE newKeyState[256]; memcpy(newKeyState, keyState, sizeof(keyState)); if (needsShiftKeyModifier) newKeyState[VK_SHIFT] = 0x80; if (argumentCount > 1) { JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], 0); if (modifiersArray) { int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 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")) newKeyState[VK_CONTROL] = 0x80; else if (JSStringIsEqualToUTF8CString(string, "shiftKey") || JSStringIsEqualToUTF8CString(string, "rangeSelectionKey")) newKeyState[VK_SHIFT] = 0x80; else if (JSStringIsEqualToUTF8CString(string, "altKey")) newKeyState[VK_MENU] = 0x80; JSStringRelease(string); } } } ::SetKeyboardState(newKeyState); } MSG msg = makeMsg(webViewWindow, (::GetKeyState(VK_MENU) & 0x8000) ? WM_SYSKEYDOWN : WM_KEYDOWN, virtualKeyCode, keyData); if (virtualKeyCode != 255) dispatchMessage(&msg); else { // For characters that do not exist in the active keyboard layout, // ::Translate will not work, so we post an WM_CHAR event ourselves. ::PostMessage(webViewWindow, WM_CHAR, charCode, 0); } // Tests expect that all messages are processed by the time keyDown() returns. if (::PeekMessage(&msg, webViewWindow, WM_CHAR, WM_CHAR, PM_REMOVE) || ::PeekMessage(&msg, webViewWindow, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE)) ::DispatchMessage(&msg); MSG msgUp = makeMsg(webViewWindow, (::GetKeyState(VK_MENU) & 0x8000) ? WM_SYSKEYUP : WM_KEYUP, virtualKeyCode, keyData); ::DispatchMessage(&msgUp); if (argumentCount > 1 || needsShiftKeyModifier) ::SetKeyboardState(keyState); return JSValueMakeUndefined(context); }
JSObjectRef JSCInt16Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { uscxml::Int16Array* localInstance = NULL; if (false) { } else if (argumentCount == 3 && JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && JSValueIsNumber(ctx, arguments[1]) && JSValueIsNumber(ctx, arguments[2])) { uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); localInstance = new uscxml::Int16Array(localBuffer, localByteOffset, localLength); } else if (argumentCount == 2 && JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && JSValueIsNumber(ctx, arguments[1])) { uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); localInstance = new uscxml::Int16Array(localBuffer, localByteOffset); } else if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl())) { uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; localInstance = new uscxml::Int16Array(localArray); } else if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; localInstance = new uscxml::Int16Array(localBuffer); } else if (argumentCount == 1 && JSValueIsNumber(ctx, arguments[0])) { unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); localInstance = new uscxml::Int16Array(localLength); } else if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0])) { std::vector<short> localArray; JSValueRef localArrayItem; unsigned int localArrayIndex = 0; while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { if (JSValueIsUndefined(ctx, localArrayItem)) break; if (JSValueIsNumber(ctx,localArrayItem)) localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); localArrayIndex++; } localInstance = new uscxml::Int16Array(localArray); } if (!localInstance) { JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Int16Array"); *exception = JSValueMakeString(ctx, exceptionString); JSStringRelease(exceptionString); return (JSObjectRef)JSValueMakeNull(ctx); } JSClassRef retClass = JSCInt16Array::getTmpl(); struct JSCInt16Array::JSCInt16ArrayPrivate* retPrivData = new JSCInt16Array::JSCInt16ArrayPrivate(); retPrivData->nativeObj = localInstance; JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); return retObj; }
GVariant* js_to_dbus(JSContextRef ctx, const JSValueRef jsvalue, const GVariantType* sig, JSValueRef *exception) { if (g_variant_type_is_array(sig)) { GVariantBuilder builder; g_variant_builder_init(&builder, sig); JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue); const GVariantType* child_sig = g_variant_type_element(sig); if (g_variant_type_is_dict_entry(child_sig)) { const GVariantType* key_sig = g_variant_type_first(child_sig); const GVariantType* value_sig = g_variant_type_next(key_sig); for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) { if (filter_function_child(ctx, jsvalue, i)) continue; g_variant_builder_open(&builder, child_sig); JSValueRef key = JSValueMakeString(ctx, JSPropertyNameArrayGetNameAtIndex(array, i)); JSValueRef value = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL); g_variant_builder_add_value(&builder, js_to_dbus(ctx, key, key_sig, exception)); g_variant_builder_add_value(&builder, js_to_dbus(ctx, value, value_sig, exception)); g_variant_builder_close(&builder); } return g_variant_builder_end(&builder); } else { GVariantBuilder builder; g_variant_builder_init(&builder, sig); JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue); const GVariantType* child_sig = g_variant_type_element(sig); for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) { if (filter_array_child(ctx, array, i)) continue; g_variant_builder_add_value(&builder, js_to_dbus(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), child_sig, exception)); } JSPropertyNameArrayRelease(array); return g_variant_builder_end(&builder); } } else if (g_variant_type_is_tuple(sig)) { GVariantBuilder builder; g_variant_builder_init(&builder, sig); JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue); const GVariantType* current_sig = g_variant_type_first(sig); for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) { if (filter_array_child(ctx, array, i)) continue; g_variant_builder_add_value(&builder, js_to_dbus(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), current_sig, exception)); current_sig = g_variant_type_next(current_sig); } JSPropertyNameArrayRelease(array); return g_variant_builder_end(&builder); } else { switch (g_variant_type_peek_string(sig)[0]) { case 'y': return g_variant_new_byte(JSValueToNumber(ctx, jsvalue, exception)); case 'n': return g_variant_new_int16(JSValueToNumber(ctx, jsvalue, exception)); case 'q': return g_variant_new_uint16(JSValueToNumber(ctx, jsvalue, exception)); case 'i': return g_variant_new_int32(JSValueToNumber(ctx, jsvalue, exception)); case 'u': return g_variant_new_uint32(JSValueToNumber(ctx, jsvalue, exception)); case 'x': return g_variant_new_int64(JSValueToNumber(ctx, jsvalue, exception)); case 't': return g_variant_new_uint64(JSValueToNumber(ctx, jsvalue, exception)); case 'd': return g_variant_new_double(JSValueToNumber(ctx, jsvalue, exception)); case 'h': return g_variant_new_handle(JSValueToNumber(ctx, jsvalue, exception)); case 'b': return g_variant_new_boolean(JSValueToBoolean(ctx, jsvalue)); case 's': { char* v = jsvalue_to_cstr(ctx, jsvalue); GVariant* r = g_variant_new_string(v); g_free(v); return r; } case 'v': { //TODO: /*g_variant_new_variant()*/ g_assert_not_reached(); } } } g_assert_not_reached(); }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static JSStringRef ctrlKey = JSStringCreateWithUTF8CString("ctrlKey"); static JSStringRef shiftKey = JSStringCreateWithUTF8CString("shiftKey"); static JSStringRef altKey = JSStringCreateWithUTF8CString("altKey"); static JSStringRef metaKey = JSStringCreateWithUTF8CString("metaKey"); static JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); COMPtr<IWebFramePrivate> framePrivate; if (SUCCEEDED(frame->QueryInterface(&framePrivate))) framePrivate->layout(); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); ASSERT(!exception || !*exception); int charCode = JSStringGetCharactersPtr(character)[0]; int virtualKeyCode = toupper(LOBYTE(VkKeyScan(charCode))); JSStringRelease(character); // Hack to map option-delete to ctrl-delete // Remove this when we fix <rdar://problem/5102974> layout tests need a way to decide how to choose the appropriate modifier keys bool convertOptionToCtrl = false; if (virtualKeyCode == VK_DELETE || virtualKeyCode == VK_BACK) convertOptionToCtrl = true; BYTE keyState[256]; if (argumentCount > 1) { ::GetKeyboardState(keyState); BYTE newKeyState[256]; memcpy(newKeyState, keyState, sizeof(keyState)); JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception); if (modifiersArray) { int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); for (int i = 0; i < modifiersCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqual(string, ctrlKey)) newKeyState[VK_CONTROL] = 0x80; else if (JSStringIsEqual(string, shiftKey)) newKeyState[VK_SHIFT] = 0x80; else if (JSStringIsEqual(string, altKey)) { if (convertOptionToCtrl) newKeyState[VK_CONTROL] = 0x80; else newKeyState[VK_MENU] = 0x80; } else if (JSStringIsEqual(string, metaKey)) newKeyState[VK_MENU] = 0x80; JSStringRelease(string); } } ::SetKeyboardState(newKeyState); } MSG msg = makeMsg(webViewWindow, WM_KEYDOWN, virtualKeyCode, 0); dispatchMessage(&msg); if (argumentCount > 1) ::SetKeyboardState(keyState); return JSValueMakeUndefined(context); }
int main(int argc, char* argv[]) { const char *scriptPath = "testapi.js"; if (argc > 1) { scriptPath = argv[1]; } // Test garbage collection with a fresh context context = JSGlobalContextCreateInGroup(NULL, NULL); TestInitializeFinalize = true; testInitializeFinalize(); JSGlobalContextRelease(context); TestInitializeFinalize = false; ASSERT(Base_didFinalize); JSClassDefinition globalObjectClassDefinition = kJSClassDefinitionEmpty; globalObjectClassDefinition.initialize = globalObject_initialize; globalObjectClassDefinition.staticValues = globalObject_staticValues; globalObjectClassDefinition.staticFunctions = globalObject_staticFunctions; globalObjectClassDefinition.attributes = kJSClassAttributeNoAutomaticPrototype; JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition); context = JSGlobalContextCreateInGroup(NULL, globalObjectClass); JSGlobalContextRetain(context); JSGlobalContextRelease(context); JSObjectRef globalObject = JSContextGetGlobalObject(context); ASSERT(JSValueIsObject(context, globalObject)); JSValueRef jsUndefined = JSValueMakeUndefined(context); JSValueRef jsNull = JSValueMakeNull(context); JSValueRef jsTrue = JSValueMakeBoolean(context, true); JSValueRef jsFalse = JSValueMakeBoolean(context, false); JSValueRef jsZero = JSValueMakeNumber(context, 0); JSValueRef jsOne = JSValueMakeNumber(context, 1); JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0); JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL); JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context)); // FIXME: test funny utf8 characters JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString(""); JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString); JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1"); JSValueRef jsOneString = JSValueMakeString(context, jsOneIString); UniChar singleUniChar = 65; // Capital A CFMutableStringRef cfString = CFStringCreateMutableWithExternalCharactersNoCopy(kCFAllocatorDefault, &singleUniChar, 1, 1, kCFAllocatorNull); JSStringRef jsCFIString = JSStringCreateWithCFString(cfString); JSValueRef jsCFString = JSValueMakeString(context, jsCFIString); CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString); JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString); CFIndex cfStringLength = CFStringGetLength(cfString); UniChar* buffer = (UniChar*)malloc(cfStringLength * sizeof(UniChar)); CFStringGetCharacters(cfString, CFRangeMake(0, cfStringLength), buffer); JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, cfStringLength); JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters); JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, CFStringGetLength(cfEmptyString)); free(buffer); JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters); ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined); ASSERT(JSValueGetType(context, jsNull) == kJSTypeNull); ASSERT(JSValueGetType(context, jsTrue) == kJSTypeBoolean); ASSERT(JSValueGetType(context, jsFalse) == kJSTypeBoolean); ASSERT(JSValueGetType(context, jsZero) == kJSTypeNumber); ASSERT(JSValueGetType(context, jsOne) == kJSTypeNumber); ASSERT(JSValueGetType(context, jsOneThird) == kJSTypeNumber); ASSERT(JSValueGetType(context, jsEmptyString) == kJSTypeString); ASSERT(JSValueGetType(context, jsOneString) == kJSTypeString); ASSERT(JSValueGetType(context, jsCFString) == kJSTypeString); ASSERT(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString); ASSERT(JSValueGetType(context, jsCFEmptyString) == kJSTypeString); ASSERT(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString); JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject"); JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL); JSStringRelease(myObjectIString); JSValueRef exception; // Conversions that throw exceptions exception = NULL; ASSERT(NULL == JSValueToObject(context, jsNull, &exception)); ASSERT(exception); exception = 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 ASSERT(isnan((float)JSValueToNumber(context, jsObjectNoProto, &exception))); ASSERT(exception); exception = NULL; ASSERT(!JSValueToStringCopy(context, jsObjectNoProto, &exception)); ASSERT(exception); ASSERT(JSValueToBoolean(context, myObject)); exception = NULL; ASSERT(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(context, 1), &exception)); ASSERT(exception); exception = NULL; JSObjectGetPropertyAtIndex(context, myObject, 0, &exception); ASSERT(1 == JSValueToNumber(context, exception, NULL)); assertEqualsAsBoolean(jsUndefined, false); assertEqualsAsBoolean(jsNull, false); assertEqualsAsBoolean(jsTrue, true); assertEqualsAsBoolean(jsFalse, false); assertEqualsAsBoolean(jsZero, false); assertEqualsAsBoolean(jsOne, true); assertEqualsAsBoolean(jsOneThird, true); assertEqualsAsBoolean(jsEmptyString, false); assertEqualsAsBoolean(jsOneString, true); assertEqualsAsBoolean(jsCFString, true); assertEqualsAsBoolean(jsCFStringWithCharacters, true); assertEqualsAsBoolean(jsCFEmptyString, false); assertEqualsAsBoolean(jsCFEmptyStringWithCharacters, false); assertEqualsAsNumber(jsUndefined, nan("")); assertEqualsAsNumber(jsNull, 0); assertEqualsAsNumber(jsTrue, 1); assertEqualsAsNumber(jsFalse, 0); assertEqualsAsNumber(jsZero, 0); assertEqualsAsNumber(jsOne, 1); assertEqualsAsNumber(jsOneThird, 1.0 / 3.0); assertEqualsAsNumber(jsEmptyString, 0); assertEqualsAsNumber(jsOneString, 1); assertEqualsAsNumber(jsCFString, nan("")); assertEqualsAsNumber(jsCFStringWithCharacters, nan("")); assertEqualsAsNumber(jsCFEmptyString, 0); assertEqualsAsNumber(jsCFEmptyStringWithCharacters, 0); ASSERT(sizeof(JSChar) == sizeof(UniChar)); assertEqualsAsCharactersPtr(jsUndefined, "undefined"); assertEqualsAsCharactersPtr(jsNull, "null"); assertEqualsAsCharactersPtr(jsTrue, "true"); assertEqualsAsCharactersPtr(jsFalse, "false"); assertEqualsAsCharactersPtr(jsZero, "0"); assertEqualsAsCharactersPtr(jsOne, "1"); assertEqualsAsCharactersPtr(jsOneThird, "0.3333333333333333"); assertEqualsAsCharactersPtr(jsEmptyString, ""); assertEqualsAsCharactersPtr(jsOneString, "1"); assertEqualsAsCharactersPtr(jsCFString, "A"); assertEqualsAsCharactersPtr(jsCFStringWithCharacters, "A"); assertEqualsAsCharactersPtr(jsCFEmptyString, ""); assertEqualsAsCharactersPtr(jsCFEmptyStringWithCharacters, ""); assertEqualsAsUTF8String(jsUndefined, "undefined"); assertEqualsAsUTF8String(jsNull, "null"); assertEqualsAsUTF8String(jsTrue, "true"); assertEqualsAsUTF8String(jsFalse, "false"); assertEqualsAsUTF8String(jsZero, "0"); assertEqualsAsUTF8String(jsOne, "1"); assertEqualsAsUTF8String(jsOneThird, "0.3333333333333333"); assertEqualsAsUTF8String(jsEmptyString, ""); assertEqualsAsUTF8String(jsOneString, "1"); assertEqualsAsUTF8String(jsCFString, "A"); assertEqualsAsUTF8String(jsCFStringWithCharacters, "A"); assertEqualsAsUTF8String(jsCFEmptyString, ""); assertEqualsAsUTF8String(jsCFEmptyStringWithCharacters, ""); ASSERT(JSValueIsStrictEqual(context, jsTrue, jsTrue)); ASSERT(!JSValueIsStrictEqual(context, jsOne, jsOneString)); ASSERT(JSValueIsEqual(context, jsOne, jsOneString, NULL)); ASSERT(!JSValueIsEqual(context, jsTrue, jsFalse, NULL)); CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString); CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString); ASSERT(CFEqual(cfJSString, cfString)); ASSERT(CFEqual(cfJSEmptyString, cfEmptyString)); CFRelease(cfJSString); CFRelease(cfJSEmptyString); CFRelease(cfString); CFRelease(cfEmptyString); jsGlobalValue = JSObjectMake(context, NULL, NULL); JSValueProtect(context, jsGlobalValue); JSGarbageCollect(context); ASSERT(JSValueIsObject(context, jsGlobalValue)); JSValueUnprotect(context, jsGlobalValue); JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;"); JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;"); ASSERT(JSCheckScriptSyntax(context, goodSyntax, NULL, 0, NULL)); ASSERT(!JSCheckScriptSyntax(context, badSyntax, NULL, 0, NULL)); JSValueRef result; JSValueRef v; JSObjectRef o; JSStringRef string; result = JSEvaluateScript(context, goodSyntax, NULL, NULL, 1, NULL); ASSERT(result); ASSERT(JSValueIsEqual(context, result, jsOne, NULL)); exception = NULL; result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception); ASSERT(!result); ASSERT(JSValueIsObject(context, exception)); JSStringRef array = JSStringCreateWithUTF8CString("Array"); JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL); JSStringRelease(array); result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL); ASSERT(result); ASSERT(JSValueIsObject(context, result)); ASSERT(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL)); ASSERT(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(context), arrayConstructor, NULL)); o = JSValueToObject(context, result, NULL); exception = NULL; ASSERT(JSValueIsUndefined(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception))); ASSERT(!exception); JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(context, 1), &exception); ASSERT(!exception); exception = NULL; ASSERT(1 == JSValueToNumber(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception), &exception)); ASSERT(!exception); JSStringRef functionBody; JSObjectRef function; exception = NULL; functionBody = JSStringCreateWithUTF8CString("rreturn Array;"); JSStringRef line = JSStringCreateWithUTF8CString("line"); ASSERT(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception)); ASSERT(JSValueIsObject(context, exception)); v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL); assertEqualsAsNumber(v, 1); JSStringRelease(functionBody); JSStringRelease(line); exception = NULL; functionBody = JSStringCreateWithUTF8CString("return Array;"); function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception); JSStringRelease(functionBody); ASSERT(!exception); ASSERT(JSObjectIsFunction(context, function)); v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); ASSERT(v); ASSERT(JSValueIsEqual(context, v, arrayConstructor, NULL)); exception = NULL; function = JSObjectMakeFunction(context, NULL, 0, NULL, jsEmptyIString, NULL, 0, &exception); ASSERT(!exception); v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, &exception); ASSERT(v && !exception); ASSERT(JSValueIsUndefined(context, v)); exception = NULL; v = NULL; JSStringRef foo = JSStringCreateWithUTF8CString("foo"); JSStringRef argumentNames[] = { foo }; functionBody = JSStringCreateWithUTF8CString("return foo;"); function = JSObjectMakeFunction(context, foo, 1, argumentNames, functionBody, NULL, 1, &exception); ASSERT(function && !exception); JSValueRef arguments[] = { JSValueMakeNumber(context, 2) }; v = JSObjectCallAsFunction(context, function, NULL, 1, arguments, &exception); JSStringRelease(foo); JSStringRelease(functionBody); string = JSValueToStringCopy(context, function, NULL); assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) {return foo;}"); JSStringRelease(string); JSStringRef print = JSStringCreateWithUTF8CString("print"); JSObjectRef printFunction = JSObjectMakeFunctionWithCallback(context, print, print_callAsFunction); JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone, NULL); JSStringRelease(print); ASSERT(!JSObjectSetPrivate(printFunction, (void*)1)); ASSERT(!JSObjectGetPrivate(printFunction)); JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor"); JSObjectRef myConstructor = JSObjectMakeConstructor(context, NULL, myConstructor_callAsConstructor); JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone, NULL); JSStringRelease(myConstructorIString); ASSERT(!JSObjectSetPrivate(myConstructor, (void*)1)); ASSERT(!JSObjectGetPrivate(myConstructor)); string = JSStringCreateWithUTF8CString("Derived"); JSObjectRef derivedConstructor = JSObjectMakeConstructor(context, Derived_class(context), NULL); JSObjectSetProperty(context, globalObject, string, derivedConstructor, kJSPropertyAttributeNone, NULL); JSStringRelease(string); o = JSObjectMake(context, NULL, NULL); JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL); JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL); JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o); size_t expectedCount = JSPropertyNameArrayGetCount(nameArray); size_t count; for (count = 0; count < expectedCount; ++count) JSPropertyNameArrayGetNameAtIndex(nameArray, count); JSPropertyNameArrayRelease(nameArray); ASSERT(count == 1); // jsCFString should not be enumerated JSClassDefinition nullDefinition = kJSClassDefinitionEmpty; nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype; JSClassRef nullClass = JSClassCreate(&nullDefinition); JSClassRelease(nullClass); nullDefinition = kJSClassDefinitionEmpty; nullClass = JSClassCreate(&nullDefinition); JSClassRelease(nullClass); functionBody = JSStringCreateWithUTF8CString("return this;"); function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL); JSStringRelease(functionBody); v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); ASSERT(JSValueIsEqual(context, v, globalObject, NULL)); v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL); ASSERT(JSValueIsEqual(context, v, o, NULL)); functionBody = JSStringCreateWithUTF8CString("return eval(\"this\");"); function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL); JSStringRelease(functionBody); v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); ASSERT(JSValueIsEqual(context, v, globalObject, NULL)); v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL); ASSERT(JSValueIsEqual(context, v, o, NULL)); JSStringRef script = JSStringCreateWithUTF8CString("this;"); v = JSEvaluateScript(context, script, NULL, NULL, 1, NULL); ASSERT(JSValueIsEqual(context, v, globalObject, NULL)); v = JSEvaluateScript(context, script, o, NULL, 1, NULL); ASSERT(JSValueIsEqual(context, v, o, NULL)); JSStringRelease(script); script = JSStringCreateWithUTF8CString("eval(this);"); v = JSEvaluateScript(context, script, NULL, NULL, 1, NULL); ASSERT(JSValueIsEqual(context, v, globalObject, NULL)); v = JSEvaluateScript(context, script, o, NULL, 1, NULL); ASSERT(JSValueIsEqual(context, v, o, NULL)); JSStringRelease(script); char* scriptUTF8 = createStringWithContentsOfFile(scriptPath); if (!scriptUTF8) printf("FAIL: Test script could not be loaded.\n"); else { script = JSStringCreateWithUTF8CString(scriptUTF8); result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); if (JSValueIsUndefined(context, result)) printf("PASS: Test script executed successfully.\n"); else { printf("FAIL: Test script returned unexpected value:\n"); JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL); CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString); CFShow(exceptionCF); CFRelease(exceptionCF); JSStringRelease(exceptionIString); } JSStringRelease(script); free(scriptUTF8); } // Clear out local variables pointing at JSObjectRefs to allow their values to be collected function = NULL; v = NULL; o = NULL; globalObject = NULL; JSStringRelease(jsEmptyIString); JSStringRelease(jsOneIString); JSStringRelease(jsCFIString); JSStringRelease(jsCFEmptyIString); JSStringRelease(jsCFIStringWithCharacters); JSStringRelease(jsCFEmptyIStringWithCharacters); JSStringRelease(goodSyntax); JSStringRelease(badSyntax); JSGlobalContextRelease(context); JSClassRelease(globalObjectClass); printf("PASS: Program exited normally.\n"); return 0; }
pdf_jsimp_obj *pdf_jsimp_array_item(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i) { return wrap_val(imp, JSObjectGetPropertyAtIndex(imp->jscore_ctx, JSValueToObject(imp->jscore_ctx, obj->ref, NULL), i, NULL)); }
JSValueRef JSPropertyValue::instance() const { if (using_numeric_idx_) return JSObjectGetPropertyAtIndex(ctx_, *proxyObj_, numeric_idx_, nullptr); else return JSObjectGetProperty(ctx_, *proxyObj_, string_idx_, nullptr); }
JSValueRef ArrayWrapper::GetValue(int index) { return JSObjectGetPropertyAtIndex(g_ctx, m_arr, index, NULL); }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static const JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); webkit_web_frame_layout(mainFrame); // handle modifier keys. int state = 0; if (argumentCount > 1) { JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception); if (modifiersArray) { for (int i = 0; i < JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqualToUTF8CString(string, "ctrlKey")) state |= GDK_CONTROL_MASK; else if (JSStringIsEqualToUTF8CString(string, "shiftKey")) state |= GDK_SHIFT_MASK; else if (JSStringIsEqualToUTF8CString(string, "altKey")) state |= GDK_MOD1_MASK; JSStringRelease(string); } } } // handle location argument. int location = DOM_KEY_LOCATION_STANDARD; if (argumentCount > 2) location = (int)JSValueToNumber(context, arguments[2], exception); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); int gdkKeySym = GDK_VoidSymbol; if (location == DOM_KEY_LOCATION_NUMPAD) { if (JSStringIsEqualToUTF8CString(character, "leftArrow")) gdkKeySym = GDK_KP_Left; else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) gdkKeySym = GDK_KP_Right; else if (JSStringIsEqualToUTF8CString(character, "upArrow")) gdkKeySym = GDK_KP_Up; else if (JSStringIsEqualToUTF8CString(character, "downArrow")) gdkKeySym = GDK_KP_Down; else if (JSStringIsEqualToUTF8CString(character, "pageUp")) gdkKeySym = GDK_KP_Page_Up; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) gdkKeySym = GDK_KP_Page_Down; else if (JSStringIsEqualToUTF8CString(character, "home")) gdkKeySym = GDK_KP_Home; else if (JSStringIsEqualToUTF8CString(character, "end")) gdkKeySym = GDK_KP_End; else // Assume we only get arrow/pgUp/pgDn/home/end keys with // location=NUMPAD for now. g_assert_not_reached(); } else { if (JSStringIsEqualToUTF8CString(character, "leftArrow")) gdkKeySym = GDK_Left; else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) gdkKeySym = GDK_Right; else if (JSStringIsEqualToUTF8CString(character, "upArrow")) gdkKeySym = GDK_Up; else if (JSStringIsEqualToUTF8CString(character, "downArrow")) gdkKeySym = GDK_Down; else if (JSStringIsEqualToUTF8CString(character, "pageUp")) gdkKeySym = GDK_Page_Up; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) gdkKeySym = GDK_Page_Down; else if (JSStringIsEqualToUTF8CString(character, "home")) gdkKeySym = GDK_Home; else if (JSStringIsEqualToUTF8CString(character, "end")) gdkKeySym = GDK_End; else if (JSStringIsEqualToUTF8CString(character, "delete")) gdkKeySym = GDK_BackSpace; else if (JSStringIsEqualToUTF8CString(character, "F1")) gdkKeySym = GDK_F1; else if (JSStringIsEqualToUTF8CString(character, "F2")) gdkKeySym = GDK_F2; else if (JSStringIsEqualToUTF8CString(character, "F3")) gdkKeySym = GDK_F3; else if (JSStringIsEqualToUTF8CString(character, "F4")) gdkKeySym = GDK_F4; else if (JSStringIsEqualToUTF8CString(character, "F5")) gdkKeySym = GDK_F5; else if (JSStringIsEqualToUTF8CString(character, "F6")) gdkKeySym = GDK_F6; else if (JSStringIsEqualToUTF8CString(character, "F7")) gdkKeySym = GDK_F7; else if (JSStringIsEqualToUTF8CString(character, "F8")) gdkKeySym = GDK_F8; else if (JSStringIsEqualToUTF8CString(character, "F9")) gdkKeySym = GDK_F9; else if (JSStringIsEqualToUTF8CString(character, "F10")) gdkKeySym = GDK_F10; else if (JSStringIsEqualToUTF8CString(character, "F11")) gdkKeySym = GDK_F11; else if (JSStringIsEqualToUTF8CString(character, "F12")) gdkKeySym = GDK_F12; else { int charCode = JSStringGetCharactersPtr(character)[0]; if (charCode == '\n' || charCode == '\r') gdkKeySym = GDK_Return; else if (charCode == '\t') gdkKeySym = GDK_Tab; else if (charCode == '\x8') gdkKeySym = GDK_BackSpace; else { gdkKeySym = gdk_unicode_to_keyval(charCode); if (WTF::isASCIIUpper(charCode)) state |= GDK_SHIFT_MASK; } } } JSStringRelease(character); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); // create and send the event GdkEvent event; memset(&event, 0, sizeof(event)); event.key.keyval = gdkKeySym; event.key.state = state; event.key.window = GTK_WIDGET(view)->window; // When synthesizing an event, an invalid hardware_keycode value // can cause it to be badly processed by Gtk+. GdkKeymapKey* keys; gint n_keys; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), gdkKeySym, &keys, &n_keys)) { event.key.hardware_keycode = keys[0].keycode; g_free(keys); } gboolean return_val; event.key.type = GDK_KEY_PRESS; g_signal_emit_by_name(view, "key-press-event", &event.key, &return_val); event.key.type = GDK_KEY_RELEASE; g_signal_emit_by_name(view, "key-release-event", &event.key, &return_val); return JSValueMakeUndefined(context); }
static void gumjs_proxy_get_property_names (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef property_names) { GumJscProxy * self; GumJscCore * core; self = GUMJS_PROXY (object); if (self->enumerate == NULL) return; core = JSObjectGetPrivate (JSContextGetGlobalObject (ctx)); { GumJscScope scope = GUM_JSC_SCOPE_INIT (core); JSValueRef * ex = &scope.exception; JSValueRef value; JSObjectRef names; guint length, i; value = JSObjectCallAsFunction (ctx, self->enumerate, self->receiver, 0, NULL, ex); if (value == NULL) goto beach; if (!JSValueIsArray (ctx, value)) goto invalid_result_type; names = (JSObjectRef) value; if (!_gumjs_object_try_get_uint (ctx, names, "length", &length, ex)) goto beach; for (i = 0; i != length; i++) { JSValueRef element; JSStringRef s; element = JSObjectGetPropertyAtIndex (ctx, names, i, ex); if (element == NULL) goto beach; if (!JSValueIsString (ctx, element)) goto invalid_element_type; s = JSValueToStringCopy (ctx, element, ex); if (s == NULL) goto beach; JSPropertyNameAccumulatorAddName (property_names, s); JSStringRelease (s); } goto beach; invalid_result_type: { _gumjs_throw (ctx, ex, "expected enumerate() to return an array"); goto beach; } invalid_element_type: { _gumjs_throw (ctx, ex, "expected a string"); goto beach; } beach: { _gum_jsc_scope_flush (&scope); } } }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static const JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); webkit_web_frame_layout(mainFrame); // handle modifier keys. int state = 0; if (argumentCount > 1) { JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception); if (modifiersArray) { for (int i = 0; i < JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqualToUTF8CString(string, "ctrlKey")) state |= GDK_CONTROL_MASK; else if (JSStringIsEqualToUTF8CString(string, "shiftKey")) state |= GDK_SHIFT_MASK; else if (JSStringIsEqualToUTF8CString(string, "altKey")) state |= GDK_MOD1_MASK; JSStringRelease(string); } } } // handle location argument. int location = DOM_KEY_LOCATION_STANDARD; if (argumentCount > 2) location = (int)JSValueToNumber(context, arguments[2], exception); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); int gdkKeySym = GDK_VoidSymbol; if (location == DOM_KEY_LOCATION_NUMPAD) { if (JSStringIsEqualToUTF8CString(character, "leftArrow")) gdkKeySym = GDK_KP_Left; else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) gdkKeySym = GDK_KP_Right; else if (JSStringIsEqualToUTF8CString(character, "upArrow")) gdkKeySym = GDK_KP_Up; else if (JSStringIsEqualToUTF8CString(character, "downArrow")) gdkKeySym = GDK_KP_Down; else if (JSStringIsEqualToUTF8CString(character, "pageUp")) gdkKeySym = GDK_KP_Page_Up; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) gdkKeySym = GDK_KP_Page_Down; else if (JSStringIsEqualToUTF8CString(character, "home")) gdkKeySym = GDK_KP_Home; else if (JSStringIsEqualToUTF8CString(character, "end")) gdkKeySym = GDK_KP_End; else if (JSStringIsEqualToUTF8CString(character, "insert")) gdkKeySym = GDK_KP_Insert; else if (JSStringIsEqualToUTF8CString(character, "delete")) gdkKeySym = GDK_KP_Delete; else // If we get some other key specified with the numpad location, // crash here, so we add it sooner rather than later. g_assert_not_reached(); } else { if (JSStringIsEqualToUTF8CString(character, "leftArrow")) gdkKeySym = GDK_Left; else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) gdkKeySym = GDK_Right; else if (JSStringIsEqualToUTF8CString(character, "upArrow")) gdkKeySym = GDK_Up; else if (JSStringIsEqualToUTF8CString(character, "downArrow")) gdkKeySym = GDK_Down; else if (JSStringIsEqualToUTF8CString(character, "pageUp")) gdkKeySym = GDK_Page_Up; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) gdkKeySym = GDK_Page_Down; else if (JSStringIsEqualToUTF8CString(character, "home")) gdkKeySym = GDK_Home; else if (JSStringIsEqualToUTF8CString(character, "end")) gdkKeySym = GDK_End; else if (JSStringIsEqualToUTF8CString(character, "insert")) gdkKeySym = GDK_Insert; else if (JSStringIsEqualToUTF8CString(character, "delete")) gdkKeySym = GDK_Delete; else if (JSStringIsEqualToUTF8CString(character, "printScreen")) gdkKeySym = GDK_Print; else if (JSStringIsEqualToUTF8CString(character, "F1")) gdkKeySym = GDK_F1; else if (JSStringIsEqualToUTF8CString(character, "F2")) gdkKeySym = GDK_F2; else if (JSStringIsEqualToUTF8CString(character, "F3")) gdkKeySym = GDK_F3; else if (JSStringIsEqualToUTF8CString(character, "F4")) gdkKeySym = GDK_F4; else if (JSStringIsEqualToUTF8CString(character, "F5")) gdkKeySym = GDK_F5; else if (JSStringIsEqualToUTF8CString(character, "F6")) gdkKeySym = GDK_F6; else if (JSStringIsEqualToUTF8CString(character, "F7")) gdkKeySym = GDK_F7; else if (JSStringIsEqualToUTF8CString(character, "F8")) gdkKeySym = GDK_F8; else if (JSStringIsEqualToUTF8CString(character, "F9")) gdkKeySym = GDK_F9; else if (JSStringIsEqualToUTF8CString(character, "F10")) gdkKeySym = GDK_F10; else if (JSStringIsEqualToUTF8CString(character, "F11")) gdkKeySym = GDK_F11; else if (JSStringIsEqualToUTF8CString(character, "F12")) gdkKeySym = GDK_F12; else { int charCode = JSStringGetCharactersPtr(character)[0]; if (charCode == '\n' || charCode == '\r') gdkKeySym = GDK_Return; else if (charCode == '\t') gdkKeySym = GDK_Tab; else if (charCode == '\x8') gdkKeySym = GDK_BackSpace; else { gdkKeySym = gdk_unicode_to_keyval(charCode); if (WTF::isASCIIUpper(charCode)) state |= GDK_SHIFT_MASK; } } } JSStringRelease(character); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); // create and send the event GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS); pressEvent->key.keyval = gdkKeySym; pressEvent->key.state = state; pressEvent->key.window = gtk_widget_get_window(GTK_WIDGET(view)); g_object_ref(pressEvent->key.window); #ifndef GTK_API_VERSION_2 gdk_event_set_device(pressEvent, getDefaultGDKPointerDevice(pressEvent->key.window)); #endif // When synthesizing an event, an invalid hardware_keycode value // can cause it to be badly processed by Gtk+. GdkKeymapKey* keys; gint n_keys; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), gdkKeySym, &keys, &n_keys)) { pressEvent->key.hardware_keycode = keys[0].keycode; g_free(keys); } GdkEvent* releaseEvent = gdk_event_copy(pressEvent); dispatchEvent(pressEvent); releaseEvent->key.type = GDK_KEY_RELEASE; dispatchEvent(releaseEvent); return JSValueMakeUndefined(context); }
VJSValue VJSArray::GetValueAt( size_t inIndex, JS4D::ExceptionRef *outException) const { return VJSValue( fContext, JSObjectGetPropertyAtIndex( fContext, fObject, inIndex, outException)); }
JSValueRef JSCInt16Array::setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(thisObj); if (false) { } else if (argumentCount == 2 && JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl()) && JSValueIsNumber(ctx, arguments[1])) { uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); privData->nativeObj->set(localArray, localOffset); JSValueRef jscRetVal = JSValueMakeUndefined(ctx); return jscRetVal; } else if (argumentCount == 2 && JSValueIsNumber(ctx, arguments[0]) && JSValueIsNumber(ctx, arguments[1])) { unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); short localValue = (short)JSValueToNumber(ctx, arguments[1], exception); privData->nativeObj->set(localIndex, localValue); JSValueRef jscRetVal = JSValueMakeUndefined(ctx); return jscRetVal; } else if (argumentCount == 2 && JSValueIsObject(ctx, arguments[0]) && JSValueIsNumber(ctx, arguments[1])) { std::vector<short> localArray; JSValueRef localArrayItem; unsigned int localArrayIndex = 0; while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { if (JSValueIsUndefined(ctx, localArrayItem)) break; if (JSValueIsNumber(ctx,localArrayItem)) localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); localArrayIndex++; } unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); privData->nativeObj->set(localArray, localOffset); JSValueRef jscRetVal = JSValueMakeUndefined(ctx); return jscRetVal; } else if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl())) { uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; privData->nativeObj->set(localArray); JSValueRef jscRetVal = JSValueMakeUndefined(ctx); return jscRetVal; } else if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0])) { std::vector<short> localArray; JSValueRef localArrayItem; unsigned int localArrayIndex = 0; while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { if (JSValueIsUndefined(ctx, localArrayItem)) break; if (JSValueIsNumber(ctx,localArrayItem)) localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); localArrayIndex++; } privData->nativeObj->set(localArray); JSValueRef jscRetVal = JSValueMakeUndefined(ctx); return jscRetVal; } JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); *exception = JSValueMakeString(ctx, exceptionString); JSStringRelease(exceptionString); return JSValueMakeUndefined(ctx); }