Workaround an issue where variables must be defined in the interface when building for i386

I'm honestly surprised that this issue doesn't appear with the older version of JavaScriptCore...
This commit is contained in:
Thomas A 2022-11-27 21:37:50 -08:00
parent 45a14ab7ba
commit 1151b227f3
14 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// The file works around the circular dependencies issue when building for i386
#ifndef DARLING_JSCONTEXTPRIVATE_H
#define DARLING_JSCONTEXTPRIVATE_H
#if defined(DARLING) && __i386__
#if JSC_OBJC_API_ENABLED
@class JSContext, JSValue;
@protocol JSModuleLoaderDelegate <NSObject>
@required
- (void)context:(JSContext *)context fetchModuleForIdentifier:(JSValue *)identifier withResolveHandler:(JSValue *)resolve andRejectHandler:(JSValue *)reject;
@optional
- (void)willEvaluateModule:(NSURL *)key;
- (void)didEvaluateModule:(NSURL *)key;
@end
#endif
#endif // !defined(DARLING) || !__i386__
#endif // DARLING_JSCONTEXTPRIVATE_H

View File

@ -28,6 +28,13 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#if defined(DARLING) && __i386__
#import <wtf/WeakObjCPtr.h>
#import "JSVirtualMachine.h"
#import "DarlingJSContextPrivate.h"
#import "StrongInlines.h"
#endif // __i386__
@class JSScript, JSVirtualMachine, JSValue, JSContext; @class JSScript, JSVirtualMachine, JSValue, JSContext;
/*! /*!
@ -37,7 +44,17 @@
are tied to a context. are tied to a context.
*/ */
JSC_CLASS_AVAILABLE(macos(10.9), ios(7.0)) JSC_CLASS_AVAILABLE(macos(10.9), ios(7.0))
#if defined(DARLING) && __i386__
@interface JSContext : NSObject {
JSVirtualMachine *m_virtualMachine;
JSGlobalContextRef m_context;
JSC::Strong<JSC::JSObject> m_exception;
WeakObjCPtr<id <JSModuleLoaderDelegate>> m_moduleLoaderDelegate;
void(^_exceptionHandler)(JSContext *context, JSValue *exception);
}
#else
@interface JSContext : NSObject @interface JSContext : NSObject
#endif
/*! /*!
@methodgroup Creating New JSContexts @methodgroup Creating New JSContexts
@ -230,4 +247,17 @@ JSC_CLASS_AVAILABLE(macos(10.9), ios(7.0))
@end @end
#if defined(DARLING) && __i386__
// Taken from JSContextPrivate.h
@interface JSContext(Private)
@property (setter=_setRemoteInspectionEnabled:) BOOL _remoteInspectionEnabled JSC_API_AVAILABLE(macos(10.10), ios(8.0));
@property (setter=_setIncludesNativeCallStackWhenReportingExceptions:) BOOL _includesNativeCallStackWhenReportingExceptions JSC_API_AVAILABLE(macos(10.10), ios(8.0));
@property (setter=_setDebuggerRunLoop:) CFRunLoopRef _debuggerRunLoop JSC_API_AVAILABLE(macos(10.10), ios(8.0));
@property (nonatomic, weak) id <JSModuleLoaderDelegate> moduleLoaderDelegate JSC_API_AVAILABLE(macos(10.15), ios(13.0));
- (JSValue *)evaluateJSScript:(JSScript *)script JSC_API_AVAILABLE(macos(10.15), ios(13.0));
- (JSValue *)dependencyIdentifiersForModuleJSScript:(JSScript *)script JSC_API_AVAILABLE(macos(10.15), ios(13.0));
- (void)_setITMLDebuggableType JSC_API_AVAILABLE(macos(11.0), ios(14.0));
@end
#endif // defined(DARLING) && __i386__
#endif #endif

View File

@ -46,12 +46,16 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#if defined(DARLING) && __i386__
@implementation JSContext
#else
@implementation JSContext { @implementation JSContext {
JSVirtualMachine *m_virtualMachine; JSVirtualMachine *m_virtualMachine;
JSGlobalContextRef m_context; JSGlobalContextRef m_context;
JSC::Strong<JSC::JSObject> m_exception; JSC::Strong<JSC::JSObject> m_exception;
WeakObjCPtr<id <JSModuleLoaderDelegate>> m_moduleLoaderDelegate; WeakObjCPtr<id <JSModuleLoaderDelegate>> m_moduleLoaderDelegate;
} }
#endif
- (JSGlobalContextRef)JSGlobalContextRef - (JSGlobalContextRef)JSGlobalContextRef
{ {

View File

@ -30,6 +30,8 @@
#import <JavaScriptCore/JSContext.h> #import <JavaScriptCore/JSContext.h>
#if !defined(DARLING) || defined(DARLING) && !__i386__
@protocol JSModuleLoaderDelegate <NSObject> @protocol JSModuleLoaderDelegate <NSObject>
@required @required
@ -114,6 +116,7 @@
@end @end
#endif // !defined(DARLING) || defined(DARLING) && !__i386__
#endif #endif
#endif // JSContextInternal_h #endif // JSContextInternal_h

View File

@ -31,6 +31,11 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#ifdef defined(DARLING) && __i386__
#import "JSWeakValue.h"
#import "JSLock.h"
#endif
@class JSValue; @class JSValue;
@class JSContext; @class JSContext;
@ -49,7 +54,16 @@ or Swift object that is exported to JavaScript. It is incorrect to store a JSVal
in an object that is exported to JavaScript, since doing so creates a retain cycle. in an object that is exported to JavaScript, since doing so creates a retain cycle.
*/ */
NS_CLASS_AVAILABLE(10_9, 7_0) NS_CLASS_AVAILABLE(10_9, 7_0)
#if defined(DARLING) && __i386__
@interface JSManagedValue : NSObject {
JSC::Weak<JSC::JSGlobalObject> m_globalObject;
RefPtr<JSC::JSLock> m_lock;
JSC::JSWeakValue m_weakValue;
NSMapTable *m_owners;
}
#else
@interface JSManagedValue : NSObject @interface JSManagedValue : NSObject
#endif
/*! /*!
@method @method

View File

@ -51,12 +51,16 @@ static JSManagedValueHandleOwner& managedValueHandleOwner()
return jsManagedValueHandleOwner; return jsManagedValueHandleOwner;
} }
#if defined(DARLING) && __i386__
@implementation JSManagedValue
#else
@implementation JSManagedValue { @implementation JSManagedValue {
JSC::Weak<JSC::JSGlobalObject> m_globalObject; JSC::Weak<JSC::JSGlobalObject> m_globalObject;
RefPtr<JSC::JSLock> m_lock; RefPtr<JSC::JSLock> m_lock;
JSC::JSWeakValue m_weakValue; JSC::JSWeakValue m_weakValue;
NSMapTable *m_owners; NSMapTable *m_owners;
} }
#endif
+ (JSManagedValue *)managedValueWithValue:(JSValue *)value + (JSManagedValue *)managedValueWithValue:(JSValue *)value
{ {

View File

@ -27,6 +27,12 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#ifdef defined(DARLING) && __i386__
#import <wtf/WeakObjCPtr.h>
#import <wtf/FileSystem.h>
#import "CachedBytecode.h"
#endif
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class JSVirtualMachine; @class JSVirtualMachine;
@ -44,7 +50,19 @@ typedef NS_ENUM(NSInteger, JSScriptType) {
JSC_CLASS_AVAILABLE(macos(10.15), ios(13.0)) JSC_CLASS_AVAILABLE(macos(10.15), ios(13.0))
#if defined(DARLING) && __i386__
@interface JSScript : NSObject {
WeakObjCPtr<JSVirtualMachine> m_virtualMachine;
JSScriptType m_type;
FileSystem::MappedFileData m_mappedSource;
String m_source;
RetainPtr<NSURL> m_sourceURL;
RetainPtr<NSURL> m_cachePath;
RefPtr<JSC::CachedBytecode> m_cachedBytecode;
}
#else
@interface JSScript : NSObject @interface JSScript : NSObject
#endif
/*! /*!
@method @method

View File

@ -47,6 +47,9 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#if defined(DARLING) && __i386__
@implementation JSScript
#else
@implementation JSScript { @implementation JSScript {
WeakObjCPtr<JSVirtualMachine> m_virtualMachine; WeakObjCPtr<JSVirtualMachine> m_virtualMachine;
JSScriptType m_type; JSScriptType m_type;
@ -56,6 +59,7 @@
RetainPtr<NSURL> m_cachePath; RetainPtr<NSURL> m_cachePath;
RefPtr<JSC::CachedBytecode> m_cachedBytecode; RefPtr<JSC::CachedBytecode> m_cachedBytecode;
} }
#endif
static JSScript *createError(NSString *message, NSError** error) static JSScript *createError(NSString *message, NSError** error)
{ {

View File

@ -45,7 +45,14 @@
different JSVirtualMachine. Doing so will raise an Objective-C exception. different JSVirtualMachine. Doing so will raise an Objective-C exception.
*/ */
NS_CLASS_AVAILABLE(10_9, 7_0) NS_CLASS_AVAILABLE(10_9, 7_0)
#if defined(DARLING) && __i386__
@interface JSValue : NSObject {
JSValueRef m_value;
JSContext *_context;
}
#else
@interface JSValue : NSObject @interface JSValue : NSObject
#endif
/*! /*!
@property @property

View File

@ -65,9 +65,13 @@ NSString * const JSPropertyDescriptorValueKey = @"value";
NSString * const JSPropertyDescriptorGetKey = @"get"; NSString * const JSPropertyDescriptorGetKey = @"get";
NSString * const JSPropertyDescriptorSetKey = @"set"; NSString * const JSPropertyDescriptorSetKey = @"set";
#if defined(DARLING) && __i386__
@implementation JSValue
#else
@implementation JSValue { @implementation JSValue {
JSValueRef m_value; JSValueRef m_value;
} }
#endif
- (void)dealloc - (void)dealloc
{ {

View File

@ -27,6 +27,10 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#if defined(DARLING) && __i386__
#import "JSLock.h"
#endif
/*! /*!
@interface @interface
@discussion An instance of JSVirtualMachine represents a single JavaScript "object space" @discussion An instance of JSVirtualMachine represents a single JavaScript "object space"
@ -40,7 +44,17 @@
JSVirtualMachine's run loop once it has been initialized. JSVirtualMachine's run loop once it has been initialized.
*/ */
NS_CLASS_AVAILABLE(10_9, 7_0) NS_CLASS_AVAILABLE(10_9, 7_0)
#if defined(DARLING) && __i386__
@interface JSVirtualMachine : NSObject {
JSContextGroupRef m_group;
Lock m_externalDataMutex;
NSMapTable *m_contextCache;
NSMapTable *m_externalObjectGraph;
NSMapTable *m_externalRememberedSet;
}
#else
@interface JSVirtualMachine : NSObject @interface JSVirtualMachine : NSObject
#endif
/*! /*!
@methodgroup Creating New Virtual Machines @methodgroup Creating New Virtual Machines

View File

@ -82,6 +82,9 @@ static NSMapTable *wrapperCache()
@end @end
#if defined(DARLING) && __i386__
@implementation JSVirtualMachine
#else
@implementation JSVirtualMachine { @implementation JSVirtualMachine {
JSContextGroupRef m_group; JSContextGroupRef m_group;
Lock m_externalDataMutex; Lock m_externalDataMutex;
@ -89,6 +92,7 @@ static NSMapTable *wrapperCache()
NSMapTable *m_externalObjectGraph; NSMapTable *m_externalObjectGraph;
NSMapTable *m_externalRememberedSet; NSMapTable *m_externalRememberedSet;
} }
#endif
- (instancetype)init - (instancetype)init
{ {

View File

@ -29,7 +29,15 @@
#if JSC_OBJC_API_ENABLED #if JSC_OBJC_API_ENABLED
#if defined(DARLING) && __i386__
@interface JSWrapperMap : NSObject {
NSMutableDictionary *m_classMap;
std::unique_ptr<JSC::WeakGCMap<__unsafe_unretained id, JSC::JSObject>> m_cachedJSWrappers;
NSMapTable *m_cachedObjCWrappers;
}
#else
@interface JSWrapperMap : NSObject @interface JSWrapperMap : NSObject
#endif
- (instancetype)initWithGlobalContextRef:(JSGlobalContextRef)context; - (instancetype)initWithGlobalContextRef:(JSGlobalContextRef)context;

View File

@ -592,11 +592,15 @@ typedef std::pair<JSC::JSObject*, JSC::JSObject*> ConstructorPrototypePair;
@end @end
#if defined(DARLING) && __i386__
@implementation JSWrapperMap
#else
@implementation JSWrapperMap { @implementation JSWrapperMap {
NSMutableDictionary *m_classMap; NSMutableDictionary *m_classMap;
std::unique_ptr<JSC::WeakGCMap<__unsafe_unretained id, JSC::JSObject>> m_cachedJSWrappers; std::unique_ptr<JSC::WeakGCMap<__unsafe_unretained id, JSC::JSObject>> m_cachedJSWrappers;
NSMapTable *m_cachedObjCWrappers; NSMapTable *m_cachedObjCWrappers;
} }
#endif
- (instancetype)initWithGlobalContextRef:(JSGlobalContextRef)context - (instancetype)initWithGlobalContextRef:(JSGlobalContextRef)context
{ {