"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7693/ios/sdk/src/JavaScriptSandbox.m" (8 Dec 2023, 1543 Bytes) of package /linux/misc/jitsi-meet-7693.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * Copyright @ 2019-present 8x8, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 @import JavaScriptCore;
18
19 #import <React/RCTBridgeModule.h>
20
21
22 @interface JavaScriptSandbox : NSObject<RCTBridgeModule>
23 @end
24
25 @implementation JavaScriptSandbox
26
27 RCT_EXPORT_MODULE();
28
29 + (BOOL)requiresMainQueueSetup {
30 return NO;
31 }
32
33 #pragma mark - Exported methods
34
35 RCT_EXPORT_METHOD(evaluate:(NSString *)code
36 resolve:(RCTPromiseResolveBlock)resolve
37 reject:(RCTPromiseRejectBlock)reject) {
38 __block BOOL hasError = NO;
39 JSContext *ctx = [[JSContext alloc] init];
40 ctx.exceptionHandler = ^(JSContext *context, JSValue *exception) {
41 hasError = YES;
42 reject(@"evaluate", [exception toString], nil);
43 };
44 JSValue *ret = [ctx evaluateScript:code];
45 if (!hasError) {
46 NSString *result = [ret toString];
47 if (result == nil) {
48 reject(@"evaluate", @"Error in string coercion", nil);
49 } else {
50 resolve(result);
51 }
52 }
53 }
54
55 @end