static JSValueRef search(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) { InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject)); if (!controller) return JSValueMakeUndefined(ctx); if (argumentCount < 2 || !JSValueIsString(ctx, arguments[1])) return JSValueMakeUndefined(ctx); Node* node = toNode(toJS(arguments[0])); if (!node) return JSValueMakeUndefined(ctx); JSStringRef string = JSValueToStringCopy(ctx, arguments[1], 0); String target(JSStringGetCharactersPtr(string), JSStringGetLength(string)); JSStringRelease(string); JSObjectRef globalObject = JSContextGetGlobalObject(ctx); JSStringRef constructorString = JSStringCreateWithUTF8CString("Array"); JSObjectRef arrayConstructor = JSValueToObject(ctx, JSObjectGetProperty(ctx, globalObject, constructorString, 0), 0); JSStringRelease(constructorString); JSObjectRef array = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, 0); JSStringRef pushString = JSStringCreateWithUTF8CString("push"); JSValueRef pushValue = JSObjectGetProperty(ctx, array, pushString, 0); JSStringRelease(pushString); JSObjectRef push = JSValueToObject(ctx, pushValue, 0); RefPtr<Range> searchRange(rangeOfContents(node)); int exception = 0; do { RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false)); if (resultRange->collapsed(exception)) break; // A non-collapsed result range can in some funky whitespace cases still not // advance the range's start position (4509328). Break to avoid infinite loop. VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM); if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM)) break; KJS::JSLock lock; JSValueRef arg0 = toRef(toJS(toJS(ctx), resultRange.get())); JSObjectCallAsFunction(ctx, push, array, 1, &arg0, 0); setStart(searchRange.get(), newStart); } while (true); return array; }
/* Callback - JavaScript window object has been cleared */ static void window_object_cleared_cb(WebKitWebView *web_view, WebKitWebFrame *frame, gpointer context, gpointer window_object, gpointer user_data) { /* Add classes to JavaScriptCore */ JSClassRef classDef = JSClassCreate(&class_def); JSObjectRef classObj = JSObjectMake(context, classDef, context); JSObjectRef globalObj = JSContextGetGlobalObject(context); JSStringRef str = JSStringCreateWithUTF8CString("CustomClass"); JSObjectSetProperty(context, globalObj, str, classObj, kJSPropertyAttributeNone, NULL); }
void SocketJSObject::handleReadData(const string &data) { JSContextRef ctx = MJSCoreObjectFactory::getJSContext(); JSObjectRef global = JSContextGetGlobalObject(ctx); MJSCoreObject * eventObj = dynamic_cast<MJSCoreObject *>(MJSCoreObjectFactory::getMObject()); eventObj->setProperty("data", MJSCoreObjectFactory::getMObject(data)); MJSCoreObject * handler = GetEventListener(READ_DATA_EVENT_NAME); if (handler) { JSValueRef eventObject = eventObj->getJSValue(); JSObjectCallAsFunction(ctx, handler->getJSObject(), global, 1, &eventObject, 0); } }
static JSValueRef call( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { try { auto globalObj = JSContextGetGlobalObject(ctx); auto executor = static_cast<JSCExecutor*>(JSObjectGetPrivate(globalObj)); return (executor->*method)(object, propertyName); } catch (...) { *exception = translatePendingCppExceptionToJSError(ctx, object); return JSValueMakeUndefined(ctx); } }
static void windowObjectClearedCallback(WebKitScriptWorld* world, WebKitWebPage* webPage, WebKitFrame* frame, WebKitWebExtension* extension) { JSGlobalContextRef context = webkit_frame_get_javascript_context_for_script_world(frame, world); JSObjectRef globalObject = JSContextGetGlobalObject(context); JSClassDefinition classDefinition = kJSClassDefinitionEmpty; classDefinition.className = "WebProcessTestRunner"; classDefinition.staticFunctions = webProcessTestRunnerStaticFunctions; classDefinition.finalize = webProcessTestRunnerFinalize; JSClassRef jsClass = JSClassCreate(&classDefinition); JSObjectRef classObject = JSObjectMake(context, jsClass, g_object_ref(webPage)); JSRetainPtr<JSStringRef> propertyString(Adopt, JSStringCreateWithUTF8CString("WebProcessTestRunner")); JSObjectSetProperty(context, globalObject, propertyString.get(), classObject, kJSPropertyAttributeNone, nullptr); JSClassRelease(jsClass); }
static JSValueRef call( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { try { auto globalObj = JSContextGetGlobalObject(ctx); auto executor = static_cast<JSCExecutor*>(JSObjectGetPrivate(globalObj)); return (executor->*method)(argumentCount, arguments); } catch (...) { *exception = translatePendingCppExceptionToJSError(ctx, function); return JSValueMakeUndefined(ctx); } }
void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, WKBundleScriptWorldRef world) { if (!InjectedBundle::shared().isTestRunning()) return; if (WKBundleScriptWorldNormalWorld() != world) return; JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); JSObjectRef window = JSContextGetGlobalObject(context); JSValueRef exception = 0; InjectedBundle::shared().layoutTestController()->makeWindowObject(context, window, &exception); InjectedBundle::shared().gcController()->makeWindowObject(context, window, &exception); InjectedBundle::shared().eventSendingController()->makeWindowObject(context, window, &exception); }
static JSObjectRef getElementById(WKBundleFrameRef frame, JSStringRef elementId) { JSContextRef context = WKBundleFrameGetJavaScriptContext(frame); JSObjectRef document = propertyObject(context, JSContextGetGlobalObject(context), "document"); if (!document) return 0; JSValueRef getElementById = propertyObject(context, document, "getElementById"); if (!getElementById || !JSValueIsObject(context, getElementById)) return 0; JSValueRef elementIdValue = JSValueMakeString(context, elementId); JSValueRef exception; JSValueRef element = JSObjectCallAsFunction(context, const_cast<JSObjectRef>(getElementById), document, 1, &elementIdValue, &exception); if (!element || !JSValueIsObject(context, element)) return 0; return const_cast<JSObjectRef>(element); }
template<> JSValueRef RJSAccessor::from_binary(JSContextRef ctx, BinaryData data) { static JSStringRef bufferString = JSStringCreateWithUTF8CString("buffer"); static JSStringRef uint8ArrayString = JSStringCreateWithUTF8CString("Uint8Array"); size_t byteCount = data.size(); JSValueRef byteCountValue = JSValueMakeNumber(ctx, byteCount); JSObjectRef uint8ArrayContructor = RJSValidatedObjectProperty(ctx, JSContextGetGlobalObject(ctx), uint8ArrayString); JSObjectRef uint8Array = JSObjectCallAsConstructor(ctx, uint8ArrayContructor, 1, &byteCountValue, NULL); for (size_t i = 0; i < byteCount; i++) { JSValueRef num = JSValueMakeNumber(ctx, data[i]); JSObjectSetPropertyAtIndex(ctx, uint8Array, (unsigned)i, num, NULL); } return RJSValidatedObjectProperty(ctx, uint8Array, bufferString); }
void mk_zs__(WebKitWebView* wwv){ WebKitWebFrame* web_frame; JSGlobalContextRef js_context; JSObjectRef js_global; JSStringRef js_function_name; JSObjectRef js_function; web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (wwv)); js_context = webkit_web_frame_get_global_context (web_frame); js_global = JSContextGetGlobalObject (js_context); js_function_name = JSStringCreateWithUTF8CString (s1_[zs_].c_str()); js_function = JSObjectMakeFunctionWithCallback (js_context, js_function_name, zs__); JSObjectSetProperty (js_context, js_global, js_function_name, js_function, kJSPropertyAttributeNone, NULL); JSStringRelease (js_function_name); }
void SocketJSObject::onConnectComplete(const string & hostname, const string & port, bool bConnected) { JSContextRef ctx = MJSCoreObjectFactory::getJSContext(); JSObjectRef global = JSContextGetGlobalObject(ctx); MJSCoreObject * eventObj = dynamic_cast<MJSCoreObject *>(MJSCoreObjectFactory::getMObject()); eventObj->setProperty("hostname", MJSCoreObjectFactory::getMObject(hostname)); eventObj->setProperty("port", MJSCoreObjectFactory::getMObject(port)); eventObj->setProperty("connected", MJSCoreObjectFactory::getMObject(bConnected)); MJSCoreObject * handler = GetEventListener(CONNECTED_EVENT_NAME); if (handler) { JSValueRef eventObject = eventObj->getJSValue(); JSObjectCallAsFunction(ctx, handler->getJSObject(), global, 1, &eventObject, 0); } }
void* plat_create_window(void* tag, int w, int h) { struct gtk_state* state = malloc(sizeof(struct gtk_state)); state->tag = tag; GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "WebUI"); state->window = window; gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(close_window), state); GtkWidget* scroll = gtk_scrolled_window_new(NULL, NULL); state->web_view = webkit_web_view_new(); gtk_container_add(GTK_CONTAINER(scroll), state->web_view); gtk_container_add(GTK_CONTAINER(window), scroll); WebKitWebFrame* web_frame = webkit_web_view_get_main_frame( WEBKIT_WEB_VIEW(state->web_view)); gtk_window_set_default_size(GTK_WINDOW(window), w, h); gtk_widget_show_all(window); JSGlobalContextRef jsctx = webkit_web_frame_get_global_context(web_frame); state->jsctx = jsctx; JSClassDefinition system_def = kJSClassDefinitionEmpty; system_def.className = "ruby"; system_def.getProperty = ruby_getprop; JSClassRef system_class = JSClassCreate(&system_def); JSObjectRef o = JSObjectMake(jsctx, system_class, NULL); if(!JSObjectSetPrivate(o, tag)) { printf("WebKit is busted.\n"); abort(); } JSStringRef name = JSStringCreateWithUTF8CString("ruby"); JSObjectSetProperty(jsctx, JSContextGetGlobalObject(jsctx), name, o, kJSPropertyAttributeDontDelete, NULL); JSStringRelease(name); return state; }
/** * Evaluates given string as script and return if this call succeed or not. */ gboolean ext_util_js_eval(JSContextRef ctx, const char *script, JSValueRef *result) { JSStringRef js_str; JSValueRef exc = NULL, res = NULL; js_str = JSStringCreateWithUTF8CString(script); res = JSEvaluateScript(ctx, js_str, JSContextGetGlobalObject(ctx), NULL, 0, &exc); JSStringRelease(js_str); if (exc) { *result = exc; return FALSE; } *result = res; return TRUE; }
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) { KJS::JSLock lock(false); if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass())) return JSValueMakeUndefined(ctx); ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject)); const Vector<RefPtr<ProfileNode> >& children = profileNode->children(); JSObjectRef global = JSContextGetGlobalObject(ctx); JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array")); JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push")); JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception); if (exception && *exception) return JSValueMakeUndefined(ctx); JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) { JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() )); JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception); if (exception && *exception) return JSValueMakeUndefined(ctx); } return result; }
static bool gumjs_proxy_has_property (JSContextRef ctx, JSObjectRef object, JSStringRef property_name) { GumJscProxy * self; GumJscCore * core; self = GUMJS_PROXY (object); if (self->has == NULL) return false; core = JSObjectGetPrivate (JSContextGetGlobalObject (ctx)); { GumJscScope scope = GUM_JSC_SCOPE_INIT (core); JSValueRef * ex = &scope.exception; JSValueRef property_name_value, value; bool result = false; property_name_value = JSValueMakeString (ctx, property_name); value = JSObjectCallAsFunction (ctx, self->has, self->receiver, 1, &property_name_value, ex); if (value == NULL) goto beach; if (!JSValueIsBoolean (ctx, value)) goto invalid_result_type; result = JSValueToBoolean (ctx, value); goto beach; invalid_result_type: { _gumjs_throw (ctx, ex, "expected has() to return a boolean"); goto beach; } beach: { _gum_jsc_scope_flush (&scope); return result; } } }
void installGlobalProxy( JSGlobalContextRef ctx, const char* name, JSObjectGetPropertyCallback callback) { JSClassDefinition proxyClassDefintion = kJSClassDefinitionEmpty; proxyClassDefintion.className = "_FBProxyClass"; proxyClassDefintion.getProperty = callback; JSClassRef proxyClass = JSClassCreate(&proxyClassDefintion); JSObjectRef proxyObj = JSObjectMake(ctx, proxyClass, nullptr); JSObjectRef globalObject = JSContextGetGlobalObject(ctx); JSStringRef jsName = JSStringCreateWithUTF8CString(name); JSObjectSetProperty(ctx, globalObject, jsName, proxyObj, 0, NULL); JSStringRelease(jsName); JSClassRelease(proxyClass); }
InspectorController::~InspectorController() { if (m_scriptContext) { JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); JSStringRef controllerProperty = JSStringCreateWithUTF8CString("InspectorController"); JSObjectRef controller = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, global, controllerProperty, 0), 0); JSStringRelease(controllerProperty); JSObjectSetPrivate(controller, 0); } m_client->closeWindow(); m_client->inspectorDestroyed(); if (m_page) m_page->setParentInspectorController(0); deleteAllValues(m_frameResources); deleteAllValues(m_consoleMessages); }
static void webview_register_function(WebKitWebFrame *frame, const gchar *name, gpointer ref) { JSGlobalContextRef context = webkit_web_frame_get_global_context(frame); JSStringRef js_name = JSStringCreateWithUTF8CString(name); // prepare callback function JSClassDefinition def = kJSClassDefinitionEmpty; def.callAsFunction = webview_registered_function_callback; def.className = g_strdup(name); def.finalize = webview_collect_registered_function; JSClassRef class = JSClassCreate(&def); JSObjectRef fun = JSObjectMake(context, class, ref); // register with global object JSObjectRef global = JSContextGetGlobalObject(context); JSObjectSetProperty(context, global, js_name, fun, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL); // release strings JSStringRelease(js_name); JSClassRelease(class); }
static void globalObject_initialize(JSContextRef context, JSObjectRef object) { UNUSED_PARAM(object); // Ensure that an execution context is passed in ASSERT(context); // Ensure that the global object is set to the object that we were passed JSObjectRef globalObject = JSContextGetGlobalObject(context); ASSERT(globalObject); ASSERT(object == globalObject); // Ensure that the standard global properties have been set on the global object JSStringRef array = JSStringCreateWithUTF8CString("Array"); JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL); JSStringRelease(array); UNUSED_PARAM(arrayConstructor); ASSERT(arrayConstructor); }
static JSGlobalContextRef CreateGlobalContext(WorkerContext* context) { JSGlobalContextRef jsContext = KJSUtil::CreateGlobalContext(); JSGlobalContextRetain(jsContext); KObjectRef global(new KKJSObject(jsContext, JSContextGetGlobalObject(jsContext))); global->SetMethod("postMessage", StaticBoundMethod::FromMethod<WorkerContext>( context, &WorkerContext::_PostMessage)); global->SetMethod("importScript", StaticBoundMethod::FromMethod<WorkerContext>( context, &WorkerContext::_ImportScripts)); global->SetMethod("importScripts", StaticBoundMethod::FromMethod<WorkerContext>( context, &WorkerContext::_ImportScripts)); global->SetMethod("sleep", StaticBoundMethod::FromMethod<WorkerContext>( context, &WorkerContext::_Sleep)); return jsContext; }
int main(int argc, char* argv[]) { const char *scriptPath = "minidom.js"; if (argc > 1) { scriptPath = argv[1]; } JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL); JSObjectRef globalObject = JSContextGetGlobalObject(context); JSStringRef printIString = JSStringCreateWithUTF8CString("print"); JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunctionWithCallback(context, printIString, print), kJSPropertyAttributeNone, NULL); JSStringRelease(printIString); JSStringRef node = JSStringCreateWithUTF8CString("Node"); JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_class(context), JSNode_construct), kJSPropertyAttributeNone, NULL); JSStringRelease(node); char* scriptUTF8 = createStringWithContentsOfFile(scriptPath); JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8); JSValueRef exception; JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); if (result) printf("PASS: Test script executed successfully.\n"); else { printf("FAIL: Test script threw exception:\n"); JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL); size_t exceptionUTF8Size = JSStringGetMaximumUTF8CStringSize(exceptionIString); char* exceptionUTF8 = (char*)malloc(exceptionUTF8Size); JSStringGetUTF8CString(exceptionIString, exceptionUTF8, exceptionUTF8Size); printf("%s\n", exceptionUTF8); free(exceptionUTF8); JSStringRelease(exceptionIString); } JSStringRelease(script); free(scriptUTF8); globalObject = 0; JSGlobalContextRelease(context); printf("PASS: Program exited normally.\n"); return 0; }
void QtBuiltinBundlePage::registerNavigatorQtObject(JSGlobalContextRef context) { static JSStringRef postMessageName = JSStringCreateWithUTF8CString("postMessage"); static JSStringRef navigatorName = JSStringCreateWithUTF8CString("navigator"); static JSStringRef qtName = JSStringCreateWithUTF8CString("qt"); if (m_navigatorQtObject) JSValueUnprotect(context, m_navigatorQtObject); m_navigatorQtObject = JSObjectMake(context, navigatorQtObjectClass(), this); JSValueProtect(context, m_navigatorQtObject); JSObjectRef postMessage = JSObjectMakeFunctionWithCallback(context, postMessageName, qt_postMessageCallback); JSObjectSetProperty(context, m_navigatorQtObject, postMessageName, postMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); JSValueRef navigatorValue = JSObjectGetProperty(context, JSContextGetGlobalObject(context), navigatorName, 0); if (!JSValueIsObject(context, navigatorValue)) return; JSObjectRef navigatorObject = JSValueToObject(context, navigatorValue, 0); JSObjectSetProperty(context, navigatorObject, qtName, m_navigatorQtObject, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); }
void defineGlobals (JSContextRef context, entry globals[]) { JSObjectRef g = JSContextGetGlobalObject(context); int i = 0; while (1) { entry global = globals[i++]; if (global.name == NULL) break; JSStringRef name = JSStringCreateWithUTF8CString(global.name); JSValueRef value; if (global.type == FUNCTION) value = JSObjectMakeFunctionWithCallback(context, name, global.value.function); else value = global.value.value; JSObjectSetProperty(context, g, name, value, kJSPropertyAttributeNone, NULL); JSStringRelease(name); } }
JavascriptModuleInstance::JavascriptModuleInstance(Host* host, std::string path, std::string dir, std::string name) : Module(host, dir.c_str(), name.c_str(), "0.1"), path(path) { this->context = JSGlobalContextCreate(NULL); this->global = JSContextGetGlobalObject(context); KJSUtil::RegisterGlobalContext(global, context); KJSUtil::ProtectGlobalContext(context); try { this->Run(); } catch (ValueException& e) { SharedString ss = e.GetValue()->DisplayString(); Logger *logger = Logger::Get("Javascript"); logger->Error("Could not execute %s because %s", path.c_str(), (*ss).c_str()); } }
static void registerNavigatorObject(JSObjectRef *object, JSStringRef name, JSGlobalContextRef context, void* data, CreateClassRefCallback createClassRefCallback, JSStringRef postMessageName, JSObjectCallAsFunctionCallback postMessageCallback) { static JSStringRef navigatorName = JSStringCreateWithUTF8CString("navigator"); if (*object) JSValueUnprotect(context, *object); *object = JSObjectMake(context, createClassRefCallback(), data); JSValueProtect(context, *object); JSObjectRef postMessage = JSObjectMakeFunctionWithCallback(context, postMessageName, postMessageCallback); JSObjectSetProperty(context, *object, postMessageName, postMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); JSValueRef navigatorValue = JSObjectGetProperty(context, JSContextGetGlobalObject(context), navigatorName, 0); if (!JSValueIsObject(context, navigatorValue)) return; JSObjectRef navigatorObject = JSValueToObject(context, navigatorValue, 0); JSObjectSetProperty(context, navigatorObject, name, *object, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); }
void InspectorController::windowScriptObjectAvailable() { if (!m_page || !enabled()) return; m_scriptContext = toRef(m_page->mainFrame()->scriptProxy()->interpreter()->globalExec()); JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); ASSERT(global); static JSStaticFunction staticFunctions[] = { { "addSourceToFrame", addSourceToFrame, kJSPropertyAttributeNone }, { "getResourceDocumentNode", getResourceDocumentNode, kJSPropertyAttributeNone }, { "highlightDOMNode", highlightDOMNode, kJSPropertyAttributeNone }, { "hideDOMNodeHighlight", hideDOMNodeHighlight, kJSPropertyAttributeNone }, { "loaded", loaded, kJSPropertyAttributeNone }, { "windowUnloading", unloading, kJSPropertyAttributeNone }, { "attach", attach, kJSPropertyAttributeNone }, { "detach", detach, kJSPropertyAttributeNone }, { "log", log, kJSPropertyAttributeNone }, { "search", search, kJSPropertyAttributeNone }, { "inspectedWindow", inspectedWindow, kJSPropertyAttributeNone }, { 0, 0, 0 } }; JSClassDefinition inspectorControllerDefinition = { 0, kJSClassAttributeNone, "InspectorController", 0, 0, staticFunctions, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; JSClassRef controllerClass = JSClassCreate(&inspectorControllerDefinition); ASSERT(controllerClass); m_controllerScriptObject = JSObjectMake(m_scriptContext, controllerClass, reinterpret_cast<void*>(this)); ASSERT(m_controllerScriptObject); JSStringRef controllerObjectString = JSStringCreateWithUTF8CString("InspectorController"); JSObjectSetProperty(m_scriptContext, global, controllerObjectString, m_controllerScriptObject, kJSPropertyAttributeNone, 0); JSStringRelease(controllerObjectString); }
void PagePopupBlackBerry::installDOMFunction(Frame* frame) { JSDOMWindow* window = toJSDOMWindow(frame, mainThreadNormalWorld()); ASSERT(window); JSC::ExecState* exec = window->globalExec(); ASSERT(exec); JSC::JSLockHolder lock(exec); JSContextRef context = ::toRef(exec); JSObjectRef globalObject = JSContextGetGlobalObject(context); JSStringRef functionName = JSStringCreateWithUTF8CString( "setValueAndClosePopup"); JSObjectRef function = JSObjectMakeFunctionWithCallback(context, functionName, setValueAndClosePopupCallback); JSObjectSetProperty(context, globalObject, functionName, function, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); // Register client into DOM JSClassDefinition definition = kJSClassDefinitionEmpty; definition.staticValues = popUpExtensionStaticValues; definition.staticFunctions = popUpExtensionStaticFunctions; definition.initialize = popUpExtensionInitialize; definition.finalize = popUpExtensionFinalize; JSClassRef clientClass = JSClassCreate(&definition); JSObjectRef clientClassObject = JSObjectMake(context, clientClass, 0); // Add a reference. See popUpExtensionFinalize. m_sharedClientPointer->ref(); JSObjectSetPrivate(clientClassObject, m_sharedClientPointer.get()); String name("popUp"); JSC::PutPropertySlot slot; window->put(window, exec, JSC::Identifier(exec, name), toJS(clientClassObject), slot); JSClassRelease(clientClass); }
int main(int argc, char** argv) { gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); webFrame = webkit_web_view_get_main_frame (web_view); context = webkit_web_frame_get_global_context(webFrame); globalObject = JSContextGetGlobalObject(context); setlogmask (LOG_UPTO (LOG_NOTICE)); openlog ("kioskbrowser", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); signal(SIGHUP, reload_browser); signal(SIGUSR1, jsmessage); signal(SIGUSR2, jsmessage); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(web_view)); if(argc > 1) { webkit_web_view_load_uri(web_view, argv[1]); } else { webkit_web_view_load_uri(web_view, default_url); } maximize(); gtk_widget_show_all(window); gtk_main(); return 0; }
KKJSList::KKJSList(JSContextRef context, JSObjectRef js_object) : context(NULL), object(js_object) { /* KJS methods run in the global context that they originated from * this seems to prevent nasty crashes from trying to access invalid * contexts later. Global contexts need to be registered by all modules * that use a KJS context. */ JSObjectRef global_object = JSContextGetGlobalObject(context); JSGlobalContextRef global_context = KJSUtil::GetGlobalContext(global_object); // This context hasn't been registered. Something has gone pretty // terribly wrong and Kroll will likely crash soon. Nonetheless, keep // the user up-to-date to keep their hopes up. if (global_context == NULL) std::cerr << "Could not locate global context for a KJS method." << " One of the modules is misbehaving." << std::endl; this->context = global_context; KJSUtil::ProtectGlobalContext(this->context); JSValueProtect(this->context, this->object); this->kjs_bound_object = new KKJSObject(this->context, this->object); }
void removeGlobal(JSGlobalContextRef ctx, const char* name) { JSStringRef jsName = JSStringCreateWithUTF8CString(name); JSObjectRef globalObject = JSContextGetGlobalObject(ctx); JSObjectSetProperty(ctx, globalObject, jsName, nullptr, 0, nullptr); JSStringRelease(jsName); }