javascriptcore

How to test functions within Javascriptcore?

余生长醉 提交于 2020-01-13 16:23:00
问题 I have seen many examples where someone takes a JavaScript function and evaluates it by doing something like: JSContext *context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; [context evaluateScript:@"var add = function(a, b) {return a + b;}"]; NSLog(@"%@", [context[@"add"] callWithArguments:@[@20, @30]]); //Output is 50 But how can we run test cases on the function? By calling arguments we can see the result (assuming it doesn't throw an exception). In the

How to test functions within Javascriptcore?

大憨熊 提交于 2020-01-13 16:20:17
问题 I have seen many examples where someone takes a JavaScript function and evaluates it by doing something like: JSContext *context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; [context evaluateScript:@"var add = function(a, b) {return a + b;}"]; NSLog(@"%@", [context[@"add"] callWithArguments:@[@20, @30]]); //Output is 50 But how can we run test cases on the function? By calling arguments we can see the result (assuming it doesn't throw an exception). In the

Can't JSExport an Objective-C Method With More Than One Parameter?

假装没事ソ 提交于 2020-01-12 08:45:17
问题 Consider this: @protocol FooExport <JSExport> - (void)method1:(NSString *)param1; - (void)method2:(NSString *)param1 param2:(NSString *)param2; @end @interface Foo : NSObject <FooExport> @end @implementation Foo - (void)method1:(NSString *)param1 { NSLog(@"method1"); } - (void)method2:(NSString *)param1 param2:(NSString *)param2 { NSLog(@"method2"); } @end { sContext = [[JSContext alloc] init]; if (sContext) { sContext[@"foo"] = [[Foo alloc] init]; [sContext evaluateScript:@"foo.method1(\"foo

Javascript canvas pixel manipulation

强颜欢笑 提交于 2020-01-05 02:30:07
问题 I have product images and each image has two configurable areas as below: 1. background 2. Foreground I have to develop a feature where customer can change the color of both areas and save the design. My problem is, i am traversing the image to read old pixel value and change it with new selected color. Bit old pixel values are not consistent. There is textured effect on the image, which is causing the pixel value to be changed at every pixel. How can i achieve the desired the functionality?

JavaScriptCore External Arrays

点点圈 提交于 2020-01-04 11:02:15
问题 I've been messing around with JavaScriptCore for iOS and I've been trying to figure out a way to do something along the lines of "SetIndexedPropertiesToExternalArrayData" from v8, where I would have a javascript object, and set it's array data to point to another object's array. For example, if I were to have an empty javascript object, and another javascript object that looked like: { '0': 0, '1': 1, '2': 2 }; and if I were to make the empty javascript object point to the array object,

Using setInterval, setTimeout in JavascriptCore Framework for ObjectiveC

妖精的绣舞 提交于 2020-01-04 02:02:07
问题 I've been experimenting with the new Objective C JavascriptCore Framework. This is crazy, but it seems that it doesn't have setTimeout or setInterval . Which... I don't understand. Am I right about this? Are there alternatives? I could potentially create the timer in Objective C but most of my library is written in Javascript, and aside from that, it seems just weird not having setInterval or setTimeout !! I've tried a few alternative methods: window.setInterval(function(){ /* dosomething */

How to pass C++ object to JavaScript function using JavaScriptCore

╄→尐↘猪︶ㄣ 提交于 2020-01-03 04:40:27
问题 I've written a function in JavaScript in an external JavaScript file sample.js . function fileInfo(obj) { ///// } I have a class defined in the sample.cpp file as follows : class sample { int i; /// }; /// int main() { sample obj; /// /// } How can we pass obj to the JavaScript function "fileInfo" as a parameter? 回答1: You cannot directly pass an object encoded in one programming language to another program written in a different programming language. This is not possible since the binary

Cocoa/Mac: JavaScript Core crash on the 38th call

回眸只為那壹抹淺笑 提交于 2019-12-24 02:55:07
问题 We are developing a Cocoa app for Mac OSX (10.8) which needs to use a JavaScript library (long story why we must use JavaScript). In a demo application everything seemed to be just fine, but while incorporating the code in our project, we can call the function 37 times without issues and then crashes the 38th time. To call the JS code we are using Apple's JSWrappers.m (from the JavaScriptCoreHeadStart example). The line that crashes (with a EXC_BAD_ACCESS) is #149: JSObjectCallAsFunction(self

Call to swift method from JavaScript hangs xcode and application

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 09:18:03
问题 I am writing an iOS App (using xcode 7.3 and swift 2.2) using JavascriptCode framework. Calling javascript methods from swift works perfect, but when I call the swift method from javascript, xcode simply shows a "loading" type of symbol and nothing happens. I need to "force quit" xcode to get out of this state. I have followed https://www.raywenderlich.com/124075/javascriptcore-tutorial and http://nshipster.com/javascriptcore/ and I am trying pretty simple calls. Has anyone faced this kind of

JavascriptCore: pass javascript function as parameter in JSExport

若如初见. 提交于 2019-12-21 18:33:22
问题 JavascriptCore is a new framework supported in iOS7. We can use the JSExport protocol to expose parts of objc class to JavaScript. In javascript, I tried to pass function as parameter. Just like this: function getJsonCallback(json) { movie = JSON.parse(json) renderTemplate() } viewController.getJsonWithURLCallback("", getJsonCallback) In my objc viewController, I defined my protocol: @protocol FetchJsonForJS <JSExport> - (void)getJsonWithURL:(NSString *)URL callback:(void (^)(NSString *json)