⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 236520 in webkit


Ignore:
Timestamp:
Sep 26, 2018, 1:04:27 PM (8 years ago)
Author:
keith_miller@apple.com
Message:

Move Symbol API to SPI
https://bugs.webkit.org/show_bug.cgi?id=189946

Reviewed by Michael Saboff.

Some of the property access methods on JSValue needed to be moved
to a category so that SPI overloads don't result in a compiler
error for internal users.

Additionally, this patch does not move the new enum entry for
Symbols in the JSType enumeration.

  • API/JSObjectRef.h:
  • API/JSObjectRefPrivate.h:
  • API/JSValue.h:
  • API/JSValuePrivate.h:
  • API/JSValueRef.h:
Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

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

    r234381 r236520  
    556556/*!
    557557@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 */
    565 JS_EXPORT bool JSObjectHasPropertyForKey(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 */
    577 JS_EXPORT JSValueRef JSObjectGetPropertyForKey(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 */
    590 JS_EXPORT void JSObjectSetPropertyForKey(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 */
    602 JS_EXPORT bool JSObjectDeletePropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    603 
    604 /*!
    605 @function
    606558@abstract Gets a property from an object by numeric index.
    607559@param ctx The execution context to use.
  • trunk/Source/JavaScriptCore/API/JSObjectRefPrivate.h

    r236372 r236520  
    8282 */
    8383JS_EXPORT JSObjectRef JSObjectMakeDeferredPromise(JSContextRef ctx, JSObjectRef* resolve, JSObjectRef* reject, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    84    
     84
     85/*!
     86 @function
     87 @abstract Tests whether an object has a given property using a JSValueRef as the property key.
     88 @param object The JSObject to test.
     89 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
     90 @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.
     91 @result true if the object has a property whose name matches propertyKey, otherwise false.
     92 @discussion This function is the same as performing "propertyKey in object" from JavaScript.
     93 */
     94JS_EXPORT bool JSObjectHasPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     95
     96/*!
     97 @function
     98 @abstract Gets a property from an object using a JSValueRef as the property key.
     99 @param ctx The execution context to use.
     100 @param object The JSObject whose property you want to get.
     101 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
     102 @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.
     103 @result The property's value if object has the property key, otherwise the undefined value.
     104 @discussion This function is the same as performing "object[propertyKey]" from JavaScript.
     105 */
     106JS_EXPORT JSValueRef JSObjectGetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     107
     108/*!
     109 @function
     110 @abstract Sets a property on an object using a JSValueRef as the property key.
     111 @param ctx The execution context to use.
     112 @param object The JSObject whose property you want to set.
     113 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
     114 @param value A JSValueRef to use as the property's value.
     115 @param attributes A logically ORed set of JSPropertyAttributes to give to the property.
     116 @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.
     117 @discussion This function is the same as performing "object[propertyKey] = value" from JavaScript.
     118 */
     119JS_EXPORT void JSObjectSetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     120
     121/*!
     122 @function
     123 @abstract Deletes a property from an object using a JSValueRef as the property key.
     124 @param ctx The execution context to use.
     125 @param object The JSObject whose property you want to delete.
     126 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
     127 @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.
     128 @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
     129 @discussion This function is the same as performing "delete object[propertyKey]" from JavaScript.
     130 */
     131JS_EXPORT bool JSObjectDeletePropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     132
     133/*!
     134 @function
     135 @abstract       Tests whether a JavaScript value's type is the symbol type.
     136 @param ctx      The execution context to use.
     137 @param value    The JSValue to test.
     138 @result         true if value's type is the symbol type, otherwise false.
     139 */
     140JS_EXPORT bool JSValueIsSymbol(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     141
    85142#ifdef __cplusplus
    86143}
  • trunk/Source/JavaScriptCore/API/JSValue.h

    r235465 r236520  
    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)
    51 typedef NSString *JSValueProperty;
    52 #else
    53 typedef id JSValueProperty;
    54 #endif
    55 
    5650/*!
    5751@property
     
    154148*/
    155149+ (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));
    165150
    166151/*!
     
    319304
    320305/*!
    321 @methodgroup Accessing Properties
    322 */
    323 
    324 /*!
    325 @method
    326 @abstract Access a property of a JSValue.
    327 @result The JSValue for the requested property or the JSValue <code>undefined</code>
    328  if the property does not exist.
    329 @discussion Corresponds to the JavaScript operation <code>object[property]</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
    330 */
    331 - (JSValue *)valueForProperty:(JSValueProperty)property;
    332 
    333 /*!
    334 @method
    335 @abstract Set a property on a JSValue.
    336 @discussion Corresponds to the JavaScript operation <code>object[property] = value</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
    337 */
    338 - (void)setValue:(id)value forProperty:(JSValueProperty)property;
    339 
    340 /*!
    341 @method
    342 @abstract Delete a property from a JSValue.
    343 @result YES if deletion is successful, NO otherwise.
    344 @discussion Corresponds to the JavaScript operation <code>delete object[property]</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
    345 */
    346 - (BOOL)deleteProperty:(JSValueProperty)property;
    347 
    348 /*!
    349 @method
    350 @abstract Check if a JSValue has a property.
    351 @discussion This method has the same function as the JavaScript operator <code>in</code>.
    352 @result Returns YES if property is present on the value.
    353 @discussion Corresponds to the JavaScript operation <code>property in object</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
    354 */
    355 - (BOOL)hasProperty:(JSValueProperty)property;
    356 
    357 /*!
    358 @method
    359 @abstract Define properties with custom descriptors on JSValues.
    360 @discussion This method may be used to create a data or accessor property on an object.
    361  This method operates in accordance with the Object.defineProperty method in the JavaScript language. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
    362 */
    363 - (void)defineProperty:(JSValueProperty)property descriptor:(id)descriptor;
    364 
    365 /*!
    366 @method
    367 @abstract Access an indexed (numerical) property on a JSValue.
    368 @result The JSValue for the property at the specified index.
    369  Returns the JavaScript value <code>undefined</code> if no property exists at that index.
    370 */
    371 - (JSValue *)valueAtIndex:(NSUInteger)index;
    372 
    373 /*!
    374 @method
    375 @abstract Set an indexed (numerical) property on a JSValue.
    376 @discussion For JSValues that are JavaScript arrays, indices greater than
    377  UINT_MAX - 1 will not affect the length of the array.
    378 */
    379 - (void)setValue:(id)value atIndex:(NSUInteger)index;
    380 
    381 /*!
    382306@functiongroup Checking JavaScript Types
    383307*/
     
    421345*/
    422346@property (readonly) BOOL isObject;
    423 
    424 /*!
    425 @property
    426 @abstract Check if a JSValue is a symbol.
    427 */
    428 @property (readonly) BOOL isSymbol JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    429347
    430348/*!
     
    582500
    583501/*!
     502 @category
     503 @discussion These methods enable querying properties on a JSValue.
     504 */
     505@interface JSValue (PropertyAccess)
     506
     507/*!
     508 @method
     509 @abstract Access a property of a JSValue.
     510 @result The JSValue for the requested property or the JSValue <code>undefined</code>
     511 if the property does not exist.
     512 */
     513- (JSValue *)valueForProperty:(NSString *)property;
     514
     515/*!
     516 @method
     517 @abstract Set a property on a JSValue.
     518 */
     519- (void)setValue:(id)value forProperty:(NSString *)property;
     520
     521/*!
     522 @method
     523 @abstract Delete a property from a JSValue.
     524 @result YES if deletion is successful, NO otherwise.
     525 */
     526- (BOOL)deleteProperty:(NSString *)property;
     527
     528/*!
     529 @method
     530 @abstract Check if a JSValue has a property.
     531 @discussion This method has the same function as the JavaScript operator <code>in</code>.
     532 @result Returns YES if property is present on the value.
     533 */
     534- (BOOL)hasProperty:(NSString *)property;
     535
     536/*!
     537 @method
     538 @abstract Define properties with custom descriptors on JSValues.
     539 @discussion This method may be used to create a data or accessor property on an object.
     540 This method operates in accordance with the Object.defineProperty method in the
     541 JavaScript language.
     542 */
     543- (void)defineProperty:(NSString *)property descriptor:(id)descriptor;
     544
     545/*!
     546 @method
     547 @abstract Access an indexed (numerical) property on a JSValue.
     548 @result The JSValue for the property at the specified index.
     549 Returns the JavaScript value <code>undefined</code> if no property exists at that index.
     550 */
     551- (JSValue *)valueAtIndex:(NSUInteger)index;
     552
     553/*!
     554 @method
     555 @abstract Set an indexed (numerical) property on a JSValue.
     556 @discussion For JSValues that are JavaScript arrays, indices greater than
     557 UINT_MAX - 1 will not affect the length of the array.
     558 */
     559- (void)setValue:(id)value atIndex:(NSUInteger)index;
     560
     561@end
     562
     563/*!
    584564@category
    585565@discussion Instances of JSValue implement the following methods in order to enable
     
    595575
    596576 An object key passed as a subscript will be converted to a JavaScript value,
    597  and then the value using the same rules as <code>valueWithObject:inContext:</code>. In macOS
    598  TBA and iOS TBA and below, the <code>key</code> argument of
    599  <code>setObject:object forKeyedSubscript:key</code> was restricted to an
    600  <code>NSString <NSCopying> *</code> but that restriction was never used.
     577 and then the value converted to a string used as a property name.
    601578*/
    602579@interface JSValue (SubscriptSupport)
    603580
    604 - (JSValue *)objectForKeyedSubscript:(JSValueProperty)key;
     581- (JSValue *)objectForKeyedSubscript:(id)key;
    605582- (JSValue *)objectAtIndexedSubscript:(NSUInteger)index;
    606 - (void)setObject:(id)object forKeyedSubscript:(JSValueProperty)key;
     583- (void)setObject:(id)object forKeyedSubscript:(NSObject <NSCopying> *)key;
    607584- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
    608585
  • trunk/Source/JavaScriptCore/API/JSValuePrivate.h

    r236372 r236520  
    2929
    3030@interface JSValue(JSPrivate)
     31
     32#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)
     33typedef NSString *JSValueProperty;
     34#else
     35typedef id JSValueProperty;
     36#endif
     37
     38/*!
     39 @method
     40 @abstract Create a new, unique, symbol object.
     41 @param description The description of the symbol object being created.
     42 @param context The JSContext to which the resulting JSValue belongs.
     43 @result The JSValue representing a unique JavaScript value with type symbol.
     44 */
     45+ (JSValue *)valueWithNewSymbolFromDescription:(NSString *)description inContext:(JSContext *)context JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
     46
     47/*!
     48 @method
     49 @abstract Access a property of a JSValue.
     50 @result The JSValue for the requested property or the JSValue <code>undefined</code>
     51 if the property does not exist.
     52 @discussion Corresponds to the JavaScript operation <code>object[property]</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
     53 */
     54- (JSValue *)valueForProperty:(JSValueProperty)property;
     55
     56/*!
     57 @method
     58 @abstract Set a property on a JSValue.
     59 @discussion Corresponds to the JavaScript operation <code>object[property] = value</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
     60 */
     61- (void)setValue:(id)value forProperty:(JSValueProperty)property;
     62
     63/*!
     64 @method
     65 @abstract Delete a property from a JSValue.
     66 @result YES if deletion is successful, NO otherwise.
     67 @discussion Corresponds to the JavaScript operation <code>delete object[property]</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
     68 */
     69- (BOOL)deleteProperty:(JSValueProperty)property;
     70
     71/*!
     72 @method
     73 @abstract Check if a JSValue has a property.
     74 @discussion This method has the same function as the JavaScript operator <code>in</code>.
     75 @result Returns YES if property is present on the value.
     76 @discussion Corresponds to the JavaScript operation <code>property in object</code>. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
     77 */
     78- (BOOL)hasProperty:(JSValueProperty)property;
     79
     80/*!
     81 @method
     82 @abstract Define properties with custom descriptors on JSValues.
     83 @discussion This method may be used to create a data or accessor property on an object.
     84 This method operates in accordance with the Object.defineProperty method in the JavaScript language. After macOS TBA and iOS TBA, 'property' can be any 'id' and will be converted to a JSValue using the conversion rules of <code>valueWithObject:inContext:</code>. Prior to macOS TBA and iOS TBA, 'property' was expected to be an NSString *.
     85 */
     86- (void)defineProperty:(JSValueProperty)property descriptor:(id)descriptor;
     87
     88/*!
     89 @property
     90 @abstract Check if a JSValue is a symbol.
     91 */
     92@property (readonly) BOOL isSymbol JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    3193
    3294/*!
     
    69131@end
    70132
     133/*!
     134 @category
     135 @discussion Instances of JSValue implement the following methods in order to enable
     136 support for subscript access by key and index, for example:
     137
     138 @textblock
     139 JSValue *objectA, *objectB;
     140 JSValue *v1 = object[@"X"]; // Get value for property "X" from 'object'.
     141 JSValue *v2 = object[42];   // Get value for index 42 from 'object'.
     142 object[@"Y"] = v1;          // Assign 'v1' to property "Y" of 'object'.
     143 object[101] = v2;           // Assign 'v2' to index 101 of 'object'.
     144 @/textblock
     145
     146 An object key passed as a subscript will be converted to a JavaScript value,
     147 and then the value using the same rules as <code>valueWithObject:inContext:</code>. In macOS
     148 TBA and iOS TBA and below, the <code>key</code> argument of
     149 <code>setObject:object forKeyedSubscript:key</code> was restricted to an
     150 <code>NSString <NSCopying> *</code> but that restriction was never used.
     151 */
     152@interface JSValue (SubscriptSupportPrivate)
     153
     154- (JSValue *)objectForKeyedSubscript:(JSValueProperty)key;
     155- (JSValue *)objectAtIndexedSubscript:(NSUInteger)index;
     156- (void)setObject:(id)object forKeyedSubscript:(JSValueProperty)key;
     157- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
     158
     159@end
     160
    71161#endif // JSC_OBJC_API_ENABLED
  • trunk/Source/JavaScriptCore/API/JSValueRef.h

    r234858 r236520  
    152152JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
    153153
    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 */
    161 JS_EXPORT bool JSValueIsSymbol(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA));
    162 
    163154
    164155/*!
  • trunk/Source/JavaScriptCore/ChangeLog

    r236514 r236520  
     12018-09-25  Keith Miller  <keith_miller@apple.com>
     2
     3        Move Symbol API to SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=189946
     5
     6        Reviewed by Michael Saboff.
     7
     8        Some of the property access methods on JSValue needed to be moved
     9        to a category so that SPI overloads don't result in a compiler
     10        error for internal users.
     11
     12        Additionally, this patch does not move the new enum entry for
     13        Symbols in the JSType enumeration.
     14
     15        * API/JSObjectRef.h:
     16        * API/JSObjectRefPrivate.h:
     17        * API/JSValue.h:
     18        * API/JSValuePrivate.h:
     19        * API/JSValueRef.h:
     20
    1212018-09-26  Keith Miller  <keith_miller@apple.com>
    222
Note: See TracChangeset for help on using the changeset viewer.