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; 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); }
JSValueRef LayoutTestController::originsWithApplicationCache(JSContextRef context) { // FIXME: Implement to get origins that contain application caches. 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_LCONTROL; else if (JSStringIsEqualToUTF8CString(character, "leftShift")) virtualKeyCode = VK_LSHIFT; else if (JSStringIsEqualToUTF8CString(character, "leftAlt")) virtualKeyCode = VK_LMENU; else if (JSStringIsEqualToUTF8CString(character, "rightControl")) virtualKeyCode = VK_RCONTROL; else if (JSStringIsEqualToUTF8CString(character, "rightShift")) virtualKeyCode = VK_RSHIFT; else if (JSStringIsEqualToUTF8CString(character, "rightAlt")) virtualKeyCode = 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); }
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; }
JSValueRef TestRunner::originsWithLocalStorage(JSContextRef context) { notImplemented(); return JSValueMakeUndefined(context); }
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); }
static JSValueRef collectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject)); controller->collect(); return JSValueMakeUndefined(context); }
static JSValueRef logAccessibilityEventsCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) { AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); controller->setLogAccessibilityEvents(true); return JSValueMakeUndefined(ctx); }
static JSValueRef continuousMouseScrollByCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { // GTK doesn't support continuous scroll events. 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 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); }
static JSValueRef removeNotificationListenerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); controller->removeNotificationListener(); return JSValueMakeUndefined(context); }
static JSValueRef removeSelectionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { toAXElement(thisObject)->removeSelection(); return JSValueMakeUndefined(context); }
jsc::Value::Value(Context &context) : context(context) { value = JSValueMakeUndefined(context); JSValueProtect(context, value); }
static JSValueRef leapForwardCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { // FIXME: Add proper support for forward leaps return JSValueMakeUndefined(context); }
/** * release */ JSValueRef releaseForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ReleaseBuffer(object); return JSValueMakeUndefined(ctx); }
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); }
/** * put */ JSValueRef putForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { BUFFER(buffer); ARGCOUNT(4); JSValueRef bufValueRef = arguments[0]; if (!JSValueIsObject(ctx,bufValueRef)) { JSStringRef string = JSStringCreateWithUTF8CString("first argument must be a buffer object"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } JSObjectRef bufObjectRef = JSValueToObject(ctx,bufValueRef,exception); CHECK_EXCEPTION_UNDEFINED JSBuffer *srcBuffer = (JSBuffer*)HyperloopGetPrivateObjectAsJSBuffer(bufObjectRef); if (srcBuffer==nullptr) { JSStringRef string = JSStringCreateWithUTF8CString("first argument must be a buffer object (JSBuffer nullptr)"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } GET_NUMBER(1,srcIndex); GET_NUMBER(2,srcLength); GET_NUMBER(3,destIndex); if (srcLength > srcBuffer->length) { JSStringRef string = JSStringCreateWithUTF8CString("source length passed in greater than source buffer length"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } if (srcLength <= 0) { JSStringRef string = JSStringCreateWithUTF8CString("source length must be greater than 0"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } throw ref new Exception(0, "JSBuffer's putForJSBuffer has not been implemented on Windows yet."); /*void *src = &(srcBuffer->buffer[(int)srcIndex]); size_t newsize = (buffer->length - (int)destIndex); newsize = newsize + srcLength - newsize; void *dest = &(buffer->buffer[(int)destIndex]); if (newsize > buffer->length) { // new to grow it void *copy = malloc(buffer->length); size_t copylen = buffer->length; memcpy(copy, buffer->buffer, copylen); free(buffer->buffer); buffer->buffer = malloc(newsize); buffer->length = newsize; memcpy(buffer->buffer,copy,copylen); } memcpy(dest, src, (int)srcLength); return object;*/ }
static JSValueRef zoomPageOutCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { zoomOut(TRUE); return JSValueMakeUndefined(context); }
EJApp::EJApp() : currentRenderingContext(0), screenRenderingContext(0) { landscapeMode = true; // Show the loading screen - commented out for now. // This causes some visual quirks on different devices, as the launch screen may be a // different one than we loade here - let's rather show a black screen for 200ms... //NSString * loadingScreenName = [EJApp landscapeMode] ? @"Default-Landscape.png" : @"Default-Portrait.png"; //loadingScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:loadingScreenName]]; //loadingScreen.frame = self.view.bounds; //[self.view addSubview:loadingScreen]; paused = false; internalScaling = 1.0f; mainBundle = 0; timers = new EJTimerCollection(); // Create the global JS context and attach the 'Ejecta' object jsClasses = NSDictionary::create(); JSClassDefinition constructorClassDef = kJSClassDefinitionEmpty; constructorClassDef.callAsConstructor = ej_callAsConstructor; ej_constructorClass = JSClassCreate(&constructorClassDef); JSClassDefinition globalClassDef = kJSClassDefinitionEmpty; globalClassDef.getProperty = ej_getNativeClass; JSClassRef globalClass = JSClassCreate(&globalClassDef); jsGlobalContext = JSGlobalContextCreate(NULL); ej_global_undefined = JSValueMakeUndefined(jsGlobalContext); JSValueProtect(jsGlobalContext, ej_global_undefined); JSObjectRef globalObject = JSContextGetGlobalObject(jsGlobalContext); JSObjectRef iosObject = JSObjectMake( jsGlobalContext, globalClass, NULL ); JSObjectSetProperty( jsGlobalContext, globalObject, JSStringCreateWithUTF8CString("Ejecta"), iosObject, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL ); // Create the OpenGL ES1 Context // Android init GLView on java framework NSObjectFactory::map_type* base = NSObjectFactory::getMap(); for(NSObjectFactory::map_type::iterator it = base->begin(); it != base->end(); it++) { string name = it->first; NSLOG("NSObjectFactory : %s", name.c_str()); } NSObjectFactory::fuc_map_type* fuc_base = NSObjectFactory::getFunctionMap(); for(NSObjectFactory::fuc_map_type::iterator it = fuc_base->begin(); it != fuc_base->end(); it++) { string name = it->first; NSLOG("NSObjectFactory : %s", name.c_str()); } }
static JSValueRef repaintSweepHorizontallyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); controller->setTestRepaintSweepHorizontally(true); return JSValueMakeUndefined(context); }
static JSValueRef callMethod(JSContextRef jscore_ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { pdf_jsimp *imp; fz_context *ctx; pdf_jsimp_obj *res = NULL; JSValueRef resref = NULL; int i; pdf_jsimp_obj **args = NULL; pdf_jsimp_method *meth = JSObjectGetPrivate(function); priv_data *pdata = JSObjectGetPrivate(thisObject); if (meth == NULL) { /* The attempt to store the method pointer as private data failed, so we turn the function into a string, which will have the form "function name() xxx", and then lookup the name. */ char name[STRING_BUF_SIZE]; char *np; char *bp; JSStringRef jname = JSValueToStringCopy(jscore_ctx, function, NULL); prop *p; JSStringGetUTF8CString(jname, name, STRING_BUF_SIZE); if (strlen(name) >= FUNCTION_PREAMBLE_LEN) { np = name + FUNCTION_PREAMBLE_LEN; /* strlen("function "); */ bp = strchr(np, '('); if (bp) *bp = 0; p = find_prop(pdata->type->props, np); if (p && p->type == PROP_FN) { meth = p->u.fn.meth; } } JSStringRelease(jname); } if (meth == NULL || pdata == NULL) return JSValueMakeUndefined(jscore_ctx); imp = pdata->type->imp; ctx = imp->ctx; fz_var(args); fz_var(res); fz_try(ctx) { args = fz_malloc_array(ctx, argumentCount, sizeof(pdf_jsimp_obj)); for (i = 0; i < argumentCount; i++) args[i] = wrap_val(imp, arguments[i]); res = meth(imp->nat_ctx, pdata->natobj, argumentCount, args); if (res) resref = res->ref; } fz_always(ctx) { if (args) { for (i = 0; i < argumentCount; i++) pdf_jsimp_drop_obj(imp, args[i]); fz_free(ctx, args); } pdf_jsimp_drop_obj(imp, res); } fz_catch(ctx) { return JSValueMakeUndefined(jscore_ctx); } return resref; }
static JSValueRef addFileToPasteboardOnDragCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); controller->setAddFileToPasteboardOnDrag(true); return JSValueMakeUndefined(context); }
JSValueRef TestRunner::originsWithApplicationCache(JSContextRef context) { // FIXME: Implement to get origins that contain application caches. notImplemented(); return JSValueMakeUndefined(context); }
static JSValueRef setStopProvisionalFrameLoadsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); controller->setStopProvisionalFrameLoads(true); return JSValueMakeUndefined(context); }
JSValueRef LayoutTestController::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef value) { // FIXME: Implement this. return JSValueMakeUndefined(context); }
static JSValueRef waitForPolicyDelegateCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) { LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); controller->waitForPolicyDelegate(); return JSValueMakeUndefined(context); }
JSValueRef LayoutTestController::originsWithLocalStorage(JSContextRef context) { // FIXME: implement return JSValueMakeUndefined(context); }
static JSValueRef dumpChildFrameScrollPositionsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); controller->setDumpChildFrameScrollPositions(true); return JSValueMakeUndefined(context); }
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); }
JSValueRef JSCDocument::evaluateCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(object); if (!privData->dom || !privData->dom->xpath) return JSValueMakeUndefined(ctx); if (argumentCount < 1) { std::string errorMsg = "Wrong number of arguments in evaluate"; JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); JSValueRef exceptionString = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSValueToObject(ctx, exceptionString, NULL); return JSValueMakeUndefined(ctx); } // make sure first argument is a string if (!JSValueIsString(ctx, arguments[0])) { std::string errorMsg = "Expected xpath expression as first argument"; JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); JSValueRef exceptionString = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSValueToObject(ctx, exceptionString, NULL); return JSValueMakeUndefined(ctx); } JSStringRef stringReflocalXPath = JSValueToStringCopy(ctx, arguments[0], NULL); size_t localXPathMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalXPath); char* localXPathBuffer = new char[localXPathMaxSize]; JSStringGetUTF8CString(stringReflocalXPath, localXPathBuffer, localXPathMaxSize); std::string localXPath(localXPathBuffer); JSStringRelease(stringReflocalXPath); free(localXPathBuffer); JSClassRef arbaicaRetClass = JSCXPathResult::getTmpl(); XPath::XPathValue<std::string>* retVal; try { if (argumentCount > 1) { // make sure second argument is a node if (!JSValueIsObject(ctx, arguments[1])) { std::string errorMsg = "Second argument is not of type node"; JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); JSValueRef exceptionString = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSValueToObject(ctx, exceptionString, NULL); return JSValueMakeUndefined(ctx); } Arabica::DOM::Node<std::string>* localContextNode = (Arabica::DOM::Node<std::string>*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[1], NULL)); retVal = new XPath::XPathValue<std::string>(privData->dom->xpath->evaluate(localXPath, *localContextNode)); } else { retVal = new XPath::XPathValue<std::string>(privData->dom->xpath->evaluate(localXPath, *privData->nativeObj)); } } catch (std::runtime_error e) { std::cout << e.what() << std::endl; return JSValueMakeUndefined(ctx); } struct JSCXPathResult::JSCXPathResultPrivate* retPrivData = new JSCXPathResult::JSCXPathResultPrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; #if 0 if (args.Length() < 1) throw V8Exception("Wrong number of arguments in evaluate"); // if (!((V8Node::hasInstance(args[1])) && (V8XPathResult::hasInstance(args[3])))) // throw V8Exception("Parameter mismatch while calling evaluate"); v8::Local<v8::Object> self = args.Holder(); V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); v8::String::AsciiValue localExpression(args[0]); XPath::XPathValue<std::string>* retVal; if (args.Length() > 1) { Arabica::DOM::Node<std::string>* localContextNode = V8DOM::toClassPtr<Arabica::DOM::Node<std::string> >(args[1]->ToObject()->GetInternalField(0)); retVal = new XPath::XPathValue<std::string>(privData->dom->xpath->evaluate(*localExpression, *localContextNode)); } else { retVal = new XPath::XPathValue<std::string>(privData->dom->xpath->evaluate(*localExpression, *privData->nativeObj)); } v8::Handle<v8::Function> retCtor = V8XPathResult::getTmpl()->GetFunction(); v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); V8XPathResult::V8XPathResultPrivate* retPrivData = new V8XPathResult::V8XPathResultPrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); retObj.MakeWeak(0, V8XPathResult::jsDestructor); return retObj; #endif }