예제 #1
0
파일: main.c 프로젝트: HenryHu/weblet
static JSValueRef
js_cb_launcher_submit(JSContextRef context,
                      JSObjectRef function,
                      JSObjectRef self,
                      size_t argc,
                      const JSValueRef argv[],
                      JSValueRef* exception)
{
    if (argc != 2)
        return JSValueMakeNull(context);

    int len = JSValueToNumber(context, argv[0], NULL);
    JSObjectRef arr = JSValueToObject(context, argv[1], NULL);

    static const int CMD_LINE_SIZE = 4096;
    static const int CMD_ARGS_SIZE = 256;

    char  cmd_str_buf[CMD_LINE_SIZE];
    int   cmd_str_buf_cur = 0;
    char *cmd_idx_buf[CMD_ARGS_SIZE];

    if (len == 0 || len >= CMD_ARGS_SIZE) return JSValueMakeNull(context);

    int i;
    for (i = 0; i < len; ++ i)
    {
        JSValueRef cur = JSObjectGetPropertyAtIndex(context, arr, i, NULL);
        JSStringRef str = JSValueToStringCopy(context, cur, NULL);
        size_t l = JSStringGetUTF8CString(str, cmd_str_buf + cmd_str_buf_cur, CMD_LINE_SIZE - cmd_str_buf_cur);
        cmd_idx_buf[i] = cmd_str_buf + cmd_str_buf_cur;
        cmd_str_buf_cur += l;
        JSStringRelease(str);
        JSValueUnprotect(context, cur);
    }
    cmd_idx_buf[i] = 0;

    if (fork() == 0)
    {
        /* Redirect I/O streams */
        freopen("/dev/null", "r", stdin);
        freopen("/dev/null", "w", stdout);
        execvp(cmd_idx_buf[0], cmd_idx_buf);
        fprintf(stderr, "RETURNED");
        exit(1);
    }
    
    return JSValueMakeNull(context);
}
예제 #2
0
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);
}
예제 #3
0
std::string NX::Value::toJSON(unsigned int indent)
{
  JSValueRef exception = nullptr;
  JSStringRef strRef = JSValueCreateJSONString(myContext, myVal, indent, &exception);
  if (exception)
  {
    NX::Object except (myContext, exception);
    throw std::runtime_error (except["message"]->toString());
  }
  std::size_t len = JSStringGetMaximumUTF8CStringSize (strRef);
  std::string str (len, ' ');
  len = JSStringGetUTF8CString (strRef, &str[0], len);
  JSStringRelease (strRef);
  str.resize (len);
  return str;
}
예제 #4
0
static JSValueRef print_callAsFunction(JSContextRef context, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    UNUSED_PARAM(functionObject);
    UNUSED_PARAM(thisObject);
    
    if (argumentCount > 0) {
        JSStringRef string = JSValueToStringCopy(context, arguments[0], NULL);
        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
        char stringUTF8[sizeUTF8];
        JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
        printf("%s\n", stringUTF8);
        JSStringRelease(string);
    }
    
    return JSValueMakeUndefined(context);
}
예제 #5
0
static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
{
    UNUSED_PARAM(context);
    UNUSED_PARAM(constructor);

    if (JSValueIsString(context, possibleValue) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, possibleValue, 0), "throwOnHasInstance")) {
        JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), constructor, JSStringCreateWithUTF8CString("test script"), 1, exception);
        return false;
    }

    JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
    JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, exception), exception);
    JSStringRelease(numberString);

    return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, exception);
}
예제 #6
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;
}
예제 #7
0
파일: JSValue.cpp 프로젝트: CodexLabs/HAL
 JSValue::operator JSString() const {
   HAL_JSVALUE_LOCK_GUARD;
   JSValueRef exception { nullptr };
   JSStringRef js_string_ref = JSValueToStringCopy(static_cast<JSContextRef>(js_context__), js_value_ref__, &exception);
   if (exception) {
     // If this assert fails then we need to JSStringRelease
     // js_string_ref.
     assert(!js_string_ref);
     detail::ThrowRuntimeError("JSValue", JSValue(js_context__, exception));
   }
   
   assert(js_string_ref);
   JSString js_string(js_string_ref);
   JSStringRelease(js_string_ref);
   
   return js_string;
 }
예제 #8
0
파일: functions.c 프로젝트: mfikes/planck
JSValueRef function_file_writer_write(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
                                      size_t argc, const JSValueRef args[], JSValueRef *exception) {
    if (argc == 2
        && JSValueGetType(ctx, args[0]) == kJSTypeString
        && JSValueGetType(ctx, args[1]) == kJSTypeString) {

        char *descriptor = value_to_c_string(ctx, args[0]);
        JSStringRef str_ref = JSValueToStringCopy(ctx, args[1], NULL);

        ufile_write(descriptor_str_to_int(descriptor), str_ref);

        free(descriptor);
        JSStringRelease(str_ref);
    }

    return JSValueMakeNull(ctx);
}
    void JavaScriptModuleInstance::Run()
    {
        std::string code(FileUtils::ReadFile(this->path));

        // 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);
        }

        KJSUtil::Evaluate(context, code.c_str());
    }
예제 #10
0
파일: ext-util.c 프로젝트: cdlscpmv/vimb
/**
 * Returns a new allocates string for given value reference.
 * String must be freed if not used anymore.
 */
char* ext_util_js_ref_to_string(JSContextRef ctx, JSValueRef ref)
{
    char *string;
    size_t len;
    JSStringRef str_ref;

    g_return_val_if_fail(ref != NULL, NULL);

    str_ref = JSValueToStringCopy(ctx, ref, NULL);
    len     = JSStringGetMaximumUTF8CStringSize(str_ref);

    string = g_new0(char, len);
    JSStringGetUTF8CString(str_ref, string, len);
    JSStringRelease(str_ref);

    return string;
}
예제 #11
0
static char *js2utf8(JSContextRef ctx, JSValueRef val, size_t* out_len) {
	JSStringRef str = JSValueToStringCopy(ctx, val, NULL);
	size_t max = 0, len;
	char *buf;

	max = JSStringGetMaximumUTF8CStringSize(str);
	buf = malloc(max);
	len = JSStringGetUTF8CString(str, buf, max);

	if (out_len) {
		*out_len = len;
	}

	JSStringRelease(str);

	return buf;
}
HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::checkNotificationPermission(
        /* [in] */ BSTR origin, 
        /* [out, retval] */ int* result)
{
#if ENABLE(NOTIFICATIONS)
    JSStringRef jsOrigin = JSStringCreateWithBSTR(origin);
    bool allowed = ::gLayoutTestController->checkDesktopNotificationPermission(jsOrigin);

    if (allowed)
        *result = WebCore::NotificationPresenter::PermissionAllowed;
    else
        *result = WebCore::NotificationPresenter::PermissionDenied;

    JSStringRelease(jsOrigin);
#endif
    return S_OK;
}
예제 #13
0
size_t VJSArray::GetLength() const
{
	size_t length;
	JSStringRef jsString = JSStringCreateWithUTF8CString( "length");
	JSValueRef result = JSObjectGetProperty( fContext, fObject, jsString, NULL);
	JSStringRelease( jsString);
	if (testAssert( result != NULL))
	{
		double r = JSValueToNumber( fContext, result, NULL);
		length = (size_t) r;
	}
	else
	{
		length = 0;
	}
	return length;
}
예제 #14
0
파일: ext-util.c 프로젝트: cdlscpmv/vimb
/**
 * 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;
}
예제 #15
0
void js_fill_exception(JSContextRef ctx,
                       JSValueRef* excp,
                       const char* format,
                       ...)
{
    va_list args;
    va_start (args, format);
    char* str = g_strdup_vprintf(format, args);
    va_end(args);

    JSStringRef string = JSStringCreateWithUTF8CString(str);
    JSValueRef exc_str = JSValueMakeString(ctx, string);
    JSStringRelease(string);
    g_free(str);

    *excp= JSValueToObject(ctx, exc_str, NULL);
}
예제 #16
0
static JSValueRef nativeProfilerEnd(
    JSContextRef ctx,
    JSObjectRef function,
    JSObjectRef thisObject,
    size_t argumentCount,
    const JSValueRef arguments[],
    JSValueRef* exception) {
  if (argumentCount < 1) {
    // Could raise an exception here.
    return JSValueMakeUndefined(ctx);
  }

  JSStringRef title = JSValueToStringCopy(ctx, arguments[0], NULL);
  JSEndProfilingAndRender(ctx, title, "/sdcard/profile.json");
  JSStringRelease(title);
  return JSValueMakeUndefined(ctx);
}
예제 #17
0
파일: main.c 프로젝트: yuyichao/explore
void
print_js(JSContextRef ctx, JSValueRef jsvalue)
{
    if (!jsvalue)
        return;
    JSStringRef jsstr = JSValueToStringCopy(ctx, jsvalue, NULL);
    int length = JSStringGetMaximumUTF8CStringSize(jsstr);
    if (length > 0) {
        char buf[length + 1];
        JSStringGetUTF8CString(jsstr, buf, length);
        printf("%d: %s\n", length, buf);
    } else {
        printf("l <= 0\n");
    }
    if (jsstr)
        JSStringRelease(jsstr);
}
예제 #18
0
void InspectorController::updateScriptResourceResponse(InspectorResource* resource)
{
    ASSERT(resource->scriptObject);
    ASSERT(m_scriptContext);
    if (!resource->scriptObject || !m_scriptContext)
        return;

    JSStringRef mimeType = JSStringCreateWithCharacters(resource->mimeType.characters(), resource->mimeType.length());
    JSValueRef mimeTypeValue = JSValueMakeString(m_scriptContext, mimeType);
    JSStringRelease(mimeType);

    JSStringRef suggestedFilename = JSStringCreateWithCharacters(resource->suggestedFilename.characters(), resource->suggestedFilename.length());
    JSValueRef suggestedFilenameValue = JSValueMakeString(m_scriptContext, suggestedFilename);
    JSStringRelease(suggestedFilename);

    JSValueRef expectedContentLengthValue = JSValueMakeNumber(m_scriptContext, static_cast<double>(resource->expectedContentLength));
    JSValueRef statusCodeValue = JSValueMakeNumber(m_scriptContext, resource->responseStatusCode);

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

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

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

    propertyName = JSStringCreateWithUTF8CString("statusCode");
    JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName, statusCodeValue, kJSPropertyAttributeNone, 0);
    JSStringRelease(propertyName);
    
    propertyName = JSStringCreateWithUTF8CString("responseHeaders");
    JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName, scriptObjectForResponse(m_scriptContext, resource), kJSPropertyAttributeNone, 0);
    JSStringRelease(propertyName);

    JSValueRef typeValue = JSValueMakeNumber(m_scriptContext, resource->type());
    propertyName = JSStringCreateWithUTF8CString("type");
    JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName, typeValue, kJSPropertyAttributeNone, 0);
    JSStringRelease(propertyName);
}
예제 #19
0
파일: JSBindings.cpp 프로젝트: Omgan/CallJS
/**
 * The callback from JavaScriptCore.  We told JSC to call this function
 * whenever it sees "console.report".
 */
static JSValueRef console_report(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception)
{
    if (!JSValueIsObjectOfClass(ctx, thisObject, ConsoleClass()))
        return JSValueMakeUndefined(ctx);

    CallJSDlg* dlg = static_cast<CallJSDlg*>(JSObjectGetPrivate(thisObject));
    if (!dlg)
        return JSValueMakeUndefined(ctx);

    if (argumentCount)
        return JSValueMakeUndefined(ctx);

    JSStringRef jsString = JSStringCreateWithBSTR(dlg->sharedString());
    JSValueRef jsValue = JSValueMakeString(ctx, jsString);
    JSStringRelease(jsString);

    return jsValue;
}
예제 #20
0
static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
{
    JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);

    size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
    char jsBuffer[jsSize];
    JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
    
    unsigned i;
    for (i = 0; jsBuffer[i]; i++)
        if (jsBuffer[i] != expectedValue[i])
            fprintf(stderr, "assertEqualsAsUTF8String failed at character %d: %c(%d) != %c(%d)\n", i, jsBuffer[i], jsBuffer[i], expectedValue[i], expectedValue[i]);
        
    if (jsSize < strlen(jsBuffer) + 1)
        fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");

    JSStringRelease(valueAsString);
}
예제 #21
0
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);
}
예제 #22
0
static VALUE js2rb(JSContextRef ctx, JSValueRef val) {
	VALUE output = Qnil;
	JSStringRef str = JSValueToStringCopy(ctx, val, NULL);

	size_t len = 0;
	size_t max = 0;
	char *buf;

	max = JSStringGetMaximumUTF8CStringSize(str);
	buf = malloc(max);
	len = JSStringGetUTF8CString(str, buf, max);

	output = rb_str_new(buf, len-1); // Ignore terminator
	free(buf);

	JSStringRelease(str);
	return output;
}
예제 #23
0
EJ_BIND_SET( EJBindingCanvas,font, ctx, value) {
 	char string[64]; // Long font names are long
 	JSStringRef jsString = JSValueToStringCopy( ctx, value, NULL );
 	JSStringGetUTF8CString(jsString, string, 64);

 	// Yeah, oldschool!
 	float size = 0;
 	char name[64];
 	sscanf( string, "%fp%*[tx] %63s", &size, name); // matches: 10.5p[tx] helvetica
	
 	UIFont * newFont = new UIFont(NSStringMake("droidsans.ttf"),size);
 	if( newFont ) {
		renderingContext->state->font->release();
 	 	renderingContext->state->font = newFont;
 	}

 	JSStringRelease(jsString);
}
예제 #24
0
bool JS4D::ConvertErrorContextToException( ContextRef inContext, VErrorContext *inErrorContext, ExceptionRef *outException)
{
	bool exceptionGenerated;
	if ( (inErrorContext != NULL) && !inErrorContext->IsEmpty() && (outException != NULL) )
	{
		exceptionGenerated = true;
		VErrorBase *error = inErrorContext->GetLast();
		
		if ( (error != NULL) && (*outException == NULL) )	// don't override existing exception
		{
			VString description;
			for( VErrorStack::const_reverse_iterator i = inErrorContext->GetErrorStack().rbegin() ; description.IsEmpty() && (i != inErrorContext->GetErrorStack().rend()) ; ++i)
			{
				(*i)->GetErrorDescription( description);
			}
		
			JSStringRef jsString = JS4D::VStringToString( description);
			JSValueRef argumentsErrorValues[] = { JSValueMakeString( inContext, jsString) };
			JSStringRelease( jsString);

			*outException = JSObjectMakeError( inContext, 1, argumentsErrorValues, NULL);
			if ( *outException != NULL )
			{
				VJSObject e(inContext, JSValueToObject(inContext, *outException, nil));
				VJSArray arr(inContext);

				for( VErrorStack::const_reverse_iterator i = inErrorContext->GetErrorStack().rbegin() ; (i != inErrorContext->GetErrorStack().rend()) ; ++i)
				{
					(*i)->GetErrorDescription( description);
					VJSValue jsdesc(inContext);
					jsdesc.SetString(description);
					arr.PushValue(jsdesc);
				}

				e.SetProperty("messages", arr, PropertyAttributeNone);
			}
		}
	}
	else
	{
		exceptionGenerated = false;
	}
	return exceptionGenerated;
}
예제 #25
0
JSValueRef JSCArrayBuffer::sliceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {

	struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj);

	if (false) {
	} else if (argumentCount == 2 &&
	           JSValueIsNumber(ctx, arguments[0]) &&
	           JSValueIsNumber(ctx, arguments[1])) {
		long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception);
		long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception);

		uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd));
		JSClassRef retClass = JSCArrayBuffer::getTmpl();

		struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate();
		retPrivData->dom = privData->dom;
		retPrivData->nativeObj = retVal;

		JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);

		return retObj;

	} else if (argumentCount == 1 &&
	           JSValueIsNumber(ctx, arguments[0])) {
		long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception);

		uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin));
		JSClassRef retClass = JSCArrayBuffer::getTmpl();

		struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate();
		retPrivData->dom = privData->dom;
		retPrivData->nativeObj = retVal;

		JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);

		return retObj;

	}

	JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling slice");
	*exception = JSValueMakeString(ctx, exceptionString);
	JSStringRelease(exceptionString);
	return JSValueMakeUndefined(ctx);
}
예제 #26
0
static void didRunJavaScript(WKSerializedScriptValueRef resultSerializedScriptValue, WKErrorRef error, void* context)
{
    EXPECT_EQ(reinterpret_cast<void*>(0x1234578), context);
    EXPECT_NOT_NULL(resultSerializedScriptValue);

    JSGlobalContextRef scriptContext = JSGlobalContextCreate(0);
    JSValueRef scriptValue = WKSerializedScriptValueDeserialize(resultSerializedScriptValue, scriptContext, 0);
    EXPECT_TRUE(JSValueIsString(scriptContext, scriptValue));

    // Make sure that the result of navigator.userAgent isn't empty, even if we set the custom
    // user agent to the empty string.
    JSStringRef scriptString = JSValueToStringCopy(scriptContext, scriptValue, 0);
    EXPECT_GT(JSStringGetLength(scriptString), 0u);

    JSStringRelease(scriptString);
    JSGlobalContextRelease(scriptContext);

    testDone = true;
}
예제 #27
0
/**
 * run JS in a new context and return result
 */
static JSValueRef RunInNewContext(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (argumentCount > 0) 
    {
        std::ostringstream stream;
        std::string js(HyperloopJSValueToStringCopy(ctx,arguments[0],exception));
        stream << "(function(){" << js << "})";
        auto newCtx = JSGlobalContextCreateInGroup(globalContextGroupRef,nullptr);
        auto scriptRef = JSStringCreateWithUTF8CString(stream.str().c_str());
        auto thisObjectRef = argumentCount > 1 ? JSValueToObject(ctx,arguments[1],exception) : thisObject;
        auto functionRef = JSEvaluateScript(newCtx,scriptRef,thisObjectRef,nullptr,0,exception);
        auto functionObj = JSValueToObject(newCtx,functionRef,exception);
        auto resultRef = JSObjectCallAsFunction(newCtx,functionObj,thisObjectRef,0,nullptr,exception);
        JSStringRelease(scriptRef);
        JSGlobalContextRelease(newCtx);
        return resultRef;
    } 
    return JSValueMakeUndefined(ctx);   
}
예제 #28
0
파일: functions.c 프로젝트: mfikes/planck
JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
                                  size_t argc, const JSValueRef args[], JSValueRef *exception) {
    if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
        JSStringRef path_str_ref = JSValueToStringCopy(ctx, args[0], NULL);
        assert(JSStringGetLength(path_str_ref) < 100);
        char tmp[100];
        tmp[0] = '\0';
        JSStringGetUTF8CString(path_str_ref, tmp, 100);
        JSStringRelease(path_str_ref);

        bool can_skip_load = false;
        char *path = tmp;
        if (str_has_prefix(path, "goog/../") == 0) {
            path = path + 8;
        } else {
            unsigned long h = hash((unsigned char *) path);
            if (is_loaded(h)) {
                can_skip_load = true;
            } else {
                add_loaded_hash(h);
            }
        }

        if (!can_skip_load) {
            char *source = NULL;
            if (config.out_path == NULL) {
                source = bundle_get_contents(path);
            } else {
                char *full_path = str_concat(config.out_path, path);
                source = get_contents(full_path, NULL);
                free(full_path);
            }

            if (source != NULL) {
                evaluate_script(ctx, source, path);
                display_launch_timing(path);
                free(source);
            }
        }
    }

    return JSValueMakeUndefined(ctx);
}
예제 #29
0
파일: testapi.c 프로젝트: acss/owb-mirror
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);
}
예제 #30
0
파일: webview.c 프로젝트: stuartpb/retik
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);
}