javascriptcore

JavaScript - Object definition available before code execution on Safari

孤街浪徒 提交于 2019-12-07 04:55:26
Objects and functions which I require only to execute once on a page load are wrapped inside an undefined check for the object. On Chrome on Windows/Linux which I usually use, the code works perfectly i.e. code only executes once. But on Safari on both iPad and MacBook, the undefined check doesn't work i.e. as per the browser, the object/function is already declared without even the code execution reaching there! I've simplified my code to only include an if loop that checks if the nested function is already declared. Since it should not have been declared the first time, I've included

Using React Native within an iOS share extension

ぃ、小莉子 提交于 2019-12-07 03:40:18
问题 Jumping off of this facebook/react-native#1626 GitHub issue, I had a question about setting up a React Native view within an iOS share extension I posted an example GitHub repo that demonstrates the problem, summarized below. So far the proof-of-concept setup is pretty straightforward, but I feel like I'm missing something very simple. In my react-native init scaffolded Xcode project I created a new Share Extension target, and within it linked the appropriate React Native static libraries (

iOS implemention of “window.setTimeout” with JavascriptCore

↘锁芯ラ 提交于 2019-12-06 01:34:09
问题 I am using JavaScriptCore library inside iOS application and I am trying to implement setTimeout function. setTimeout(func, period) After application is launched, the JSC engine with global context is created and two functions are added to that context: _JSContext = JSGlobalContextCreate(NULL); [self mapName:"iosSetTimeout" toFunction:_setTimeout]; [self mapName:"iosLog" toFunction:_log]; Here is native implementation that is mapping global JS function with desired name to static objective C

Using JSContextGroupSetExecutionTimeLimit in iOS

半腔热情 提交于 2019-12-06 01:12:14
I need to stop the execution of Javascript in a JSContext object? I found the following method which exactly what I need @function @abstract Sets the script execution time limit. @param group The JavaScript context group that this time limit applies to. @param limit The time limit of allowed script execution time in seconds. @param callback The callback function that will be invoked when the time limit has been reached. This will give you a chance to decide if you want to terminate the script or not. If you pass a NULL callback, the script will be terminated unconditionally when the time limit

How to test functions within Javascriptcore?

时间秒杀一切 提交于 2019-12-05 19:22:51
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 event it does throw an exception we can set an exception handler on the context prior to calling the code.

iOS Crash related to javascript core, web thread

三世轮回 提交于 2019-12-05 06:54:09
问题 getting lots of crashes in ios11 as below: webkit framework is included in project. any idea what could be reason for this crash ? Crashed: WebThread 0 JavaScriptCore 0x18bdbeebc bmalloc::Heap::allocateSmallChunk(std::__1::lock_guard<bmalloc::StaticMutex>&, unsigned long) + 680 1 JavaScriptCore 0x18bdbec70 bmalloc::Heap::allocateSmallChunk(std::__1::lock_guard<bmalloc::StaticMutex>&, unsigned long) + 92 2 JavaScriptCore 0x18bdbef58 bmalloc::Heap::allocateSmallPage(std::__1::lock_guard<bmalloc

Using React Native within an iOS share extension

我怕爱的太早我们不能终老 提交于 2019-12-05 06:15:39
Jumping off of this facebook/react-native#1626 GitHub issue , I had a question about setting up a React Native view within an iOS share extension I posted an example GitHub repo that demonstrates the problem, summarized below. So far the proof-of-concept setup is pretty straightforward, but I feel like I'm missing something very simple. In my react-native init scaffolded Xcode project I created a new Share Extension target, and within it linked the appropriate React Native static libraries ( libReact.a , libRCTWebSocket.a , etc.). This gets our project compiling for a very simple

Should I avoid creating JSContexts in global queues?

大憨熊 提交于 2019-12-05 01:08:35
问题 I've just had a crash log from a customer's device, and it's crashing here: dispatch_async(dispatch_get_global_queue(0, 0), ^{ JSContext *javaScriptContext = [[JSContext alloc] init]; Here's the crash log: Thread 11 Crashed: 0 JavaScriptCore 0x31009cd6 WTFCrash + 54 1 JavaScriptCore 0x30e0edf6 WTF::OSAllocator::reserveAndCommit(unsigned long, WTF::OSAllocator::Usage, bool, bool, bool) + 166 2 JavaScriptCore 0x30e0ed2a WTF::OSAllocator::reserveUncommitted(unsigned long, WTF::OSAllocator::Usage

JavascriptCore: pass javascript function as parameter in JSExport

大憨熊 提交于 2019-12-04 11:51:08
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))callback; - (void)getJsonWithURL:(NSString *)URL callbackScript:(NSString *)script; @end In javascript,

iOS implemention of “window.setTimeout” with JavascriptCore

血红的双手。 提交于 2019-12-04 06:47:25
I am using JavaScriptCore library inside iOS application and I am trying to implement setTimeout function. setTimeout(func, period) After application is launched, the JSC engine with global context is created and two functions are added to that context: _JSContext = JSGlobalContextCreate(NULL); [self mapName:"iosSetTimeout" toFunction:_setTimeout]; [self mapName:"iosLog" toFunction:_log]; Here is native implementation that is mapping global JS function with desired name to static objective C function: - (void) mapName:(const char*)name toFunction:(JSObjectCallAsFunctionCallback)func {