コード例 #1
0
void webWorkerInitialize(JSContextRef context, int isDedicated)
{
    if (isDedicated) {
        JSStringRef funcName = JSStringCreateWithUTF8CString("foo");
        JSObjectRef jsFunc = JSObjectMakeFunctionWithCallback(context, funcName, &foo);
        JSObjectSetProperty(context, JSContextGetGlobalObject(context), funcName, jsFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0);
        JSStringRelease(funcName);
    } else {
        JSStringRef funcName = JSStringCreateWithUTF8CString("bar");
        JSObjectRef jsFunc = JSObjectMakeFunctionWithCallback(context, funcName, &bar);
        JSObjectSetProperty(context, JSContextGetGlobalObject(context), funcName, jsFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0);
        JSStringRelease(funcName);
    }
}
コード例 #2
0
int MDNativeBindingManager::registerNativeJSObjectsToContext(ScriptController *script, DOMWrapperWorld* world)
{
    DOMWrapperWorld* nativeWorld = (world)? world : mainThreadNormalWorld();
    JSDOMWindow*    window =  (script->globalObject(nativeWorld));
    //toJSDOMWindow
    JSContextRef context = reinterpret_cast<JSContextRef>(window->globalExec()); 
    JSObjectRef globalObject = JSContextGetGlobalObject(context);

    IMDNativeBindingObject *object = NULL;
    size_t size = m_jsTable.size();
    
    for (size_t i=0; i<size; i++) {
        object = m_jsTable.at(i);
        JSStringRef propertyName = object->propertyName(); //entry->m_propertyName;
        JSObjectSetProperty(
                context,
                globalObject,
                propertyName,
                object->propertyValue(context),
                kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete, NULL);

        JSStringRelease(propertyName);
    }

    return 0;
}
コード例 #3
0
void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
{
    JSRetainPtr<JSStringRef> layoutTestContollerStr(Adopt, JSStringCreateWithUTF8CString("layoutTestController"));
    ref();
    JSValueRef layoutTestContollerObject = JSObjectMake(context, getJSClass(), this);
    JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
}
コード例 #4
0
void Java_com_vasco_digipass_sdk_smartfaceplugin_PluginImp_initNative(JNIEnv *env, jobject thiz,jlong jsContext,jlong envMap)
{
	long jscontextlong = (long)jsContext;
	DPPlugin* instance = DPPlugin::getInstance();
	instance->jsContext = (JSContextRef)jsContext;
	instance->envMap = (std::map<long,JNIEnv*>*)envMap;
	instance->pluginImpObject = env->NewGlobalRef(thiz);
    jclass clazz = env->GetObjectClass(thiz);
    jmethodID initMethod = env->GetMethodID(clazz,"init","(Ljava/lang/String;)V");
    jstring fingerprint = env->NewStringUTF(DBFINGERPRINT);
    env->CallVoidMethod(thiz,initMethod,fingerprint);
    env->DeleteLocalRef(fingerprint);
    instance->getBytes = env->GetMethodID(clazz,"getBytes","(Ljava/lang/String;)[B");
    instance->putBytes = env->GetMethodID(clazz,"putBytes","(Ljava/lang/String;Ljava/lang/String;[B)Z");
    instance->initializeRegistrationDataV2JavaFunction = env->GetMethodID(clazz,"initializeRegistrationDataV2","(Ljava/lang/String;[Z)Ljava/lang/String;");
    instance->decryptActivationDataJavaFunction = env->GetMethodID(clazz,"decryptActivationData","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Z)Ljava/lang/String;");
    instance->validateSharedDataChecksumJavaFunction = env->GetMethodID(clazz,"validateSharedDataChecksum","(Ljava/lang/String;[Z)Ljava/lang/String;");
    env->DeleteLocalRef(clazz);
    JSStringRef str = JSStringCreateWithUTF8CString("VASCO");
	JSClassRef classDef = JSClassCreate(&spjsdpplugin_def);
	JSObjectRef classObj = JSObjectMake(instance->jsContext, classDef, (void*)DPPlugin::getInstance());
	JSObjectSetProperty(instance->jsContext, JSContextGetGlobalObject(instance->jsContext), str, classObj, kJSPropertyAttributeNone, NULL);
    JSClassRelease(classDef);
	JSStringRelease(str);
}
コード例 #5
0
ファイル: module.cpp プロジェクト: Aeva/webkit2gtk-experiment
//
//  Boilerplate code / signal callback for attaching methods when a
//  new javascript context is created.
//
static void 
window_object_cleared_callback (WebKitScriptWorld *world, 
                                WebKitWebPage *web_page, 
                                WebKitFrame *frame, 
                                gpointer user_data)
{
  std::cout << "attempting to set up custom c function bindings\n";
  JSGlobalContextRef js_ctx;
  js_ctx = webkit_frame_get_javascript_context_for_script_world (frame, world);
  
  JSStringRef function_name = JSStringCreateWithUTF8CString("whatever");
  JSObjectRef boiler_plate = JSObjectMakeFunctionWithCallback(js_ctx,
                                                              function_name,
                                                              some_method);
  JSValueRef exception = 0;
  JSObjectRef global = JSContextGetGlobalObject(js_ctx);
  JSObjectSetProperty(js_ctx,
                      global,
                      JSStringCreateWithUTF8CString("myCFunction"),
                      boiler_plate,
                      kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly,
                      &exception);
  if (exception) {
    std::cout << "Argh! an exception!!!!\n";
  }
}
コード例 #6
0
static void window_object_cleared_callback(WebKitWebView* web_view, WebKitWebFrame* web_frame, JSGlobalContextRef context, JSObjectRef window_object, gpointer data)
{
    JSStringRef name = JSStringCreateWithUTF8CString("runTest");
    JSObjectRef testComplete = JSObjectMakeFunctionWithCallback(context, name, runPasteTestCallback);
    JSObjectSetProperty(context, window_object, name, testComplete, kJSPropertyAttributeNone, 0);
    JSStringRelease(name);
}
コード例 #7
0
ファイル: ns_net.c プロジェクト: vifino/dwb
static JSValueRef
get_message_data(SoupMessage *msg)
{
    const char *name, *value;
    SoupMessageHeadersIter iter;
    JSObjectRef o = NULL, ho;
    JSValueRef ret;
    JSStringRef s;

    JSContextRef ctx = scripts_get_global_context();
    if (ctx == NULL) {
        return NIL;
    }

    o = JSObjectMake(ctx, NULL, NULL);
    js_set_object_property(ctx, o, "body", msg->response_body->data, NULL);

    ho = JSObjectMake(ctx, NULL, NULL);

    soup_message_headers_iter_init(&iter, msg->response_headers);
    while (soup_message_headers_iter_next(&iter, &name, &value))
        js_set_object_property(ctx, ho, name, value, NULL);

    s = JSStringCreateWithUTF8CString("headers");
    JSObjectSetProperty(ctx, o, s, ho, kJSDefaultProperty, NULL);
    JSStringRelease(s);
    ret = o;

    scripts_release_global_context();

    return ret;
}
コード例 #8
0
	void JavascriptModuleInstance::Run()
	{
		std::string code(FileUtils::ReadFile(this->path));

		// Insert the global object into this script's context.
		KValueRef globalValue = Value::NewObject(host->GetGlobalObject());
		JSValueRef jsAPI = KJSUtil::ToJSValue(globalValue, context);
		JSStringRef propertyName = JSStringCreateWithUTF8CString(PRODUCT_NAME);
		JSObjectSetProperty(context, global, propertyName, jsAPI,
			kJSPropertyAttributeNone, NULL);
		JSStringRelease(propertyName);

		// Check the script's syntax.
		JSValueRef exception;
		JSStringRef jsCode = JSStringCreateWithUTF8CString(code.c_str());
		bool syntax = JSCheckScriptSyntax(context, jsCode, NULL, 0, &exception);
		if (!syntax)
		{
			KValueRef e = KJSUtil::ToKrollValue(exception, context, NULL);
			JSStringRelease(jsCode);
			throw ValueException(e);
		}

		// Run the script.
		JSValueRef ret = JSEvaluateScript(context, jsCode, NULL, NULL, 1, &exception);
		JSStringRelease(jsCode);

		if (ret == NULL)
		{
			KValueRef e = KJSUtil::ToKrollValue(exception, context, NULL);
			throw ValueException(e);
		}
	}
コード例 #9
0
static void window_object_cleared__(
	WebKitWebView  *wv,
	WebKitWebFrame *wf,
	JSGlobalContextRef ctx,
	gpointer        window_object,
	gpointer        user_data)
{
	const char* name0 = "z$";
	JSStringRef name = JSStringCreateWithUTF8CString(name0);

	JSObjectRef func;
	//func = JSObjectMakeFunctionWithCallback(ctx, name, zs__);
	{
		JSClassDefinition cd = kJSClassDefinitionEmpty;
		cd.className = name0;
		cd.callAsFunction = zs__;
		JSClassRef cr = JSClassCreate (&cd);
		func = JSObjectMake (ctx, cr, NULL);
	}

	JSObjectRef o = JSContextGetGlobalObject(ctx);
	JSObjectSetProperty(ctx, o, name, func, kJSPropertyAttributeNone, NULL);
	JSStringRelease(name);
	/*bool b=*/JSObjectSetPrivate(func, (void*)webkit_view___::from__(wv));
}
コード例 #10
0
ファイル: Value.cpp プロジェクト: 0m15/react-native-1
void Object::setProperty(const String& propName, const Value& value) const {
  JSValueRef exn = NULL;
  JSObjectSetProperty(m_context, m_obj, propName, value, kJSPropertyAttributeNone, &exn);
  if (exn) {
    std::string exceptionText = Value(m_context, exn).toString().str();
    throwJSExecutionException("Failed to set property: %s", exceptionText.c_str());
  }
}
	static void create(JSContextRef ctx, JSObjectRef global) {
		JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
		classDefinition.callAsConstructor = classConstructor;
		JSClassRef clsRef = JSClassCreate(&classDefinition);
		JSObjectRef classDef = JSObjectMake(ctx, clsRef, NULL);
		JSStringRef className = JSStringCreateWithUTF8CString("ManipulationDeltaEventHandler");
		JSObjectSetProperty(ctx, global, className, classDef, kJSPropertyAttributeNone, NULL);
	}
コード例 #12
0
ファイル: JSHelpers.cpp プロジェクト: FinnProjects/ultralight
JSPropertyValue& JSPropertyValue::operator=(const JSCallbackWithRetval& callback) {
  JSObjectRef nativeFunction = JSObjectMake(ctx_, NativeFunctionWithRetvalClass(), new JSCallbackWithRetval(callback));
  if (using_numeric_idx_)
    JSObjectSetPropertyAtIndex(ctx_, *proxyObj_, numeric_idx_, nativeFunction, nullptr);
  else
    JSObjectSetProperty(ctx_, *proxyObj_, string_idx_, nativeFunction, kJSPropertyAttributeNone, nullptr);
  return *this;
}
コード例 #13
0
ファイル: JSHelpers.cpp プロジェクト: FinnProjects/ultralight
JSPropertyValue& JSPropertyValue::operator=(const JSValue& value) {
  if (using_numeric_idx_)
    JSObjectSetPropertyAtIndex(ctx_, *proxyObj_, numeric_idx_, value, nullptr);
  else
    JSObjectSetProperty(ctx_, *proxyObj_, string_idx_, value, kJSPropertyAttributeNone, nullptr);

  return *this;
}
コード例 #14
0
ファイル: main.c プロジェクト: gsnewmark/planck
void register_global_function(JSContextRef ctx, char *name, JSObjectCallAsFunctionCallback handler) {
	JSObjectRef global_obj = JSContextGetGlobalObject(ctx);

	JSStringRef fn_name = JSStringCreateWithUTF8CString(name);
	JSObjectRef fn_obj = JSObjectMakeFunctionWithCallback(ctx, fn_name, handler);

	JSObjectSetProperty(ctx, global_obj, fn_name, fn_obj, kJSPropertyAttributeNone, NULL);
}
コード例 #15
0
ファイル: jsbridge_webview.cpp プロジェクト: vnmc/zephyros
bool ObjectWrapper::SetValue(const KeyType key, JSValueRef value)
{
    JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
    JSObjectSetProperty(g_ctx, m_obj, strKey, value, kJSPropertyAttributeNone, NULL);
    JSStringRelease(strKey);

    return true;
}
コード例 #16
0
ファイル: JSCExecutor.cpp プロジェクト: DYS1230/react-native
void JSCExecutor::setGlobalVariable(const std::string& propName, const std::string& jsonValue) {
  auto globalObject = JSContextGetGlobalObject(m_context);
  String jsPropertyName(propName.c_str());

  String jsValueJSON(jsonValue.c_str());
  auto valueToInject = JSValueMakeFromJSONString(m_context, jsValueJSON);

  JSObjectSetProperty(m_context, globalObject, jsPropertyName, valueToInject, 0, NULL);
}
コード例 #17
0
ファイル: gcds.c プロジェクト: diegoe/webkitgtk.org
int
main (int    argc,
      gchar* argv[])
{
  GtkWidget* window;
  GtkWidget* vbox;
  GtkWidget* scrolled;
  GtkWidget* web_view;
  GtkWidget* button_box;
  WebKitWebFrame* web_frame;
  JSGlobalContextRef js_context;
  JSObjectRef js_global;
  JSStringRef js_function_name;
  JSObjectRef js_set_can_register;

  if (!g_thread_supported ())
    g_thread_init (NULL);
  gtk_init_check (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "WebKitGTK+ API Demo");
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 240);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  scrolled = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
  web_view = webkit_web_view_new ();
  gtk_container_add (GTK_CONTAINER (scrolled), web_view);
  webkit_web_view_load_string (WEBKIT_WEB_VIEW (web_view), form_markup, "text/html", "UTF-8", "");
  g_signal_connect (web_view, "create-plugin-widget",
                    G_CALLBACK (web_view_create_plugin_widget_cb), NULL);

  button_box = gtk_hbutton_box_new ();
  gtk_box_pack_start (GTK_BOX (vbox), button_box, FALSE, FALSE, 0);
  register_button = gtk_button_new_with_mnemonic ("Send _Registration");
  gtk_widget_set_sensitive (register_button, FALSE);
  gtk_box_pack_start (GTK_BOX (button_box), register_button, FALSE, FALSE, 0);

  web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
  js_context = webkit_web_frame_get_global_context (web_frame);
  js_global = JSContextGetGlobalObject (js_context);
  js_function_name = JSStringCreateWithUTF8CString ("setCanRegister");
  js_set_can_register = JSObjectMakeFunctionWithCallback (js_context,
    js_function_name, (JSObjectCallAsFunctionCallback)set_can_register_cb);
  JSObjectSetProperty (js_context, js_global, js_function_name, js_set_can_register, 0, NULL);
  JSStringRelease (js_function_name);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
コード例 #18
0
ファイル: JSBuffer.cpp プロジェクト: pec1985/hyperloop
/**
 * called to make a native object for JSBuffer. this method must be called instead of
 * normal JSObjectMake in JavaScriptCore so that the correct prototype chain and
 * constructor will be setup.
 */
JSObjectRef MakeObjectForJSBuffer (JSContextRef ctx, JSBuffer *instance)
{
    JSObjectRef object = JSObjectMake(ctx, CreateClassForJSBuffer(), HyperloopMakePrivateObjectForJSBuffer(instance));
    JSObjectRef value = JSObjectMake(ctx, CreateClassForJSBufferConstructor(), 0);

    JSStringRef cproperty = JSStringCreateWithUTF8CString("constructor");
    JSObjectSetProperty(ctx, object, cproperty, value, kJSPropertyAttributeDontEnum, 0);
    JSStringRelease(cproperty);

    JSStringRef nameProperty = JSStringCreateWithUTF8CString("name");
    JSStringRef valueProperty = JSStringCreateWithUTF8CString("JSBuffer");
    JSValueRef valueRef = JSValueMakeString(ctx, valueProperty);
    JSObjectSetProperty(ctx, value, nameProperty, valueRef, kJSPropertyAttributeDontEnum, 0);
    JSStringRelease(nameProperty);
    JSStringRelease(valueProperty);

    return object;
}
コード例 #19
0
static JSObjectRef createWrappedMessage(JSGlobalContextRef context, WKStringRef data)
{
    static JSStringRef dataName = JSStringCreateWithUTF8CString("data");

    JSRetainPtr<JSStringRef> jsData = WKStringCopyJSString(data);
    JSObjectRef wrappedMessage = JSObjectMake(context, 0, 0);
    JSObjectSetProperty(context, wrappedMessage, dataName, JSValueMakeString(context, jsData.get()), kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0);
    return wrappedMessage;
}
コード例 #20
0
ファイル: JSObject.cpp プロジェクト: garymathews/HAL
 void JSObject::SetProperty(const JSString& property_name, const JSValue& property_value, const std::unordered_set<JSPropertyAttribute>& attributes) {
   HAL_JSOBJECT_LOCK_GUARD;
   
   JSValueRef exception { nullptr };
   JSObjectSetProperty(static_cast<JSContextRef>(js_context__), js_object_ref__, static_cast<JSStringRef>(property_name), static_cast<JSValueRef>(property_value), detail::ToJSPropertyAttributes(attributes), &exception);
   if (exception) {
     detail::ThrowRuntimeError("JSObject", JSValue(js_context__, exception));
   }
 }
コード例 #21
0
ファイル: scripts_state.c プロジェクト: rzel/dim3
bool script_state_load_single(int script_idx,bool checkpoint,char *err_str)
{
	int				prop_name_len,prop_value_len;
	char			prop_name[256];
	char			*prop_value;
	script_type		*script;
	JSStringRef		js_prop_name,js_prop_json;
	JSValueRef		js_prop_value;

	if (script_idx==-1) return(TRUE);

		// get the script

	script=js.script_list.scripts[script_idx];

		// run through the properties to replace
		// a 0 property name length means the end
		// of properties for this script

	while (TRUE) {

			// get the prop name and JSON value

		game_file_get_chunk(&prop_name_len);
		if (prop_name_len==0) break;

		game_file_get_chunk(prop_name);

		game_file_get_chunk(&prop_value_len);
		prop_value=(char*)malloc(prop_value_len);
		if (prop_value==NULL) {
			strcpy(err_str,"Out of Memory");
			return(FALSE);
		}

		game_file_get_chunk(prop_value);

			// process the property

		js_prop_name=JSStringCreateWithUTF8CString(prop_name);

		js_prop_json=JSStringCreateWithUTF8CString(prop_value);
		js_prop_value=JSValueMakeFromJSONString(script->cx,js_prop_json);
		JSStringRelease(js_prop_json);

		JSObjectSetProperty(script->cx,script->global_obj,js_prop_name,js_prop_value,0,NULL);
	
		JSStringRelease(js_prop_name);
	}

		// send load event to script

	scripts_post_event(script_idx,-1,sd_event_state,(checkpoint?sd_event_state_load_checkpoint:sd_event_state_load),0,err_str);

	return(TRUE);
}
コード例 #22
0
ファイル: JSCHelpers.cpp プロジェクト: MaxLap/react-native
void installGlobalFunction(
    JSGlobalContextRef ctx,
    const char* name,
    JSFunction function) {
  auto jsName = JSStringCreateWithUTF8CString(name);
  auto functionObj = makeFunction(ctx, jsName, std::move(function));
  JSObjectRef globalObject = JSContextGetGlobalObject(ctx);
  JSObjectSetProperty(ctx, globalObject, jsName, functionObj, 0, NULL);
  JSStringRelease(jsName);
}
コード例 #23
0
void InspectorController::updateScriptResource(InspectorResource* resource, bool finished, bool failed)
{
    ASSERT(resource->scriptObject);
    ASSERT(m_scriptContext);
    if (!resource->scriptObject || !m_scriptContext)
        return;

    JSValueRef failedValue = JSValueMakeBoolean(m_scriptContext, failed);
    JSValueRef finishedValue = JSValueMakeBoolean(m_scriptContext, finished);

    JSStringRef propertyName = JSStringCreateWithUTF8CString("failed");
    JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName, failedValue, kJSPropertyAttributeNone, 0);
    JSStringRelease(propertyName);

    propertyName = JSStringCreateWithUTF8CString("finished");
    JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName, finishedValue, kJSPropertyAttributeNone, 0);
    JSStringRelease(propertyName);

}
コード例 #24
0
void AccessibilityController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
{
    JSRetainPtr<JSStringRef> accessibilityControllerStr(Adopt, JSStringCreateWithUTF8CString("accessibilityController"));
    
    JSClassRef classRef = getJSClass();
    JSValueRef accessibilityControllerObject = JSObjectMake(context, classRef, this);
    JSClassRelease(classRef);

    JSObjectSetProperty(context, windowObject, accessibilityControllerStr.get(), accessibilityControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
}
コード例 #25
0
ファイル: minidom.c プロジェクト: WebKitNix/webkitnix
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;
}
コード例 #26
0
ファイル: JSCHelpers.cpp プロジェクト: MaxLap/react-native
void installGlobalFunction(
    JSGlobalContextRef ctx,
    const char* name,
    JSObjectCallAsFunctionCallback callback) {
  JSStringRef jsName = JSStringCreateWithUTF8CString(name);
  JSObjectRef functionObj = JSObjectMakeFunctionWithCallback(
      ctx, jsName, callback);
  JSObjectRef globalObject = JSContextGetGlobalObject(ctx);
  JSObjectSetProperty(ctx, globalObject, jsName, functionObj, 0, NULL);
  JSStringRelease(jsName);
}
コード例 #27
0
static void windowObjectCleared(WebKitScriptWorld* world, WebKitWebPage* page, WebKitFrame* frame, gpointer)
{
    JSGlobalContextRef jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world);
    g_assert(jsContext);
    JSObjectRef globalObject = JSContextGetGlobalObject(jsContext);
    g_assert(globalObject);

    JSRetainPtr<JSStringRef> functionName(Adopt, JSStringCreateWithUTF8CString("echo"));
    JSObjectRef function = JSObjectMakeFunctionWithCallback(jsContext, functionName.get(), echoCallback);
    JSObjectSetProperty(jsContext, globalObject, functionName.get(), function, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0);
}
コード例 #28
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);
}
コード例 #29
0
JNIEXPORT void JNICALL WebKit_win32_NATIVE(JSObjectSetProperty)
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2, jintLong arg3, jintLong arg4, jintLongArray arg5)
{
	jintLong *lparg5=NULL;
	WebKit_win32_NATIVE_ENTER(env, that, JSObjectSetProperty_FUNC);
	if (arg5) if ((lparg5 = env->GetIntLongArrayElements(arg5, NULL)) == NULL) goto fail;
	JSObjectSetProperty((JSContextRef)arg0, (JSObjectRef)arg1, (JSStringRef)arg2, (JSValueRef)arg3, (JSPropertyAttributes)arg4, (JSValueRef *)lparg5);
fail:
	if (arg5 && lparg5) env->ReleaseIntLongArrayElements(arg5, lparg5, 0);
	WebKit_win32_NATIVE_EXIT(env, that, JSObjectSetProperty_FUNC);
}
コード例 #30
0
void
JSOSInstaller_maker(JSGlobalContextRef context,JSInstaller* jsinst)
{
    JSStringRef jsinst_name = JSStringCreateWithUTF8CString("JSOSInstaller");
    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    ///JSObjectSetProperty(context, globalObject, jsinst_name, 
    ///    JSObjectMakeConstructor(context, JSNode_class(context), JSNode_construct),
    ///    kJSPropertyAttributeNone, NULL);
    JSObjectSetProperty(context, globalObject, jsinst_name,JSOSInstaller_new(context,jsinst),kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete, NULL);
    JSStringRelease(jsinst_name);
}