javascriptcore

iOS 8 JavaScriptCore: Where do you place your JavaScript files at?

怎甘沉沦 提交于 2021-02-08 09:24:31
问题 How do you add a JS file to the home directory so that 's' does not return 'nil'. Thanks. func analyzeText(text: String) { let homeDir = NSHomeDirectory() var err: NSError? = NSError() let s = String(contentsOfFile: homeDir + "/text.js", encoding: NSUTF8StringEncoding, error: &err) println(s) var context = JSContext(virtualMachine: JSVirtualMachine()) context.evaluateScript(s) let analyzeText = context.objectForKeyedSubscript("analyzeText") let analyzeTextVal = analyzeText.callWithArguments(

Force garbage collection of JavaScriptCore virtual machine on iOS

こ雲淡風輕ζ 提交于 2021-01-27 05:24:49
问题 Is there any way to force iOS (or Mac OS) JavaScriptCore VM garbage collector to run? I need it only to test for memory leaks, so private API would be fine. 回答1: Use following function from JSBase.h: /*! @function JSGarbageCollect @abstract Performs a JavaScript garbage collection. @param ctx The execution context to use. @discussion JavaScript values that are on the machine stack, in a register, protected by JSValueProtect, set as the global object of an execution context, or reachable from

Force garbage collection of JavaScriptCore virtual machine on iOS

强颜欢笑 提交于 2021-01-27 05:24:38
问题 Is there any way to force iOS (or Mac OS) JavaScriptCore VM garbage collector to run? I need it only to test for memory leaks, so private API would be fine. 回答1: Use following function from JSBase.h: /*! @function JSGarbageCollect @abstract Performs a JavaScript garbage collection. @param ctx The execution context to use. @discussion JavaScript values that are on the machine stack, in a register, protected by JSValueProtect, set as the global object of an execution context, or reachable from

Access to filesystem in a Mac App JSContext

倾然丶 夕夏残阳落幕 提交于 2020-06-17 00:56:33
问题 I am working on a Mac app that uses a JSContext for some functionality. It uses a call like this (where ctx is a JSContext ): let result: JSValue? = ctx.evaluateScript("someFunction")?.call(withArguments: [someArg1!, someArg2]) Inside the someFunction script, we need to parse a directory and determine whether it exists on the filesystem. Apple's JavaScriptCore API does not have filesystem access as far as I can tell. Is there some way I can have a function like this in swift: public static

Access to filesystem in a Mac App JSContext

喜夏-厌秋 提交于 2020-06-17 00:56:03
问题 I am working on a Mac app that uses a JSContext for some functionality. It uses a call like this (where ctx is a JSContext ): let result: JSValue? = ctx.evaluateScript("someFunction")?.call(withArguments: [someArg1!, someArg2]) Inside the someFunction script, we need to parse a directory and determine whether it exists on the filesystem. Apple's JavaScriptCore API does not have filesystem access as far as I can tell. Is there some way I can have a function like this in swift: public static

Access to filesystem in a Mac App JSContext

寵の児 提交于 2020-06-17 00:55:32
问题 I am working on a Mac app that uses a JSContext for some functionality. It uses a call like this (where ctx is a JSContext ): let result: JSValue? = ctx.evaluateScript("someFunction")?.call(withArguments: [someArg1!, someArg2]) Inside the someFunction script, we need to parse a directory and determine whether it exists on the filesystem. Apple's JavaScriptCore API does not have filesystem access as far as I can tell. Is there some way I can have a function like this in swift: public static

How to stop JavaScriptCore JSContext evaluating by force on iOS?

南笙酒味 提交于 2020-05-17 08:48:51
问题 The bounty expires in 4 days . Answers to this question are eligible for a +50 reputation bounty. Suge wants to draw more attention to this question. Sometime the script being evaluated should be stopped by force, but I can't find a way to achieve this. Someone pointed out JSContextGroupSetExecutionTimeLimit might work, but It doesn't in my testing, can anyone help? Another reference: https://github.com/phoboslab/JavaScriptCore-iOS/issues/14 My code: int extendTerminateCallbackCalled = 0;

How to import modules in Swift's JavaScriptCore?

对着背影说爱祢 提交于 2020-02-21 10:33:07
问题 I'm trying to use Swift's JavaScriptCore framework to take advantage of an existing JavaScript library that uses ES6 modules. Specifically, morse-pro by Stephen C Phillips. I've added the files to an Xcode playground, then used this code to load the library and run it in the JavaScript context: import JavaScriptCore var jsContext = JSContext() // set up exception handler for javascript errors jsContext?.exceptionHandler = { context, exception in if let exc = exception { print("JS Exception:",

How to import modules in Swift's JavaScriptCore?

余生长醉 提交于 2020-02-21 10:30:29
问题 I'm trying to use Swift's JavaScriptCore framework to take advantage of an existing JavaScript library that uses ES6 modules. Specifically, morse-pro by Stephen C Phillips. I've added the files to an Xcode playground, then used this code to load the library and run it in the JavaScript context: import JavaScriptCore var jsContext = JSContext() // set up exception handler for javascript errors jsContext?.exceptionHandler = { context, exception in if let exc = exception { print("JS Exception:",

How to list all of javascript functions beginning with _func

筅森魡賤 提交于 2020-01-14 04:22:23
问题 Is it possible to list / return in an array all javascript functions in my own .js file that begin with the string "_func"? Done in WebKit's JSCore. Basically, if my file has a bunch of functions, how do I enumerate those functions? 回答1: You can loop through the members of the window object and test them: var functions = []; for( var x in window) { if(typeof window[x] === "function" && x.indexOf("_func") === 0) { functions.push(x); } } 回答2: You can do it by iterating over the members of the