3333#if RCT_JSC_PROFILER
3434#include < dlfcn.h>
3535
36- static NSString * const RCTJSCProfilerEnabledDefaultsKey = @" RCTJSCProfilerEnabled" ;
36+ static NSString *const RCTJSCProfilerEnabledDefaultsKey = @" RCTJSCProfilerEnabled" ;
3737
3838#ifndef RCT_JSC_PROFILER_DYLIB
3939#define RCT_JSC_PROFILER_DYLIB [[[NSBundle mainBundle ] pathForResource: [NSString stringWithFormat: @" RCTJSCProfiler.ios%zd " , [[[UIDevice currentDevice ] systemVersion ] integerValue ]] ofType: @" dylib" inDirectory: @" RCTJSCProfiler" ] UTF8String ]
@@ -119,26 +119,14 @@ @implementation RCTContextExecutor
119119static JSValueRef RCTNativeLoggingHook(JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
120120{
121121 if (argumentCount > 0 ) {
122- JSStringRef messageRef = JSValueToStringCopy (context, arguments[0 ], exception);
123- if (!messageRef) {
124- return JSValueMakeUndefined (context);
125- }
126- NSString *message = (__bridge_transfer NSString *)JSStringCopyCFString (kCFAllocatorDefault , messageRef);
127- JSStringRelease (messageRef);
128- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
129- @" ( stack: )?([_a-z0-9]*)@?(http://|file:///)[a-z.0-9:/_-]+/([a-z0-9_]+).bundle(:[0-9]+:[0-9]+)"
130- options: NSRegularExpressionCaseInsensitive
131- error: NULL ];
132- message = [regex stringByReplacingMatchesInString: message
133- options: 0
134- range: (NSRange ){0 , message.length }
135- withTemplate: @" [$4$5] \t $2" ];
122+ NSString *message = RCTJSValueToNSString (context, arguments[0 ], exception);
136123
137124 RCTLogLevel level = RCTLogLevelInfo;
138125 if (argumentCount > 1 ) {
139- level = MAX (level, JSValueToNumber (context, arguments[1 ], exception) - 1 );
126+ level = MAX (level, JSValueToNumber (context, arguments[1 ], exception));
140127 }
141- RCTGetLogFunction ()(level, nil , nil , message);
128+
129+ _RCTLog (level, @" %@ " , message);
142130 }
143131
144132 return JSValueMakeUndefined (context);
@@ -152,18 +140,22 @@ static JSValueRef RCTNoop(JSContextRef context, __unused JSObjectRef object, __u
152140 return JSValueMakeUndefined (context);
153141}
154142
155- static NSString *RCTJSValueToNSString (JSContextRef context, JSValueRef value)
143+ static NSString *RCTJSValueToNSString (JSContextRef context, JSValueRef value, JSValueRef *exception )
156144{
157- JSStringRef JSString = JSValueToStringCopy (context, value, NULL );
145+ JSStringRef JSString = JSValueToStringCopy (context, value, exception);
146+ if (!JSString) {
147+ return nil ;
148+ }
149+
158150 CFStringRef string = JSStringCopyCFString (kCFAllocatorDefault , JSString);
159151 JSStringRelease (JSString);
160152
161153 return (__bridge_transfer NSString *)string;
162154}
163155
164- static NSString *RCTJSValueToJSONString (JSContextRef context, JSValueRef value, unsigned indent)
156+ static NSString *RCTJSValueToJSONString (JSContextRef context, JSValueRef value, JSValueRef *exception, unsigned indent)
165157{
166- JSStringRef JSString = JSValueCreateJSONString (context, value, indent, NULL );
158+ JSStringRef JSString = JSValueCreateJSONString (context, value, indent, exception );
167159 CFStringRef string = JSStringCopyCFString (kCFAllocatorDefault , JSString);
168160 JSStringRelease (JSString);
169161
@@ -172,14 +164,14 @@ static JSValueRef RCTNoop(JSContextRef context, __unused JSObjectRef object, __u
172164
173165static NSError *RCTNSErrorFromJSError (JSContextRef context, JSValueRef jsError)
174166{
175- NSString *errorMessage = jsError ? RCTJSValueToNSString (context, jsError) : @" unknown JS error" ;
176- NSString *details = jsError ? RCTJSValueToJSONString (context, jsError, 2 ) : @" no details" ;
167+ NSString *errorMessage = jsError ? RCTJSValueToNSString (context, jsError, NULL ) : @" unknown JS error" ;
168+ NSString *details = jsError ? RCTJSValueToJSONString (context, jsError, NULL , 2 ) : @" no details" ;
177169 return [NSError errorWithDomain: @" JS" code: 1 userInfo: @{NSLocalizedDescriptionKey : errorMessage, NSLocalizedFailureReasonErrorKey : details}];
178170}
179171
180172#if RCT_DEV
181173
182- static JSValueRef RCTNativeTraceBeginSection (JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], __unused JSValueRef *exception)
174+ static JSValueRef RCTNativeTraceBeginSection (JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
183175{
184176 static int profileCounter = 1 ;
185177 NSString *profileName;
@@ -189,14 +181,14 @@ static JSValueRef RCTNativeTraceBeginSection(JSContextRef context, __unused JSOb
189181 if (JSValueIsNumber (context, arguments[0 ])) {
190182 tag = JSValueToNumber (context, arguments[0 ], NULL );
191183 } else {
192- profileName = RCTJSValueToNSString (context, arguments[0 ]);
184+ profileName = RCTJSValueToNSString (context, arguments[0 ], exception );
193185 }
194186 } else {
195187 profileName = [NSString stringWithFormat: @" Profile %d " , profileCounter++];
196188 }
197189
198190 if (argumentCount > 1 && JSValueIsString (context, arguments[1 ])) {
199- profileName = RCTJSValueToNSString (context, arguments[1 ]);
191+ profileName = RCTJSValueToNSString (context, arguments[1 ], exception );
200192 }
201193
202194 if (profileName) {
@@ -206,13 +198,11 @@ static JSValueRef RCTNativeTraceBeginSection(JSContextRef context, __unused JSOb
206198 return JSValueMakeUndefined (context);
207199}
208200
209- static JSValueRef RCTNativeTraceEndSection (JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, __unused size_t argumentCount, __unused const JSValueRef arguments[], __unused JSValueRef *exception)
201+ static JSValueRef RCTNativeTraceEndSection (JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, __unused size_t argumentCount, __unused const JSValueRef arguments[], JSValueRef *exception)
210202{
211203 if (argumentCount > 0 ) {
212- JSValueRef *error = NULL ;
213- double tag = JSValueToNumber (context, arguments[0 ], error);
214-
215- if (error == NULL ) {
204+ double tag = JSValueToNumber (context, arguments[0 ], exception);
205+ if (exception == NULL ) {
216206 RCTProfileEndEvent ((uint64_t )tag, @" console" , nil );
217207 }
218208 }
0 commit comments