Changeset 234227 in webkit


Ignore:
Timestamp:
Jul 25, 2018, 7:32:25 PM (7 years ago)
Author:
keith_miller@apple.com
Message:

[JSC API] We should support the symbol type in our C/Obj-C API
https://bugs.webkit.org/show_bug.cgi?id=175836

Reviewed by Filip Pizlo.

This patch makes the following API additions:
1) Test if a JSValue/JSValueRef is a symbol via any of the methods API are able to test for the types of other JSValues.
2) Create a symbol on both APIs.
3) Get/Set/Delete/Define property now take ids in the Obj-C API.
4) Add Get/Set/Delete in the C API.

We can do 3 because it is both binary and source compatable with
the existing API. I added (4) because the current property access
APIs only have the ability to get Strings. It was possible to
merge symbols into JSStringRef but that felt confusing and exposes
implementation details of our engine. The new functions match the
same meaning that they have in JS, thus should be forward
compatible with any future language extensions.

Lastly, this patch adds the same availability preproccessing phase
in WebCore to JavaScriptCore, which enables TBA features for
testing on previous releases.

  • API/APICast.h:
  • API/JSBasePrivate.h:
  • API/JSContext.h:
  • API/JSContextPrivate.h:
  • API/JSContextRef.h:
  • API/JSContextRefInternal.h:
  • API/JSContextRefPrivate.h:
  • API/JSManagedValue.h:
  • API/JSObjectRef.cpp:

(JSObjectHasPropertyKey):
(JSObjectGetPropertyKey):
(JSObjectSetPropertyKey):
(JSObjectDeletePropertyKey):

  • API/JSObjectRef.h:
  • API/JSRemoteInspector.h:
  • API/JSTypedArray.h:
  • API/JSValue.h:
  • API/JSValue.mm:

(+[JSValue valueWithNewSymbolFromDescription:inContext:]):
(performPropertyOperation):
(-[JSValue valueForProperty:valueForProperty:]):
(-[JSValue setValue:forProperty:setValue:forProperty:]):
(-[JSValue deleteProperty:deleteProperty:]):
(-[JSValue hasProperty:hasProperty:]):
(-[JSValue defineProperty:descriptor:defineProperty:descriptor:]):
(-[JSValue isSymbol]):
(-[JSValue objectForKeyedSubscript:]):
(-[JSValue setObject:forKeyedSubscript:]):
(-[JSValue valueForProperty:]): Deleted.
(-[JSValue setValue:forProperty:]): Deleted.
(-[JSValue deleteProperty:]): Deleted.
(-[JSValue hasProperty:]): Deleted.
(-[JSValue defineProperty:descriptor:]): Deleted.

  • API/JSValueRef.cpp:

(JSValueGetType):
(JSValueIsSymbol):
(JSValueMakeSymbol):

  • API/JSValueRef.h:
  • API/WebKitAvailability.h:
  • API/tests/CurrentThisInsideBlockGetterTest.mm:
  • API/tests/CustomGlobalObjectClassTest.c:
  • API/tests/DateTests.mm:
  • API/tests/JSExportTests.mm:
  • API/tests/JSNode.c:
  • API/tests/JSNodeList.c:
  • API/tests/Node.c:
  • API/tests/NodeList.c:
  • API/tests/minidom.c:
  • API/tests/testapi.c:

(main):

  • API/tests/testapi.cpp: Added.

(APIString::APIString):
(APIString::~APIString):
(APIString::operator JSStringRef):
(APIContext::APIContext):
(APIContext::~APIContext):
(APIContext::operator JSGlobalContextRef):
(APIVector::APIVector):
(APIVector::~APIVector):
(APIVector::append):
(testCAPIViaCpp):
(TestAPI::evaluateScript):
(TestAPI::callFunction):
(TestAPI::functionReturnsTrue):
(TestAPI::check):
(TestAPI::checkJSAndAPIMatch):
(TestAPI::interestingObjects):
(TestAPI::interestingKeys):
(TestAPI::run):

  • API/tests/testapi.mm:

(testObjectiveCAPIMain):

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • config.h:
  • postprocess-headers.sh:
  • shell/CMakeLists.txt:
  • testmem/testmem.mm:
Location:
trunk/Source/JavaScriptCore
Files:
1 added
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/APICast.h

    r233765 r234227  
    3131#include "JSCJSValueInlines.h"
    3232#include "JSGlobalObject.h"
     33#include "HeapCellInlines.h"
    3334
    3435namespace JSC {
  • trunk/Source/JavaScriptCore/API/JSBasePrivate.h

    r165676 r234227  
    4444region.
    4545*/
    46 JS_EXPORT void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) CF_AVAILABLE(10_6, 7_0);
     46JS_EXPORT void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    4747
    4848JS_EXPORT void JSDisableGCTimer(void);
  • trunk/Source/JavaScriptCore/API/JSContext.h

    r207542 r234227  
    7979@result The last value generated by the script.
    8080*/
    81 - (JSValue *)evaluateScript:(NSString *)script withSourceURL:(NSURL *)sourceURL NS_AVAILABLE(10_10, 8_0);
     81- (JSValue *)evaluateScript:(NSString *)script withSourceURL:(NSURL *)sourceURL JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    8282
    8383/*!
     
    102102@result The currently executing JavaScript function or nil if there isn't one.
    103103*/
    104 + (JSValue *)currentCallee NS_AVAILABLE(10_10, 8_0);
     104+ (JSValue *)currentCallee JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    105105
    106106/*!
     
    177177@discussion Name of the JSContext. Exposed when remote debugging the context.
    178178*/
    179 @property (copy) NSString *name NS_AVAILABLE(10_10, 8_0);
     179@property (copy) NSString *name JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    180180
    181181@end
  • trunk/Source/JavaScriptCore/API/JSContextPrivate.h

    r170589 r234227  
    3737@discussion Remote inspection setting of the JSContext. Default value is YES.
    3838*/
    39 @property (setter=_setRemoteInspectionEnabled:) BOOL _remoteInspectionEnabled NS_AVAILABLE(10_10, 8_0);
     39@property (setter=_setRemoteInspectionEnabled:) BOOL _remoteInspectionEnabled JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    4040
    4141/*!
     
    4343@discussion Set whether or not the native call stack is included when reporting exceptions. Default value is YES.
    4444*/
    45 @property (setter=_setIncludesNativeCallStackWhenReportingExceptions:) BOOL _includesNativeCallStackWhenReportingExceptions NS_AVAILABLE(10_10, 8_0);
     45@property (setter=_setIncludesNativeCallStackWhenReportingExceptions:) BOOL _includesNativeCallStackWhenReportingExceptions JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    4646
    4747/*!
     
    4949@discussion Set the run loop the Web Inspector debugger should use when evaluating JavaScript in the JSContext.
    5050*/
    51 @property (setter=_setDebuggerRunLoop:) CFRunLoopRef _debuggerRunLoop NS_AVAILABLE(10_10, 8_0);
     51@property (setter=_setDebuggerRunLoop:) CFRunLoopRef _debuggerRunLoop JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    5252
    5353@end
  • trunk/Source/JavaScriptCore/API/JSContextRef.h

    r230961 r234227  
    5454@result The created JSContextGroup.
    5555*/
    56 JS_EXPORT JSContextGroupRef JSContextGroupCreate(void) CF_AVAILABLE(10_6, 7_0);
     56JS_EXPORT JSContextGroupRef JSContextGroupCreate(void) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    5757
    5858/*!
     
    6262@result A JSContextGroup that is the same as group.
    6363*/
    64 JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) CF_AVAILABLE(10_6, 7_0);
     64JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    6565
    6666/*!
     
    6969@param group The JSContextGroup to release.
    7070*/
    71 JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) CF_AVAILABLE(10_6, 7_0);
     71JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    7272
    7373/*!
     
    8484@result A JSGlobalContext with a global object of class globalObjectClass.
    8585*/
    86 JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) CF_AVAILABLE(10_5, 7_0);
     86JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) JSC_API_AVAILABLE(macosx(10.5), ios(7.0));
    8787
    8888/*!
     
    9898 group equal to group.
    9999*/
    100 JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) CF_AVAILABLE(10_6, 7_0);
     100JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    101101
    102102/*!
     
    129129@result ctx's group.
    130130*/
    131 JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) CF_AVAILABLE(10_6, 7_0);
     131JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    132132
    133133/*!
     
    137137@result ctx's global context.
    138138*/
    139 JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx) CF_AVAILABLE(10_7, 7_0);
     139JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx) JSC_API_AVAILABLE(macosx(10.7), ios(7.0));
    140140
    141141/*!
     
    147147easier to identify the context you would like to attach to.
    148148*/
    149 JS_EXPORT JSStringRef JSGlobalContextCopyName(JSGlobalContextRef ctx) CF_AVAILABLE(10_10, 8_0);
     149JS_EXPORT JSStringRef JSGlobalContextCopyName(JSGlobalContextRef ctx) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    150150
    151151/*!
     
    155155@param name The remote debugging name to set on ctx.
    156156*/
    157 JS_EXPORT void JSGlobalContextSetName(JSGlobalContextRef ctx, JSStringRef name) CF_AVAILABLE(10_10, 8_0);
     157JS_EXPORT void JSGlobalContextSetName(JSGlobalContextRef ctx, JSStringRef name) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    158158
    159159#ifdef __cplusplus
  • trunk/Source/JavaScriptCore/API/JSContextRefInternal.h

    r207542 r234227  
    4343@param ctx The JSGlobalContext whose setting you want to get.
    4444*/
    45 JS_EXPORT CFRunLoopRef JSGlobalContextGetDebuggerRunLoop(JSGlobalContextRef ctx) CF_AVAILABLE(10_10, 8_0);
     45JS_EXPORT CFRunLoopRef JSGlobalContextGetDebuggerRunLoop(JSGlobalContextRef ctx) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    4646
    4747/*!
     
    5151@param runLoop The new value of the setting for the context.
    5252*/
    53 JS_EXPORT void JSGlobalContextSetDebuggerRunLoop(JSGlobalContextRef ctx, CFRunLoopRef runLoop) CF_AVAILABLE(10_10, 8_0);
     53JS_EXPORT void JSGlobalContextSetDebuggerRunLoop(JSGlobalContextRef ctx, CFRunLoopRef runLoop) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    5454#endif
    5555
  • trunk/Source/JavaScriptCore/API/JSContextRefPrivate.h

    r207542 r234227  
    4545@result A string containing the backtrace
    4646*/
    47 JS_EXPORT JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize) CF_AVAILABLE(10_6, 7_0);
     47JS_EXPORT JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    4848   
    4949
     
    8686 any scripts.
    8787*/
    88 JS_EXPORT void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef group, double limit, JSShouldTerminateCallback callback, void* context) CF_AVAILABLE(10_6, 7_0);
     88JS_EXPORT void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef group, double limit, JSShouldTerminateCallback callback, void* context) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    8989
    9090/*!
     
    9393@param group The JavaScript context group that the time limit is cleared on.
    9494*/
    95 JS_EXPORT void JSContextGroupClearExecutionTimeLimit(JSContextGroupRef group) CF_AVAILABLE(10_6, 7_0);
     95JS_EXPORT void JSContextGroupClearExecutionTimeLimit(JSContextGroupRef group) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    9696
    9797/*!
     
    102102@discussion Remote inspection is true by default.
    103103*/
    104 JS_EXPORT bool JSGlobalContextGetRemoteInspectionEnabled(JSGlobalContextRef ctx) CF_AVAILABLE(10_10, 8_0);
     104JS_EXPORT bool JSGlobalContextGetRemoteInspectionEnabled(JSGlobalContextRef ctx) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    105105
    106106/*!
     
    110110@param enabled The new remote inspection enabled setting for the context.
    111111*/
    112 JS_EXPORT void JSGlobalContextSetRemoteInspectionEnabled(JSGlobalContextRef ctx, bool enabled) CF_AVAILABLE(10_10, 8_0);   
     112JS_EXPORT void JSGlobalContextSetRemoteInspectionEnabled(JSGlobalContextRef ctx, bool enabled) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));   
    113113
    114114/*!
     
    119119@discussion This setting is true by default.
    120120*/
    121 JS_EXPORT bool JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx) CF_AVAILABLE(10_10, 8_0);
     121JS_EXPORT bool JSGlobalContextGetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    122122
    123123/*!
     
    127127@param includesNativeCallStack The new value of the setting for the context.
    128128*/
    129 JS_EXPORT void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx, bool includesNativeCallStack) CF_AVAILABLE(10_10, 8_0);
     129JS_EXPORT void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx, bool includesNativeCallStack) JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    130130
    131131#ifdef __cplusplus
  • trunk/Source/JavaScriptCore/API/JSManagedValue.h

    r207542 r234227  
    5858*/
    5959+ (JSManagedValue *)managedValueWithValue:(JSValue *)value;
    60 + (JSManagedValue *)managedValueWithValue:(JSValue *)value andOwner:(id)owner NS_AVAILABLE(10_10, 8_0);
     60+ (JSManagedValue *)managedValueWithValue:(JSValue *)value andOwner:(id)owner JSC_API_AVAILABLE(macosx(10.10), ios(8.0));
    6161
    6262/*!
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r233245 r234227  
    367367}
    368368
     369bool JSObjectHasPropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef key, JSValueRef* exception)
     370{
     371    if (!ctx) {
     372        ASSERT_NOT_REACHED();
     373        return false;
     374    }
     375    ExecState* exec = toJS(ctx);
     376    VM& vm = exec->vm();
     377    JSLockHolder locker(vm);
     378    auto scope = DECLARE_CATCH_SCOPE(vm);
     379
     380    JSObject* jsObject = toJS(object);
     381    Identifier ident = toJS(exec, key).toPropertyKey(exec);
     382    if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
     383        return false;
     384
     385    bool result = jsObject->hasProperty(exec, ident);
     386    handleExceptionIfNeeded(scope, exec, exception);
     387    return result;
     388}
     389
     390JSValueRef JSObjectGetPropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef key, JSValueRef* exception)
     391{
     392    if (!ctx) {
     393        ASSERT_NOT_REACHED();
     394        return nullptr;
     395    }
     396    ExecState* exec = toJS(ctx);
     397    VM& vm = exec->vm();
     398    JSLockHolder locker(vm);
     399    auto scope = DECLARE_CATCH_SCOPE(vm);
     400
     401    JSObject* jsObject = toJS(object);
     402    Identifier ident = toJS(exec, key).toPropertyKey(exec);
     403    if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
     404        return nullptr;
     405
     406    JSValue jsValue = jsObject->get(exec, ident);
     407    handleExceptionIfNeeded(scope, exec, exception);
     408    return toRef(exec, jsValue);
     409}
     410
     411void JSObjectSetPropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef key, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
     412{
     413    if (!ctx) {
     414        ASSERT_NOT_REACHED();
     415        return;
     416    }
     417    ExecState* exec = toJS(ctx);
     418    VM& vm = exec->vm();
     419    JSLockHolder locker(vm);
     420    auto scope = DECLARE_CATCH_SCOPE(vm);
     421
     422    JSObject* jsObject = toJS(object);
     423    JSValue jsValue = toJS(exec, value);
     424
     425    Identifier ident = toJS(exec, key).toPropertyKey(exec);
     426    if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
     427        return;
     428
     429    bool doesNotHaveProperty = attributes && !jsObject->hasProperty(exec, ident);
     430    if (LIKELY(!scope.exception())) {
     431        if (doesNotHaveProperty) {
     432            PropertyDescriptor desc(jsValue, attributes);
     433            jsObject->methodTable(vm)->defineOwnProperty(jsObject, exec, ident, desc, false);
     434        } else {
     435            PutPropertySlot slot(jsObject);
     436            jsObject->methodTable(vm)->put(jsObject, exec, ident, jsValue, slot);
     437        }
     438    }
     439    handleExceptionIfNeeded(scope, exec, exception);
     440}
     441
     442bool JSObjectDeletePropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef key, JSValueRef* exception)
     443{
     444    if (!ctx) {
     445        ASSERT_NOT_REACHED();
     446        return false;
     447    }
     448    ExecState* exec = toJS(ctx);
     449    VM& vm = exec->vm();
     450    JSLockHolder locker(vm);
     451    auto scope = DECLARE_CATCH_SCOPE(vm);
     452
     453    JSObject* jsObject = toJS(object);
     454    Identifier ident = toJS(exec, key).toPropertyKey(exec);
     455    if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
     456        return false;
     457
     458    bool result = jsObject->methodTable(vm)->deleteProperty(jsObject, exec, ident);
     459    handleExceptionIfNeeded(scope, exec, exception);
     460    return result;
     461}
     462
    369463JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
    370464{
  • trunk/Source/JavaScriptCore/API/JSObjectRef.h

    r207542 r234227  
    442442 is supplied, this function returns an array with one element.
    443443 */
    444 JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) CF_AVAILABLE(10_6, 7_0);
     444JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    445445
    446446/*!
     
    453453 @result A JSObject that is a Date.
    454454 */
    455 JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) CF_AVAILABLE(10_6, 7_0);
     455JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    456456
    457457/*!
     
    464464 @result A JSObject that is a Error.
    465465 */
    466 JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) CF_AVAILABLE(10_6, 7_0);
     466JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    467467
    468468/*!
     
    475475 @result A JSObject that is a RegExp.
    476476 */
    477 JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) CF_AVAILABLE(10_6, 7_0);
     477JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.6), ios(7.0));
    478478
    479479/*!
     
    537537@param object The JSObject whose property you want to set.
    538538@param propertyName A JSString containing the property's name.
    539 @param value A JSValue to use as the property's value.
    540 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     539@param value A JSValueRef to use as the property's value.
    541540@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
     541@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    542542*/
    543543JS_EXPORT void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
     
    553553*/
    554554JS_EXPORT bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     555
     556/*!
     557@function
     558@abstract Tests whether an object has a given property using a JSValueRef as the property key.
     559@param object The JSObject to test.
     560@param propertyKey A JSValueRef containing the property key to use when looking up the property.
     561@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     562@result true if the object has a property whose name matches propertyKey, otherwise false.
     563@discussion This function is the same as performing "propertyKey in object" from JavaScript.
     564*/
     565JS_EXPORT bool JSObjectHasPropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     566
     567/*!
     568@function
     569@abstract Gets a property from an object using a JSValueRef as the property key.
     570@param ctx The execution context to use.
     571@param object The JSObject whose property you want to get.
     572@param propertyKey A JSValueRef containing the property key to use when looking up the property.
     573@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     574@result The property's value if object has the property key, otherwise the undefined value.
     575@discussion This function is the same as performing "object[propertyKey]" from JavaScript.
     576*/
     577JS_EXPORT JSValueRef JSObjectGetPropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     578
     579/*!
     580@function
     581@abstract Sets a property on an object using a JSValueRef as the property key.
     582@param ctx The execution context to use.
     583@param object The JSObject whose property you want to set.
     584@param propertyKey A JSValueRef containing the property key to use when looking up the property.
     585@param value A JSValueRef to use as the property's value.
     586@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
     587@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     588@discussion This function is the same as performing "object[propertyKey] = value" from JavaScript.
     589*/
     590JS_EXPORT void JSObjectSetPropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     591
     592/*!
     593@function
     594@abstract Deletes a property from an object using a JSValueRef as the property key.
     595@param ctx The execution context to use.
     596@param object The JSObject whose property you want to delete.
     597@param propertyKey A JSValueRef containing the property key to use when looking up the property.
     598@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     599@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
     600@discussion This function is the same as performing "delete object[propertyKey]" from JavaScript.
     601*/
     602JS_EXPORT bool JSObjectDeletePropertyKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    555603
    556604/*!
  • trunk/Source/JavaScriptCore/API/JSRemoteInspector.h

    r222309 r234227  
    4141#endif
    4242
    43 JS_EXPORT void JSRemoteInspectorDisableAutoStart(void) CF_AVAILABLE(10_11, 9_0);
    44 JS_EXPORT void JSRemoteInspectorStart(void) CF_AVAILABLE(10_11, 9_0);
    45 JS_EXPORT void JSRemoteInspectorSetParentProcessInformation(JSProcessID, const uint8_t* auditData, size_t auditLength) CF_AVAILABLE(10_11, 9_0);
     43JS_EXPORT void JSRemoteInspectorDisableAutoStart(void) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
     44JS_EXPORT void JSRemoteInspectorStart(void) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
     45JS_EXPORT void JSRemoteInspectorSetParentProcessInformation(JSProcessID, const uint8_t* auditData, size_t auditLength) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    4646
    47 JS_EXPORT void JSRemoteInspectorSetLogToSystemConsole(bool) CF_AVAILABLE(10_11, 9_0);
     47JS_EXPORT void JSRemoteInspectorSetLogToSystemConsole(bool) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    4848
    49 JS_EXPORT bool JSRemoteInspectorGetInspectionEnabledByDefault(void) CF_AVAILABLE(10_11, 9_0);
    50 JS_EXPORT void JSRemoteInspectorSetInspectionEnabledByDefault(bool) CF_AVAILABLE(10_11, 9_0);
     49JS_EXPORT bool JSRemoteInspectorGetInspectionEnabledByDefault(void) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
     50JS_EXPORT void JSRemoteInspectorSetInspectionEnabledByDefault(bool) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    5151
    5252#ifdef __cplusplus
  • trunk/Source/JavaScriptCore/API/JSTypedArray.h

    r207542 r234227  
    4646 @result             A JSObjectRef that is a Typed Array with all elements set to zero or NULL if there was an error.
    4747 */
    48 JS_EXPORT JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType, size_t length, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     48JS_EXPORT JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType, size_t length, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    4949
    5050/*!
     
    6161 @discussion               If an exception is thrown during this function the bytesDeallocator will always be called.
    6262 */
    63 JS_EXPORT JSObjectRef JSObjectMakeTypedArrayWithBytesNoCopy(JSContextRef ctx, JSTypedArrayType arrayType, void* bytes, size_t byteLength, JSTypedArrayBytesDeallocator bytesDeallocator, void* deallocatorContext, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     63JS_EXPORT JSObjectRef JSObjectMakeTypedArrayWithBytesNoCopy(JSContextRef ctx, JSTypedArrayType arrayType, void* bytes, size_t byteLength, JSTypedArrayBytesDeallocator bytesDeallocator, void* deallocatorContext, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    6464
    6565/*!
     
    7272 @result             A JSObjectRef that is a Typed Array or NULL if there was an error. The backing store of the Typed Array will be buffer.
    7373 */
    74 JS_EXPORT JSObjectRef JSObjectMakeTypedArrayWithArrayBuffer(JSContextRef ctx, JSTypedArrayType arrayType, JSObjectRef buffer, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     74JS_EXPORT JSObjectRef JSObjectMakeTypedArrayWithArrayBuffer(JSContextRef ctx, JSTypedArrayType arrayType, JSObjectRef buffer, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    7575
    7676/*!
     
    8585 @result             A JSObjectRef that is a Typed Array or NULL if there was an error. The backing store of the Typed Array will be buffer.
    8686 */
    87 JS_EXPORT JSObjectRef JSObjectMakeTypedArrayWithArrayBufferAndOffset(JSContextRef ctx, JSTypedArrayType arrayType, JSObjectRef buffer, size_t byteOffset, size_t length, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     87JS_EXPORT JSObjectRef JSObjectMakeTypedArrayWithArrayBufferAndOffset(JSContextRef ctx, JSTypedArrayType arrayType, JSObjectRef buffer, size_t byteOffset, size_t length, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    8888
    8989/*!
     
    9696 @discussion         The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls.
    9797 */
    98 JS_EXPORT void* JSObjectGetTypedArrayBytesPtr(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     98JS_EXPORT void* JSObjectGetTypedArrayBytesPtr(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    9999
    100100/*!
     
    106106 @result             The length of the Typed Array object or 0 if the object is not a Typed Array object.
    107107 */
    108 JS_EXPORT size_t JSObjectGetTypedArrayLength(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     108JS_EXPORT size_t JSObjectGetTypedArrayLength(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    109109
    110110/*!
     
    116116 @result             The byte length of the Typed Array object or 0 if the object is not a Typed Array object.
    117117 */
    118 JS_EXPORT size_t JSObjectGetTypedArrayByteLength(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     118JS_EXPORT size_t JSObjectGetTypedArrayByteLength(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    119119
    120120/*!
     
    126126 @result             The byte offset of the Typed Array object or 0 if the object is not a Typed Array object.
    127127 */
    128 JS_EXPORT size_t JSObjectGetTypedArrayByteOffset(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     128JS_EXPORT size_t JSObjectGetTypedArrayByteOffset(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    129129
    130130/*!
     
    136136 @result             A JSObjectRef with a JSTypedArrayType of kJSTypedArrayTypeArrayBuffer or NULL if object is not a Typed Array.
    137137 */
    138 JS_EXPORT JSObjectRef JSObjectGetTypedArrayBuffer(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     138JS_EXPORT JSObjectRef JSObjectGetTypedArrayBuffer(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    139139
    140140// ------------- Array Buffer functions -------------
     
    152152 @discussion               If an exception is thrown during this function the bytesDeallocator will always be called.
    153153 */
    154 JS_EXPORT JSObjectRef JSObjectMakeArrayBufferWithBytesNoCopy(JSContextRef ctx, void* bytes, size_t byteLength, JSTypedArrayBytesDeallocator bytesDeallocator, void* deallocatorContext, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     154JS_EXPORT JSObjectRef JSObjectMakeArrayBufferWithBytesNoCopy(JSContextRef ctx, void* bytes, size_t byteLength, JSTypedArrayBytesDeallocator bytesDeallocator, void* deallocatorContext, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    155155
    156156/*!
     
    162162 @discussion       The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls.
    163163 */
    164 JS_EXPORT void* JSObjectGetArrayBufferBytesPtr(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     164JS_EXPORT void* JSObjectGetArrayBufferBytesPtr(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    165165
    166166/*!
     
    172172 @result           The number of bytes stored in the data object.
    173173 */
    174 JS_EXPORT size_t JSObjectGetArrayBufferByteLength(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     174JS_EXPORT size_t JSObjectGetArrayBufferByteLength(JSContextRef ctx, JSObjectRef object, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    175175
    176176#ifdef __cplusplus
  • trunk/Source/JavaScriptCore/API/JSValue.h

    r207542 r234227  
    4848@interface JSValue : NSObject
    4949
     50#if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < JSC_MAC_VERSION_TBA) || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < JSC_IOS_VERSION_TBA)
     51typedef NSString *JSValuePropertyKeyType;
     52#else
     53typedef id JSValuePropertyKeyType;
     54#endif
     55
    5056/*!
    5157@property
     
    148154*/
    149155+ (JSValue *)valueWithUndefinedInContext:(JSContext *)context;
     156
     157/*!
     158 @method
     159 @abstract Create a new, unique, symbol object.
     160 @param description The description of the symbol object being created.
     161 @param context The JSContext to which the resulting JSValue belongs.
     162 @result The JSValue representing a unique JavaScript value with type symbol.
     163 */
     164+ (JSValue *)valueWithNewSymbolFromDescription:(NSString *)description inContext:(JSContext *)context JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    150165
    151166/*!
     
    306321@methodgroup Accessing Properties
    307322*/
     323
    308324/*!
    309325@method
     
    311327@result The JSValue for the requested property or the JSValue <code>undefined</code>
    312328 if the property does not exist.
    313 */
    314 - (JSValue *)valueForProperty:(NSString *)property;
     329@discussion Corresponds to the JavaScript operation <code>object[property]</code>. Pass an NSString * to access a named property. Other valid properties include symbols, numbers, and stringifiable objects. In macOS 10.13 and iOS 11 and below, 'property' was an NSString *.
     330*/
     331- (JSValue *)valueForProperty:(JSValuePropertyKeyType)property;
    315332
    316333/*!
    317334@method
    318335@abstract Set a property on a JSValue.
    319 */
    320 - (void)setValue:(id)value forProperty:(NSString *)property;
     336@discussion Corresponds to the JavaScript operation <code>object[property] = value</code>. Pass an NSString * to access a named property. Other valid properties include symbols, numbers, and stringifiable objects. In macOS 10.13 and iOS 11 and below, 'property' was an NSString *.
     337*/
     338- (void)setValue:(id)value forProperty:(JSValuePropertyKeyType)property;
    321339
    322340/*!
     
    324342@abstract Delete a property from a JSValue.
    325343@result YES if deletion is successful, NO otherwise.
    326 */
    327 - (BOOL)deleteProperty:(NSString *)property;
     344@discussion Corresponds to the JavaScript operation <code>delete object[property]</code>. Pass an NSString * to access a named property. Other valid properties include symbols, numbers, and stringifiable objects. In macOS 10.13 and iOS 11 and below, 'property' was an NSString *.
     345*/
     346- (BOOL)deleteProperty:(JSValuePropertyKeyType)property;
    328347
    329348/*!
     
    332351@discussion This method has the same function as the JavaScript operator <code>in</code>.
    333352@result Returns YES if property is present on the value.
    334 */
    335 - (BOOL)hasProperty:(NSString *)property;
     353@discussion Corresponds to the JavaScript operation <code>property in object</code>. Pass an NSString * to access a named property. Other valid properties include symbols, numbers, and stringifiable objects. In macOS 10.13 and iOS 11 and below, 'property' was an NSString *.
     354*/
     355- (BOOL)hasProperty:(JSValuePropertyKeyType)property;
    336356
    337357/*!
     
    340360@discussion This method may be used to create a data or accessor property on an object.
    341361 This method operates in accordance with the Object.defineProperty method in the
    342  JavaScript language.
    343 */
    344 - (void)defineProperty:(NSString *)property descriptor:(id)descriptor;
     362 JavaScript language. Pass an NSString * to access a named property. Other valid properties include symbols, numbers, and stringifiable objects. In macOS 10.13 and iOS 11 and below, 'property' was an NSString *.
     363*/
     364- (void)defineProperty:(JSValuePropertyKeyType)property descriptor:(id)descriptor;
    345365
    346366/*!
     
    405425/*!
    406426@property
     427@abstract Check if a JSValue is a symbol.
     428*/
     429@property (readonly) BOOL isSymbol JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     430
     431/*!
     432@property
    407433@abstract Check if a JSValue is an array.
    408434*/
    409 @property (readonly) BOOL isArray NS_AVAILABLE(10_11, 9_0);
     435@property (readonly) BOOL isArray JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    410436
    411437/*!
     
    413439@abstract Check if a JSValue is a date.
    414440*/
    415 @property (readonly) BOOL isDate NS_AVAILABLE(10_11, 9_0);
     441@property (readonly) BOOL isDate JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    416442
    417443/*!
     
    570596
    571597 An object key passed as a subscript will be converted to a JavaScript value,
    572  and then the value converted to a string used as a property name.
     598 and then the value converted to a string used as a property name. In macOS
     599 10.13 and iOS 11 and below, the <code>key</code> argument of
     600 <code>setObject:object forKeyedSubscript:key</code> was restricted to an
     601 <code>NSString <NSCopying> *</code> but that restriction was never used.
    573602*/
    574603@interface JSValue (SubscriptSupport)
    575604
    576 - (JSValue *)objectForKeyedSubscript:(id)key;
     605- (JSValue *)objectForKeyedSubscript:(JSValuePropertyKeyType)key;
    577606- (JSValue *)objectAtIndexedSubscript:(NSUInteger)index;
    578 - (void)setObject:(id)object forKeyedSubscript:(NSObject <NSCopying> *)key;
     607- (void)setObject:(id)object forKeyedSubscript:(JSValuePropertyKeyType)key;
    579608- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
    580609
  • trunk/Source/JavaScriptCore/API/JSValue.mm

    r233409 r234227  
    4040#import "Strong.h"
    4141#import "StrongInlines.h"
     42#import <wtf/Expected.h>
    4243#import <wtf/HashMap.h>
    4344#import <wtf/HashSet.h>
     
    152153}
    153154
     155+ (JSValue *)valueWithNewSymbolFromDescription:(NSString *)description inContext:(JSContext *)context
     156{
     157    JSStringRef string = JSStringCreateWithCFString(reinterpret_cast<CFStringRef>(description));
     158    return [JSValue valueWithJSValueRef:JSValueMakeSymbol([context JSGlobalContextRef], string) inContext:context];
     159}
     160
     161
    154162- (id)toObject
    155163{
     
    235243}
    236244
    237 - (JSValue *)valueForProperty:(NSString *)propertyName
    238 {
     245template<typename Result, typename NSStringFunction, typename JSValueFunction, typename... Types>
     246inline Expected<Result, JSValueRef> performPropertyOperation(NSStringFunction stringFunction, JSValueFunction jsFunction, JSValue* value, id propertyKey, Types... arguments)
     247{
     248    JSContext* context = [value context];
     249    JSValueRef exception = nullptr;
     250    JSObjectRef object = JSValueToObject([context JSGlobalContextRef], [value JSValueRef], &exception);
     251    if (exception)
     252        return Unexpected<JSValueRef>(exception);
     253
     254    Result result;
     255    // If it's a NSString already, reduce indirection and just pass the NSString.
     256    if ([propertyKey isKindOfClass:[NSString class]]) {
     257        JSStringRef name = JSStringCreateWithCFString((__bridge CFStringRef)propertyKey);
     258        result = stringFunction([context JSGlobalContextRef], object, name, arguments..., &exception);
     259        JSStringRelease(name);
     260    } else
     261        result = jsFunction([context JSGlobalContextRef], object, [[JSValue valueWithObject:propertyKey inContext:context] JSValueRef], arguments..., &exception);
     262    return Expected<Result, JSValueRef>(result);
     263}
     264
     265- (JSValue *)valueForProperty:(id)key
     266{
     267    auto result = performPropertyOperation<JSValueRef>(JSObjectGetProperty, JSObjectGetPropertyKey, self, key);
     268    if (!result)
     269        return [_context valueFromNotifyException:result.error()];
     270
     271    return [JSValue valueWithJSValueRef:result.value() inContext:_context];
     272}
     273
     274
     275- (void)setValue:(id)value forProperty:(JSValuePropertyKeyType)key
     276{
     277    // We need Unit business because void can't be assigned to in performPropertyOperation and I don't want to duplicate the code...
     278    using Unit = std::tuple<>;
     279    auto stringSetProperty = [] (auto... args) -> Unit {
     280        JSObjectSetProperty(args...);
     281        return { };
     282    };
     283
     284    auto jsValueSetProperty = [] (auto... args) -> Unit {
     285        JSObjectSetPropertyKey(args...);
     286        return { };
     287    };
     288
     289    auto result = performPropertyOperation<Unit>(stringSetProperty, jsValueSetProperty, self, key, objectToValue(_context, value), kJSPropertyAttributeNone);
     290    if (!result) {
     291        [_context notifyException:result.error()];
     292        return;
     293    }
     294}
     295
     296- (BOOL)deleteProperty:(JSValuePropertyKeyType)key
     297{
     298    Expected<BOOL, JSValueRef> result = performPropertyOperation<BOOL>(JSObjectDeleteProperty, JSObjectDeletePropertyKey, self, key);
     299    if (!result)
     300        return [_context boolFromNotifyException:result.error()];
     301    return result.value();
     302}
     303
     304- (BOOL)hasProperty:(JSValuePropertyKeyType)key
     305{
     306    // The C-api doesn't return an exception value for the string version of has property.
     307    auto stringHasProperty = [] (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef*) -> BOOL {
     308        return JSObjectHasProperty(ctx, object, propertyName);
     309    };
     310
     311    Expected<BOOL, JSValueRef> result = performPropertyOperation<BOOL>(stringHasProperty, JSObjectHasPropertyKey, self, key);
     312    if (!result)
     313        return [_context boolFromNotifyException:result.error()];
     314    return result.value();
     315}
     316
     317- (void)defineProperty:(JSValuePropertyKeyType)key descriptor:(id)descriptor
     318{
     319    [[_context globalObject][@"Object"] invokeMethod:@"defineProperty" withArguments:@[ self, key, descriptor ]];
     320}
     321
     322- (JSValue *)valueAtIndex:(NSUInteger)index
     323{
     324    // Properties that are higher than an unsigned value can hold are converted to a double then inserted as a normal property.
     325    // Indices that are bigger than the max allowed index size (UINT_MAX - 1) will be handled internally in get().
     326    if (index != (unsigned)index)
     327        return [self valueForProperty:[[JSValue valueWithDouble:index inContext:_context] toString]];
     328
    239329    JSValueRef exception = 0;
    240330    JSObjectRef object = JSValueToObject([_context JSGlobalContextRef], m_value, &exception);
     
    242332        return [_context valueFromNotifyException:exception];
    243333
    244     JSStringRef name = JSStringCreateWithCFString((__bridge CFStringRef)propertyName);
    245     JSValueRef result = JSObjectGetProperty([_context JSGlobalContextRef], object, name, &exception);
    246     JSStringRelease(name);
     334    JSValueRef result = JSObjectGetPropertyAtIndex([_context JSGlobalContextRef], object, (unsigned)index, &exception);
    247335    if (exception)
    248336        return [_context valueFromNotifyException:exception];
     
    251339}
    252340
    253 - (void)setValue:(id)value forProperty:(NSString *)propertyName
    254 {
     341- (void)setValue:(id)value atIndex:(NSUInteger)index
     342{
     343    // Properties that are higher than an unsigned value can hold are converted to a double, then inserted as a normal property.
     344    // Indices that are bigger than the max allowed index size (UINT_MAX - 1) will be handled internally in putByIndex().
     345    if (index != (unsigned)index)
     346        return [self setValue:value forProperty:[[JSValue valueWithDouble:index inContext:_context] toString]];
     347
    255348    JSValueRef exception = 0;
    256349    JSObjectRef object = JSValueToObject([_context JSGlobalContextRef], m_value, &exception);
     
    260353    }
    261354
    262     JSStringRef name = JSStringCreateWithCFString((__bridge CFStringRef)propertyName);
    263     JSObjectSetProperty([_context JSGlobalContextRef], object, name, objectToValue(_context, value), 0, &exception);
    264     JSStringRelease(name);
    265     if (exception) {
    266         [_context notifyException:exception];
    267         return;
    268     }
    269 }
    270 
    271 - (BOOL)deleteProperty:(NSString *)propertyName
    272 {
    273     JSValueRef exception = 0;
    274     JSObjectRef object = JSValueToObject([_context JSGlobalContextRef], m_value, &exception);
    275     if (exception)
    276         return [_context boolFromNotifyException:exception];
    277 
    278     JSStringRef name = JSStringCreateWithCFString((__bridge CFStringRef)propertyName);
    279     BOOL result = JSObjectDeleteProperty([_context JSGlobalContextRef], object, name, &exception);
    280     JSStringRelease(name);
    281     if (exception)
    282         return [_context boolFromNotifyException:exception];
    283 
    284     return result;
    285 }
    286 
    287 - (BOOL)hasProperty:(NSString *)propertyName
    288 {
    289     JSValueRef exception = 0;
    290     JSObjectRef object = JSValueToObject([_context JSGlobalContextRef], m_value, &exception);
    291     if (exception)
    292         return [_context boolFromNotifyException:exception];
    293 
    294     JSStringRef name = JSStringCreateWithCFString((__bridge CFStringRef)propertyName);
    295     BOOL result = JSObjectHasProperty([_context JSGlobalContextRef], object, name);
    296     JSStringRelease(name);
    297     return result;
    298 }
    299 
    300 - (void)defineProperty:(NSString *)property descriptor:(id)descriptor
    301 {
    302     [[_context globalObject][@"Object"] invokeMethod:@"defineProperty" withArguments:@[ self, property, descriptor ]];
    303 }
    304 
    305 - (JSValue *)valueAtIndex:(NSUInteger)index
    306 {
    307     // Properties that are higher than an unsigned value can hold are converted to a double then inserted as a normal property.
    308     // Indices that are bigger than the max allowed index size (UINT_MAX - 1) will be handled internally in get().
    309     if (index != (unsigned)index)
    310         return [self valueForProperty:[[JSValue valueWithDouble:index inContext:_context] toString]];
    311 
    312     JSValueRef exception = 0;
    313     JSObjectRef object = JSValueToObject([_context JSGlobalContextRef], m_value, &exception);
    314     if (exception)
    315         return [_context valueFromNotifyException:exception];
    316 
    317     JSValueRef result = JSObjectGetPropertyAtIndex([_context JSGlobalContextRef], object, (unsigned)index, &exception);
    318     if (exception)
    319         return [_context valueFromNotifyException:exception];
    320 
    321     return [JSValue valueWithJSValueRef:result inContext:_context];
    322 }
    323 
    324 - (void)setValue:(id)value atIndex:(NSUInteger)index
    325 {
    326     // Properties that are higher than an unsigned value can hold are converted to a double, then inserted as a normal property.
    327     // Indices that are bigger than the max allowed index size (UINT_MAX - 1) will be handled internally in putByIndex().
    328     if (index != (unsigned)index)
    329         return [self setValue:value forProperty:[[JSValue valueWithDouble:index inContext:_context] toString]];
    330 
    331     JSValueRef exception = 0;
    332     JSObjectRef object = JSValueToObject([_context JSGlobalContextRef], m_value, &exception);
    333     if (exception) {
    334         [_context notifyException:exception];
    335         return;
    336     }
    337 
    338355    JSObjectSetPropertyAtIndex([_context JSGlobalContextRef], object, (unsigned)index, objectToValue(_context, value), &exception);
    339356    if (exception) {
     
    371388{
    372389    return JSValueIsObject([_context JSGlobalContextRef], m_value);
     390}
     391
     392- (BOOL)isSymbol
     393{
     394    return JSValueIsSymbol([_context JSGlobalContextRef], m_value);
    373395}
    374396
     
    555577- (JSValue *)objectForKeyedSubscript:(id)key
    556578{
    557     if (![key isKindOfClass:[NSString class]]) {
    558         key = [[JSValue valueWithObject:key inContext:_context] toString];
    559         if (!key)
    560             return [JSValue valueWithUndefinedInContext:_context];
    561     }
    562 
    563     return [self valueForProperty:(NSString *)key];
     579    return [self valueForProperty:key];
    564580}
    565581
     
    569585}
    570586
    571 - (void)setObject:(id)object forKeyedSubscript:(NSObject <NSCopying> *)key
    572 {
    573     if (![key isKindOfClass:[NSString class]]) {
    574         key = [[JSValue valueWithObject:key inContext:_context] toString];
    575         if (!key)
    576             return;
    577     }
    578 
    579     [self setValue:object forProperty:(NSString *)key];
     587- (void)setObject:(id)object forKeyedSubscript:(id)key
     588{
     589    [self setValue:object forProperty:key];
    580590}
    581591
  • trunk/Source/JavaScriptCore/API/JSValueRef.cpp

    r232337 r234227  
    8787    if (jsValue.isString())
    8888        return kJSTypeString;
     89    if (jsValue.isSymbol())
     90        return kJSTypeSymbol;
    8991    ASSERT(jsValue.isObject());
    9092    return kJSTypeObject;
     
    161163
    162164    return toJS(exec, value).isObject();
     165}
     166
     167bool JSValueIsSymbol(JSContextRef ctx, JSValueRef value)
     168{
     169    if (!ctx) {
     170        ASSERT_NOT_REACHED();
     171        return false;
     172    }
     173    ExecState* exec = toJS(ctx);
     174    JSLockHolder locker(exec);
     175
     176    return toJS(exec, value).isSymbol();
    163177}
    164178
     
    321335}
    322336
     337JSValueRef JSValueMakeSymbol(JSContextRef ctx, JSStringRef description)
     338{
     339    if (!ctx) {
     340        ASSERT_NOT_REACHED();
     341        return nullptr;
     342    }
     343    ExecState* exec = toJS(ctx);
     344    JSLockHolder locker(exec);
     345    auto scope = DECLARE_CATCH_SCOPE(exec->vm());
     346
     347    JSString* jsDescription = jsString(exec, description ? description->string() : String());
     348    RETURN_IF_EXCEPTION(scope, nullptr);
     349
     350    return toRef(exec, Symbol::create(exec, jsDescription));
     351}
     352
    323353JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
    324354{
  • trunk/Source/JavaScriptCore/API/JSValueRef.h

    r207542 r234227  
    4343@constant     kJSTypeString     A primitive string value.
    4444@constant     kJSTypeObject     An object value (meaning that this JSValueRef is a JSObjectRef).
     45@constant     kJSTypeSymbol     A primitive symbol value.
    4546*/
    4647typedef enum {
     
    5051    kJSTypeNumber,
    5152    kJSTypeString,
    52     kJSTypeObject
     53    kJSTypeObject,
     54    kJSTypeSymbol JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA))
    5355} JSType;
    5456
     
    8183    kJSTypedArrayTypeArrayBuffer,
    8284    kJSTypedArrayTypeNone,
    83 } JSTypedArrayType CF_ENUM_AVAILABLE(10_12, 10_0);
     85} JSTypedArrayType JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    8486
    8587#ifdef __cplusplus
     
    149151*/
    150152JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
     153
     154/*!
     155@function
     156@abstract       Tests whether a JavaScript value's type is the symbol type.
     157@param ctx      The execution context to use.
     158@param value    The JSValue to test.
     159@result         true if value's type is the symbol type, otherwise false.
     160*/
     161JS_EXPORT bool JSValueIsSymbol(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     162
    151163
    152164/*!
     
    167179@result         true if value is an array, otherwise false.
    168180*/
    169 JS_EXPORT bool JSValueIsArray(JSContextRef ctx, JSValueRef value) CF_AVAILABLE(10_11, 9_0);
     181JS_EXPORT bool JSValueIsArray(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    170182
    171183/*!
     
    176188@result         true if value is a date, otherwise false.
    177189*/
    178 JS_EXPORT bool JSValueIsDate(JSContextRef ctx, JSValueRef value) CF_AVAILABLE(10_11, 9_0);
     190JS_EXPORT bool JSValueIsDate(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macosx(10.11), ios(9.0));
    179191
    180192/*!
     
    186198@result             A value of type JSTypedArrayType that identifies value's Typed Array type, or kJSTypedArrayTypeNone if the value is not a Typed Array object.
    187199 */
    188 JS_EXPORT JSTypedArrayType JSValueGetTypedArrayType(JSContextRef ctx, JSValueRef value, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
     200JS_EXPORT JSTypedArrayType JSValueGetTypedArrayType(JSContextRef ctx, JSValueRef value, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.12), ios(10.0));
    189201
    190202/* Comparing values */
     
    257269*/
    258270JS_EXPORT JSValueRef JSValueMakeNumber(JSContextRef ctx, double number);
     271
     272/*!
     273@function
     274@abstract            Creates a JavaScript value of the symbol type.
     275@param ctx           The execution context to use.
     276@param description   A description of the newly created symbol value.
     277@result              A unique JSValue of the symbol type, whose description matches the one provided.
     278*/
     279JS_EXPORT JSValueRef JSValueMakeSymbol(JSContextRef ctx, JSStringRef description);
    259280
    260281/*!
     
    277298 @result         A JSValue containing the parsed value, or NULL if the input is invalid.
    278299 */
    279 JS_EXPORT JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) CF_AVAILABLE(10_7, 7_0);
     300JS_EXPORT JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) JSC_API_AVAILABLE(macosx(10.7), ios(7.0));
    280301
    281302/*!
     
    288309 @result         A JSString with the result of serialization, or NULL if an exception is thrown.
    289310 */
    290 JS_EXPORT JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef* exception) CF_AVAILABLE(10_7, 7_0);
     311JS_EXPORT JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef* exception) JSC_API_AVAILABLE(macosx(10.7), ios(7.0));
    291312
    292313/* Converting to primitive values */
  • trunk/Source/JavaScriptCore/API/WebKitAvailability.h

    r219050 r234227  
    7070
    7171#if defined(BUILDING_GTK__)
    72 #undef CF_AVAILABLE
    73 #define CF_AVAILABLE(_mac, _ios)
    74 #undef CF_ENUM_AVAILABLE
    75 #define CF_ENUM_AVAILABLE(_mac, _ios)
     72#undef JSC_API_AVAILABLE
     73#define JSC_API_AVAILABLE(...)
    7674#endif
    7775
    7876#else
    79 #define CF_AVAILABLE(_mac, _ios)
    80 #define CF_ENUM_AVAILABLE(_mac, _ios)
     77#define JSC_API_AVAILABLE(...)
    8178#endif
    8279
  • trunk/Source/JavaScriptCore/API/tests/CurrentThisInsideBlockGetterTest.mm

    r221097 r234227  
    2424 */
    2525
     26#include "config.h"
    2627#include "CurrentThisInsideBlockGetterTest.h"
    2728
  • trunk/Source/JavaScriptCore/API/tests/CustomGlobalObjectClassTest.c

    r222175 r234227  
    2424 */
    2525
     26#include "config.h"
    2627#include "CustomGlobalObjectClassTest.h"
    2728
  • trunk/Source/JavaScriptCore/API/tests/DateTests.mm

    r217182 r234227  
    2424 */
    2525
     26#import "config.h"
    2627#import "DateTests.h"
    2728#import <Foundation/Foundation.h>
  • trunk/Source/JavaScriptCore/API/tests/JSExportTests.mm

    r218316 r234227  
    2424 */
    2525
     26#import "config.h"
    2627#import "JSExportTests.h"
    2728
  • trunk/Source/JavaScriptCore/API/tests/JSNode.c

    r165676 r234227  
    2424 */
    2525
    26 #include <wtf/Platform.h>
     26#include "config.h"
    2727
    2828#include "JSNode.h"
  • trunk/Source/JavaScriptCore/API/tests/JSNodeList.c

    r165676 r234227  
    2424 */
    2525
    26 #include <wtf/Platform.h>
     26#include "config.h"
    2727
    2828#include "JSNode.h"
  • trunk/Source/JavaScriptCore/API/tests/Node.c

    r165676 r234227  
    2424 */
    2525
     26#include "config.h"
    2627#include "Node.h"
     28
    2729#include <stddef.h>
    2830#include <stdlib.h>
  • trunk/Source/JavaScriptCore/API/tests/NodeList.c

    r165676 r234227  
    2424 */
    2525
     26#include "config.h"
    2627#include "NodeList.h"
    2728
  • trunk/Source/JavaScriptCore/API/tests/minidom.c

    r165676 r234227  
    2525 */
    2626
    27 #include <wtf/Platform.h>
     27#include "config.h"
    2828
    2929#include "JSContextRef.h"
  • trunk/Source/JavaScriptCore/API/tests/testapi.c

    r221546 r234227  
    2424 */
    2525
    26 #include <wtf/Platform.h>
     26#define ASSERT_DISABLED 0
     27#include "config.h"
    2728
    2829#if USE(CF)
     
    4546#include <string.h>
    4647#include <time.h>
    47 #define ASSERT_DISABLED 0
    4848#include <wtf/Assertions.h>
    4949
     
    6666void testObjectiveCAPI(void);
    6767#endif
     68
     69int testCAPIViaCpp(void);
    6870
    6971bool assertTrue(bool value, const char* message);
     
    13621364    testObjectiveCAPI();
    13631365#endif
     1366    RELEASE_ASSERT(!testCAPIViaCpp());
    13641367
    13651368    const char *scriptPath = "testapi.js";
  • trunk/Source/JavaScriptCore/API/tests/testapi.mm

    r234180 r234227  
    2424 */
    2525
     26#import "config.h"
    2627#import "JSExportMacros.h"
    2728#import <JavaScriptCore/JavaScriptCore.h>
     
    4344#import <wtf/MemoryFootprint.h>
    4445#import <wtf/Optional.h>
     46#import <wtf/DataLog.h>
    4547
    4648extern "C" void JSSynchronousGarbageCollectForDebugging(JSContextRef);
     
    628630
    629631    @autoreleasepool {
     632        JSContext *context = [[JSContext alloc] init];
     633        JSValue *symbol = [context evaluateScript:@"Symbol('dope');"];
     634        JSValue *notSymbol = [context evaluateScript:@"'dope'"];
     635        checkResult(@"Should be a symbol value", symbol.isSymbol);
     636        checkResult(@"Should not be a symbol value", !notSymbol.isSymbol);
     637    }
     638
     639    @autoreleasepool {
     640        JSContext *context = [[JSContext alloc] init];
     641        JSValue *symbol = [JSValue valueWithNewSymbolFromDescription:@"dope" inContext:context];
     642        checkResult(@"Should be a created from Obj-C", symbol.isSymbol);
     643    }
     644
     645    @autoreleasepool {
     646        JSContext *context = [[JSContext alloc] init];
     647        JSValue *arrayIterator = [context evaluateScript:@"Array.prototype[Symbol.iterator]"];
     648        JSValue *iteratorSymbol = context[@"Symbol"][@"iterator"];
     649        JSValue *array = [JSValue valueWithNewArrayInContext:context];
     650        checkResult(@"Looking up by subscript with symbol should work", [array[iteratorSymbol] isEqual:arrayIterator]);
     651        checkResult(@"Looking up by method with symbol should work", [[array valueForProperty:iteratorSymbol] isEqual:arrayIterator]);
     652    }
     653
     654    @autoreleasepool {
     655        JSContext *context = [[JSContext alloc] init];
     656        JSValue *iteratorSymbol = context[@"Symbol"][@"iterator"];
     657        JSValue *object = [JSValue valueWithNewObjectInContext:context];
     658        JSValue *theAnswer = [JSValue valueWithUInt32:42 inContext:context];
     659        object[iteratorSymbol] = theAnswer;
     660        checkResult(@"Setting by subscript with symbol should work", [object[iteratorSymbol] isEqual:theAnswer]);
     661    }
     662
     663    @autoreleasepool {
     664        JSContext *context = [[JSContext alloc] init];
     665        JSValue *iteratorSymbol = context[@"Symbol"][@"iterator"];
     666        JSValue *object = [JSValue valueWithNewObjectInContext:context];
     667        JSValue *theAnswer = [JSValue valueWithUInt32:42 inContext:context];
     668        [object setValue:theAnswer forProperty:iteratorSymbol];
     669        checkResult(@"Setting by method with symbol should work", [object[iteratorSymbol] isEqual:theAnswer]);
     670    }
     671
     672    @autoreleasepool {
     673        JSContext *context = [[JSContext alloc] init];
     674        JSValue *iteratorSymbol = context[@"Symbol"][@"iterator"];
     675        JSValue *object = [JSValue valueWithNewObjectInContext:context];
     676        JSValue *theAnswer = [JSValue valueWithUInt32:42 inContext:context];
     677        object[iteratorSymbol] = theAnswer;
     678        checkResult(@"has property with symbol should work", [object hasProperty:iteratorSymbol]);
     679    }
     680
     681    @autoreleasepool {
     682        JSContext *context = [[JSContext alloc] init];
     683        JSValue *iteratorSymbol = context[@"Symbol"][@"iterator"];
     684        JSValue *object = [JSValue valueWithNewObjectInContext:context];
     685        JSValue *theAnswer = [JSValue valueWithUInt32:42 inContext:context];
     686        checkResult(@"delete property with symbol should work without property", [object deleteProperty:iteratorSymbol]);
     687        object[iteratorSymbol] = theAnswer;
     688        checkResult(@"delete property with symbol should work with property", [object deleteProperty:iteratorSymbol]);
     689        checkResult(@"delete should be false with non-configurable property", ![context[@"Array"] deleteProperty:@"prototype"]);
     690    }
     691
     692    @autoreleasepool {
     693        JSContext *context = [[JSContext alloc] init];
     694        JSValue *object = [JSValue valueWithNewObjectInContext:context];
     695        NSObject *objCObject = [[NSObject alloc] init];
     696        JSValue *result = object[objCObject];
     697        checkResult(@"getting a non-convertable object should return undefined", [result isUndefined]);
     698        object[objCObject] = @(1);
     699        result = object[objCObject];
     700        checkResult(@"getting a non-convertable object should return the stored value", [result toUInt32] == 1);
     701    }
     702
     703    @autoreleasepool {
     704        JSContext *context = [[JSContext alloc] init];
     705        JSValue *object = [JSValue valueWithNewObjectInContext:context];
     706        JSValue *iteratorSymbol = context[@"Symbol"][@"iterator"];
     707        object[@"value"] = @(1);
     708        context[@"object"] = object;
     709
     710        object[iteratorSymbol] = ^{
     711            JSValue *result = [JSValue valueWithNewObjectInContext:context];
     712            result[@"object"] = [JSContext currentThis];
     713            result[@"next"] = ^{
     714                JSValue *result = [JSValue valueWithNewObjectInContext:context];
     715                JSValue *value = [JSContext currentThis][@"object"][@"value"];
     716                [[JSContext currentThis][@"object"] deleteProperty:@"value"];
     717                result[@"value"] = value;
     718                result[@"done"] = [JSValue valueWithBool:[value isUndefined] inContext:context];
     719                return result;
     720            };
     721            return result;
     722        };
     723
     724
     725        JSValue *count = [context evaluateScript:@"let count = 0; for (let v of object) { if (v !== 1) throw new Error(); count++; } count;"];
     726        checkResult(@"iterator should not throw", ![context exception]);
     727        checkResult(@"iteration count should be 1", [count toUInt32] == 1);
     728    }
     729
     730    @autoreleasepool {
    630731        JSCollection* myPrivateProperties = [[JSCollection alloc] init];
    631732
  • trunk/Source/JavaScriptCore/ChangeLog

    r234207 r234227  
     12018-07-25  Keith Miller  <keith_miller@apple.com>
     2
     3        [JSC API] We should support the symbol type in our C/Obj-C API
     4        https://bugs.webkit.org/show_bug.cgi?id=175836
     5
     6        Reviewed by Filip Pizlo.
     7
     8        This patch makes the following API additions:
     9        1) Test if a JSValue/JSValueRef is a symbol via any of the methods API are able to test for the types of other JSValues.
     10        2) Create a symbol on both APIs.
     11        3) Get/Set/Delete/Define property now take ids in the Obj-C API.
     12        4) Add Get/Set/Delete in the C API.
     13
     14        We can do 3 because it is both binary and source compatable with
     15        the existing API. I added (4) because the current property access
     16        APIs only have the ability to get Strings. It was possible to
     17        merge symbols into JSStringRef but that felt confusing and exposes
     18        implementation details of our engine. The new functions match the
     19        same meaning that they have in JS, thus should be forward
     20        compatible with any future language extensions.
     21
     22        Lastly, this patch adds the same availability preproccessing phase
     23        in WebCore to JavaScriptCore, which enables TBA features for
     24        testing on previous releases.
     25
     26        * API/APICast.h:
     27        * API/JSBasePrivate.h:
     28        * API/JSContext.h:
     29        * API/JSContextPrivate.h:
     30        * API/JSContextRef.h:
     31        * API/JSContextRefInternal.h:
     32        * API/JSContextRefPrivate.h:
     33        * API/JSManagedValue.h:
     34        * API/JSObjectRef.cpp:
     35        (JSObjectHasPropertyKey):
     36        (JSObjectGetPropertyKey):
     37        (JSObjectSetPropertyKey):
     38        (JSObjectDeletePropertyKey):
     39        * API/JSObjectRef.h:
     40        * API/JSRemoteInspector.h:
     41        * API/JSTypedArray.h:
     42        * API/JSValue.h:
     43        * API/JSValue.mm:
     44        (+[JSValue valueWithNewSymbolFromDescription:inContext:]):
     45        (performPropertyOperation):
     46        (-[JSValue valueForProperty:valueForProperty:]):
     47        (-[JSValue setValue:forProperty:setValue:forProperty:]):
     48        (-[JSValue deleteProperty:deleteProperty:]):
     49        (-[JSValue hasProperty:hasProperty:]):
     50        (-[JSValue defineProperty:descriptor:defineProperty:descriptor:]):
     51        (-[JSValue isSymbol]):
     52        (-[JSValue objectForKeyedSubscript:]):
     53        (-[JSValue setObject:forKeyedSubscript:]):
     54        (-[JSValue valueForProperty:]): Deleted.
     55        (-[JSValue setValue:forProperty:]): Deleted.
     56        (-[JSValue deleteProperty:]): Deleted.
     57        (-[JSValue hasProperty:]): Deleted.
     58        (-[JSValue defineProperty:descriptor:]): Deleted.
     59        * API/JSValueRef.cpp:
     60        (JSValueGetType):
     61        (JSValueIsSymbol):
     62        (JSValueMakeSymbol):
     63        * API/JSValueRef.h:
     64        * API/WebKitAvailability.h:
     65        * API/tests/CurrentThisInsideBlockGetterTest.mm:
     66        * API/tests/CustomGlobalObjectClassTest.c:
     67        * API/tests/DateTests.mm:
     68        * API/tests/JSExportTests.mm:
     69        * API/tests/JSNode.c:
     70        * API/tests/JSNodeList.c:
     71        * API/tests/Node.c:
     72        * API/tests/NodeList.c:
     73        * API/tests/minidom.c:
     74        * API/tests/testapi.c:
     75        (main):
     76        * API/tests/testapi.cpp: Added.
     77        (APIString::APIString):
     78        (APIString::~APIString):
     79        (APIString::operator JSStringRef):
     80        (APIContext::APIContext):
     81        (APIContext::~APIContext):
     82        (APIContext::operator JSGlobalContextRef):
     83        (APIVector::APIVector):
     84        (APIVector::~APIVector):
     85        (APIVector::append):
     86        (testCAPIViaCpp):
     87        (TestAPI::evaluateScript):
     88        (TestAPI::callFunction):
     89        (TestAPI::functionReturnsTrue):
     90        (TestAPI::check):
     91        (TestAPI::checkJSAndAPIMatch):
     92        (TestAPI::interestingObjects):
     93        (TestAPI::interestingKeys):
     94        (TestAPI::run):
     95        * API/tests/testapi.mm:
     96        (testObjectiveCAPIMain):
     97        * JavaScriptCore.xcodeproj/project.pbxproj:
     98        * config.h:
     99        * postprocess-headers.sh:
     100        * shell/CMakeLists.txt:
     101        * testmem/testmem.mm:
     102
    11032018-07-25  Andy VanWagoner  <andy@vanwagoner.family>
    2104
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r234127 r234227  
    10411041                53E9E0AC1EAE83DF00FEE251 /* WasmMachineThreads.h in Headers */ = {isa = PBXBuildFile; fileRef = 53E9E0AA1EAE83DE00FEE251 /* WasmMachineThreads.h */; };
    10421042                53E9E0AF1EAEC45700FEE251 /* WasmTierUpCount.h in Headers */ = {isa = PBXBuildFile; fileRef = 53E9E0AE1EAEC45700FEE251 /* WasmTierUpCount.h */; settings = {ATTRIBUTES = (Private, ); }; };
    1043                 53F11F41209138D700E411A7 /* JSImmutableButterfly.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F11F40209138D700E411A7 /* JSImmutableButterfly.h */; };
    1044                 53F40E851D58F9770099A1B6 /* WasmSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WasmSections.h */; };
     1043                53F11F41209138D700E411A7 /* JSImmutableButterfly.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F11F40209138D700E411A7 /* JSImmutableButterfly.h */; };
     1044                53EAFE2F208DFAB4007D524B /* testapi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 531D4E191F59CDD200EC836C /* testapi.cpp */; };
     1045                53F40E851D58F9770099A1B6 /* WasmSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WasmSections.h */; };
    10451046                53F40E8B1D5901BB0099A1B6 /* WasmFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WasmFunctionParser.h */; };
    10461047                53F40E8D1D5901F20099A1B6 /* WasmParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WasmParser.h */; };
     
    33063307                531374BC1D5CE67600AF7A0B /* WasmPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmPlan.h; sourceTree = "<group>"; };
    33073308                531374BE1D5CE95000AF7A0B /* WasmPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmPlan.cpp; sourceTree = "<group>"; };
     3309                531D4E191F59CDD200EC836C /* testapi.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = testapi.cpp; path = API/tests/testapi.cpp; sourceTree = "<group>"; };
    33083310                533B15DE1DC7F463004D500A /* WasmOps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmOps.h; sourceTree = "<group>"; };
    33093311                5341FC6F1DAC33E500E7E4D7 /* B3WasmBoundsCheckValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3WasmBoundsCheckValue.cpp; path = b3/B3WasmBoundsCheckValue.cpp; sourceTree = "<group>"; };
     
    34763478                53917E7C1B791106000EBD33 /* JSTypedArrayViewPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArrayViewPrototype.h; sourceTree = "<group>"; };
    34773479                53917E831B791CB8000EBD33 /* TypedArrayPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TypedArrayPrototype.js; path = builtins/TypedArrayPrototype.js; sourceTree = SOURCE_ROOT; };
    3478                 539EB0711D553DF800C82EF7 /* testWasm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = testWasm.cpp; sourceTree = "<group>"; };
    34793480                539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = "<group>"; };
    34803481                53B0BE331E561AC900A8FC29 /* GetterSetterAccessCase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetterSetterAccessCase.cpp; sourceTree = "<group>"; };
     
    54685469                                FECB8B291D25CABB006F2463 /* testapi-function-overrides.js */,
    54695470                                14BD5A2D0A3E91F600BAF59C /* testapi.c */,
     5471                                531D4E191F59CDD200EC836C /* testapi.cpp */,
    54705472                                14D857740A4696C80032146C /* testapi.js */,
    54715473                                86D22219167EF9440024C804 /* testapi.mm */,
    54725474                                651122E5140469BA002B101D /* testRegExp.cpp */,
    5473                                 539EB0711D553DF800C82EF7 /* testWasm.cpp */,
    54745475                                534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */,
    54755476                                534902831C7242C80012BCB8 /* TypedArrayCTest.h */,
     
    89838984                                0FB467811FDDA6F7003FCB09 /* IsoCellSetInlines.h in Headers */,
    89848985                                0FDCE12D1FAFB4E5006F3901 /* IsoSubspace.h in Headers */,
    8985                                 0FD2FD9520B52BE200F09441 /* IsoSubspaceInlines.h in Headers */,
    8986                                 0F5E0FE72086AD480097F0DE /* IsoSubspacePerVM.h in Headers */,
     8986                                0FD2FD9520B52BE200F09441 /* IsoSubspaceInlines.h in Headers */,
     8987                                0F5E0FE72086AD480097F0DE /* IsoSubspacePerVM.h in Headers */,
    89878988                                8B9F6D561D5912FA001C739F /* IterationKind.h in Headers */,
    89888989                                FE4D55B81AE716CA0052E459 /* IterationStatus.h in Headers */,
     
    1020410205                                FEB51F6C1A97B688001F921C /* Regress141809.mm in Sources */,
    1020510206                                1440F6100A4F85670005F061 /* testapi.c in Sources */,
     10207                                53EAFE2F208DFAB4007D524B /* testapi.cpp in Sources */,
    1020610208                                86D2221A167EF9440024C804 /* testapi.mm in Sources */,
    1020710209                                534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */,
     
    1067110673                        baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
    1067210674                        buildSettings = {
     10675                                HEADER_SEARCH_PATHS = (
     10676                                        "\"$(JAVASCRIPTCORE_FRAMEWORKS_DIR)/JavaScriptCore.framework/PrivateHeaders\"",
     10677                                        "$(inherited)",
     10678                                );
    1067310679                        };
    1067410680                        name = Debug;
     
    1067810684                        baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
    1067910685                        buildSettings = {
     10686                                HEADER_SEARCH_PATHS = (
     10687                                        "\"$(JAVASCRIPTCORE_FRAMEWORKS_DIR)/JavaScriptCore.framework/PrivateHeaders\"",
     10688                                        "$(inherited)",
     10689                                );
    1068010690                        };
    1068110691                        name = Release;
     
    1068510695                        baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
    1068610696                        buildSettings = {
     10697                                HEADER_SEARCH_PATHS = (
     10698                                        "\"$(JAVASCRIPTCORE_FRAMEWORKS_DIR)/JavaScriptCore.framework/PrivateHeaders\"",
     10699                                        "$(inherited)",
     10700                                );
    1068710701                        };
    1068810702                        name = Production;
     
    1100911023                        baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
    1101011024                        buildSettings = {
     11025                                HEADER_SEARCH_PATHS = (
     11026                                        "\"$(JAVASCRIPTCORE_FRAMEWORKS_DIR)/JavaScriptCore.framework/PrivateHeaders\"",
     11027                                        "$(inherited)",
     11028                                );
    1101111029                        };
    1101211030                        name = Profiling;
  • trunk/Source/JavaScriptCore/config.h

    r224277 r234227  
    2424#endif
    2525
     26#define JSC_API_AVAILABLE(...)
     27// Use zero since it will be less than any possible version number.
     28#define JSC_MAC_VERSION_TBA 0
     29#define JSC_IOS_VERSION_TBA 0
     30
    2631#include "JSExportMacros.h"
    2732
  • trunk/Source/JavaScriptCore/postprocess-headers.sh

    r194821 r234227  
    1 cd "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
     1#!/bin/sh
     2#
     3# Copyright (C) 2014-2018 Apple Inc. All rights reserved.
     4#
     5# Redistribution and use in source and binary forms, with or without
     6# modification, are permitted provided that the following conditions
     7# are met:
     8# 1. Redistributions of source code must retain the above copyright
     9#    notice, this list of conditions and the following disclaimer.
     10# 2. Redistributions in binary form must reproduce the above copyright
     11#    notice, this list of conditions and the following disclaimer in the
     12#    documentation and/or other materials provided with the distribution.
     13#
     14# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     15# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     16# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     18# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     19# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     20# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     21# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     22# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     23# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     24# THE POSSIBILITY OF SUCH DAMAGE.
     25#
    226
    3 UNIFDEF_OPTIONS="-D__MAC_OS_X_VERSION_MIN_REQUIRED=${TARGET_MAC_OS_X_VERSION_MAJOR}"
     27if [[ "${JSC_FRAMEWORK_HEADER_POSTPROCESSING_DISABLED}" == "YES" ]]; then
     28    exit 0;
     29fi
    430
    5 for ((i = 0; i < ${SCRIPT_INPUT_FILE_COUNT}; ++i)); do
    6     eval HEADER=\${SCRIPT_INPUT_FILE_${i}};
    7     unifdef -B ${UNIFDEF_OPTIONS} -o "${HEADER}".unifdef "${HEADER}"
    8     case $? in
    9     0)
    10         rm "${HEADER}".unifdef
    11         ;;
    12     1)
    13         mv "${HEADER}"{.unifdef,}
    14         ;;
    15     *)
    16         exit 1
    17     esac
    18 done
     31TIMESTAMP_PATH=${TARGET_TEMP_DIR}/${0##*/}
     32
     33if [[ -e $TIMESTAMP_PATH && $0 -nt $TIMESTAMP_PATH ]]; then
     34    rm "${TIMESTAMP_PATH}";
     35fi
     36
     37function process_definitions () {
     38    local DEFINITIONS_FILE=$1
     39
     40    if [[ ! -f "${DEFINITIONS_FILE}" ]]; then
     41        return 1
     42    fi
     43
     44    if [[ -e $TIMESTAMP_PATH && "${DEFINITIONS_FILE}" -nt $TIMESTAMP_PATH ]]; then
     45        rm "${TIMESTAMP_PATH}";
     46    fi
     47
     48    source "${DEFINITIONS_FILE}"
     49}
     50
     51function rewrite_headers () {
     52    if [[ "${PLATFORM_NAME}" == "macosx" ]]; then
     53        [[ -n ${OSX_VERSION} ]] || OSX_VERSION=${MACOSX_DEPLOYMENT_TARGET}
     54        [[ -n ${IOS_VERSION} ]] || IOS_VERSION="NA"
     55        [[ -n ${OSX_VERSION_NUMBER} ]] || OSX_VERSION_NUMBER=${TARGET_MAC_OS_X_VERSION_MAJOR}
     56        [[ -n ${IOS_VERSION_NUMBER} ]] || IOS_VERSION_NUMBER="0"
     57    elif [[ "${PLATFORM_NAME}" =~ "iphone" ]]; then
     58        [[ -n ${IOS_VERSION} ]] || IOS_VERSION=${IPHONEOS_DEPLOYMENT_TARGET}
     59        [[ -n ${OSX_VERSION} ]] || OSX_VERSION="NA"
     60        [[ -n ${OSX_VERSION_NUMBER} ]] || OSX_VERSION_NUMBER="0"
     61        [[ -n ${IOS_VERSION_NUMBER} ]] || IOS_VERSION_NUMBER=${SDK_VERSION_MAJOR}
     62    fi
     63
     64    SED_OPTIONS=(
     65    )
     66
     67    if [[ -n "$OSX_VERSION" && -n "$IOS_VERSION" ]]; then
     68        SED_OPTIONS+=(
     69            -e s/JSC_MAC_TBA/${OSX_VERSION}/g
     70            -e s/JSC_IOS_TBA/${IOS_VERSION}/g
     71            -e s/JSC_MAC_VERSION_TBA/${OSX_VERSION_NUMBER}/g
     72            -e s/JSC_IOS_VERSION_TBA/${IOS_VERSION_NUMBER}/g
     73            -e s/JSC_API_AVAILABLE/API_AVAILABLE/
     74            -e s/JSC_API_DEPRECATED/API_DEPRECATED/
     75            -e "s/^JSC_CLASS_AVAILABLE/JSC_EXTERN API_AVAILABLE/"
     76            -e "s/^JSC_CLASS_DEPRECATED/JSC_EXTERN API_DEPRECATED/"
     77        )
     78    else
     79        SED_OPTIONS+=(-e 's/JSC_(API_|CLASS_)AVAILABLE\(.*\)\s*\)//g' -e 's/JSC_(API_|CLASS_)DEPRECATED(_WITH_REPLACEMENT)?\(.*\)\s*\)//g')
     80    fi
     81
     82    SED_OPTIONS+=(${OTHER_SED_OPTIONS[*]})
     83
     84    for HEADER_PATH in "${1}/"*.h; do
     85        if [[ "$HEADER_PATH" -nt $TIMESTAMP_PATH ]]; then
     86            ditto "${HEADER_PATH}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
     87            sed -i .tmp -E "${SED_OPTIONS[@]}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" || exit $?
     88            mv "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" "$HEADER_PATH"
     89        fi
     90    done
     91}
     92
     93DEFINITIONS_PATH=usr/local/include/WebKitAdditions/Scripts/postprocess-framework-headers-definitions
     94
     95process_definitions "${BUILT_PRODUCTS_DIR}/${DEFINITIONS_PATH}" || process_definitions "${SDKROOT}/${DEFINITIONS_PATH}"
     96
     97rewrite_headers "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
     98rewrite_headers "${TARGET_BUILD_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}"
     99
     100touch ${TIMESTAMP_PATH}
  • trunk/Source/JavaScriptCore/shell/CMakeLists.txt

    r227952 r234227  
    2929    ../API/tests/TypedArrayCTest.cpp
    3030    ../API/tests/testapi.c
     31    ../API/tests/testapi.cpp
    3132)
    3233
  • trunk/Source/JavaScriptCore/testmem/testmem.mm

    r232193 r234227  
    2424 */
    2525
     26#import "config.h"
    2627#import <JavaScriptCore/JavaScriptCore.h>
    2728#import <inttypes.h>
Note: See TracChangeset for help on using the changeset viewer.