Changeset 197983 in webkit


Ignore:
Timestamp:
Mar 10, 2016 6:46:03 PM (8 years ago)
Author:
keith_miller@apple.com
Message:

Typed Arrays have no public facing API
https://bugs.webkit.org/show_bug.cgi?id=120112

Reviewed by Geoffrey Garen.

This patch adds a new C-API (an Obj-C API will follow in the future) for Typed Arrays. The API has two sets of
functions. One for Typed Arrays and another for Array Buffers. This API is intended to reflect the use of Typed
Array objects in JS code. There is a method for each of the core TypedArray and Array Buffer methods.
Originally, we were planning on using a separate non-JS object as the backing store instead of a JS Array Buffer
but we decide to defer that idea since there was no good CF/NS API that met all the constraints we needed
(Discussed further below). We also wanted to want until Shared Array Buffers had reached a more finished state
to see what impact they might have on an API.

The API has the following Typed Array construction methods:
1) Create with length (the backing buffer is zero initialized). -- JSObjectMakeTypedArray
2) Create with an existing pointer and a destructor. -- JSObjectMakeTypedArrayFromBytesNoCopy
3) Create with an Array Buffer object. -- JSObjectMakeTypedArrayFromArrayBuffer
4) Create with an Array Buffer object with a given offset and length. -- JSObjectMakeTypedArrayFromArrayBufferWithOffset

The API has the following functions on Typed Array JSObjectRefs:
5) Get access to a temporary void* of the backing store's data. -- JSObjectGetTypedArrayBytesPtr
6) Get the length of a Typed Array object (returns 0 if it is not a Typed Array object). -- JSObjectGetTypedArrayLength
7) Get the byte length of a Typed Array object (returns 0 if it is not a Typed Array object). -- JSObjectGetTypedArrayByteLength
8) Get the byte offset of a Typed Array object (returns 0 if it is not a Typed Array object). -- JSObjectGetTypedArrayByteOffset
9) Get a Typed Array object's Array Buffer backing store. -- JSObjectGetTypedArrayBuffer

The API has the following Array Buffer construction method:
10) Create with an existing pointer and a destructor. -- JSObjectMakeArrayBufferWithBytesNoCopy

The API has the following functions on Array Buffer JSObjectRefs:
11) Get access to a temporary void* of the backing store's data. -- JSObjectGetArrayBufferBytesPtr
12) Get the byte length of an Array Buffer object (returns 0 if it is not an Array Buffer object). -- JSObjectGetArrayBufferByteLength

The API adds the following new typedefs and enumerations:
13) A typedef representing the function pointer type used to deallocate byte pointers provided to constructors. -- JSTypedArrayByesDeallocator
14) An enumeration indicating the Typed Array API type of a JSValueRef. -- JSTypedArrayType

Finally, The API has the following function to get Typed Array Types:
15) Get the Typed Array type of a JS value. -- JSValueGetTypedArrayType

There are a couple of things to note about these functions. Calling JSObjectGetTypedArrayBytesPtr (5) or
JSObjectGetArrayBufferBytesPtr (12) will pin and lock the ArrayBuffer's data for the remaining lifetime of that
ArrayBuffer. This is because, currently, we do not have finalizers for our Array Buffers or Typed Arrays with a
backing ArrayBuffer and adding one would likely incur a non-trivial cost to GC. Also, we do not have a direct
way to make a Typed Array from a pointer with an offset as we do not expect using offsets to be a common use
case of the API.

While it would have been nice to integrate our backing store with CFData or one of its subclasses, it is not
possible to force a CFData/CFMutableData to be both writable and have a fixed size/backing store pointer.
NSData is not writable and CFMutableData can have a fixed pointer if it is allocated with a non-zero capacity
but there is no way for us to force an existing CFMutableData into this state.

  • API/APIUtils.h: Copied from Source/JavaScriptCore/runtime/ArrayBuffer.cpp.

(handleExceptionIfNeeded):
(setException):

  • API/JSBase.h:
  • API/JSObjectRef.cpp:

(handleExceptionIfNeeded): Deleted.

  • API/JSTypedArray.cpp: Added.

(toJSTypedArrayType):
(toTypedArrayType):
(createTypedArray):
(JSValueGetTypedArrayType):
(JSObjectMakeTypedArray):
(JSObjectMakeTypedArrayWithBytesNoCopy):
(JSObjectMakeTypedArrayWithArrayBuffer):
(JSObjectMakeTypedArrayWithArrayBufferAndOffset):
(JSObjectGetTypedArrayBytesPtr):
(JSObjectGetTypedArrayLength):
(JSObjectGetTypedArrayByteLength):
(JSObjectGetTypedArrayByteOffset):
(JSObjectGetTypedArrayBuffer):
(JSObjectMakeArrayBufferWithBytesNoCopy):
(JSObjectGetArrayBufferBytesPtr):
(JSObjectGetArrayBufferByteLength):

  • API/JSTypedArray.h: Added.
  • API/JSValueRef.cpp:

(handleExceptionIfNeeded): Deleted.

  • API/JSValueRef.h:
  • API/JavaScript.h:
  • API/WebKitAvailability.h:
  • API/tests/TypedArrayCTest.cpp: Added.

(id):
(freePtr):
(assertEqualsAsNumber):
(testAccess):
(testConstructors):
(forEachTypedArrayType):
(testTypedArrayCAPI):

  • API/tests/TypedArrayCTest.h: Added.
  • API/tests/testapi.c:

(main):

  • CMakeLists.txt:
  • ForwardingHeaders/JavaScriptCore/JSTypedArray.h: Added.
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • PlatformEfl.cmake:
  • PlatformGTK.cmake:
  • runtime/ArrayBuffer.cpp:

(JSC::ArrayBuffer::transfer):

  • runtime/ArrayBuffer.h:

(JSC::arrayBufferDestructorNull):
(JSC::arrayBufferDestructorDefault):
(JSC::ArrayBufferContents::ArrayBufferContents):
(JSC::ArrayBufferContents::transfer):
(JSC::ArrayBuffer::createAdopted):
(JSC::ArrayBuffer::createFromBytes):
(JSC::ArrayBuffer::ArrayBuffer):
(JSC::ArrayBuffer::pinAndLock):
(JSC::ArrayBufferContents::tryAllocate):
(JSC::ArrayBufferContents::~ArrayBufferContents):

  • shell/PlatformWin.cmake:
Location:
trunk/Source/JavaScriptCore
Files:
5 added
15 edited
1 copied

Legend:

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

    r197982 r197983  
    11/*
    2  * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #include "config.h"
    27 #include "ArrayBuffer.h"
     26#ifndef APIUtils_h
     27#define APIUtils_h
    2828
    29 #include "ArrayBufferNeuteringWatchpoint.h"
    30 #include "JSArrayBufferView.h"
    31 #include "JSCInlines.h"
    32 #include <wtf/RefPtr.h>
     29#include "Exception.h"
     30#include "JSCJSValue.h"
     31#include "JSGlobalObjectInspectorController.h"
     32#include "JSValueRef.h"
    3333
    34 namespace JSC {
     34enum class ExceptionStatus {
     35    DidThrow,
     36    DidNotThrow
     37};
    3538
    36 bool ArrayBuffer::transfer(ArrayBufferContents& result)
     39inline ExceptionStatus handleExceptionIfNeeded(JSC::ExecState* exec, JSValueRef* returnedExceptionRef)
    3740{
    38     Ref<ArrayBuffer> protect(*this);
    39 
    40     if (!m_contents.m_data) {
    41         result.m_data = 0;
    42         return false;
     41    if (exec->hadException()) {
     42        JSC::Exception* exception = exec->exception();
     43        if (returnedExceptionRef)
     44            *returnedExceptionRef = toRef(exec, exception->value());
     45        exec->clearException();
     46#if ENABLE(REMOTE_INSPECTOR)
     47        exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
     48#endif
     49        return ExceptionStatus::DidThrow;
    4350    }
    44 
    45     bool isNeuterable = !m_pinCount;
    46 
    47     if (!isNeuterable) {
    48         m_contents.copyTo(result);
    49         if (!result.m_data)
    50             return false;
    51         return true;
    52     }
    53 
    54     m_contents.transfer(result);
    55     for (size_t i = numberOfIncomingReferences(); i--;) {
    56         JSCell* cell = incomingReferenceAt(i);
    57         if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(cell))
    58             view->neuter();
    59         else if (ArrayBufferNeuteringWatchpoint* watchpoint = jsDynamicCast<ArrayBufferNeuteringWatchpoint*>(cell))
    60             watchpoint->fireAll();
    61     }
    62     return true;
     51    return ExceptionStatus::DidNotThrow;
    6352}
    6453
    65 } // namespace JSC
     54inline void setException(JSC::ExecState* exec, JSValueRef* returnedExceptionRef, JSC::JSValue exception)
     55{
     56    if (returnedExceptionRef)
     57        *returnedExceptionRef = toRef(exec, exception);
     58#if ENABLE(REMOTE_INSPECTOR)
     59    exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, JSC::Exception::create(exec->vm(), exception));
     60#endif
     61}
    6662
     63#endif /* APIUtils_h */
  • trunk/Source/JavaScriptCore/API/JSBase.h

    r194318 r197983  
    5858typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
    5959
     60/*! @typedef JSTypedArrayBytesDeallocator A function used to deallocate bytes passed to a Typed Array constructor. The function should take two arguments. The first is a pointer to the bytes that were originally passed to the Typed Array constructor. The second is a pointer to additional information desired at the time the bytes are to be freed. */
     61typedef void (*JSTypedArrayBytesDeallocator)(void* bytes, void* deallocatorContext);
    6062
    6163/* JavaScript data types */
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r197648 r197983  
    3030
    3131#include "APICast.h"
     32#include "APIUtils.h"
    3233#include "ButterflyInlines.h"
    3334#include "CodeBlock.h"
     
    6364using namespace JSC;
    6465
    65 enum class ExceptionStatus {
    66     DidThrow,
    67     DidNotThrow
    68 };
    69 
    70 static ExceptionStatus handleExceptionIfNeeded(ExecState* exec, JSValueRef* returnedExceptionRef)
    71 {
    72     if (exec->hadException()) {
    73         Exception* exception = exec->exception();
    74         if (returnedExceptionRef)
    75             *returnedExceptionRef = toRef(exec, exception->value());
    76         exec->clearException();
    77 #if ENABLE(REMOTE_INSPECTOR)
    78         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
    79 #endif
    80         return ExceptionStatus::DidThrow;
    81     }
    82     return ExceptionStatus::DidNotThrow;
    83 }
    84 
    8566JSClassRef JSClassCreate(const JSClassDefinition* definition)
    8667{
  • trunk/Source/JavaScriptCore/API/JSValueRef.cpp

    r186279 r197983  
    11/*
    2  * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929#include "APICast.h"
     30#include "APIUtils.h"
    3031#include "DateInstance.h"
    3132#include "Exception.h"
     
    5455using namespace JSC;
    5556
    56 enum class ExceptionStatus {
    57     DidThrow,
    58     DidNotThrow
    59 };
    60 
    61 static ExceptionStatus handleExceptionIfNeeded(ExecState* exec, JSValueRef* returnedExceptionRef)
    62 {
    63     if (exec->hadException()) {
    64         Exception* exception = exec->exception();
    65         if (returnedExceptionRef)
    66             *returnedExceptionRef = toRef(exec, exception->value());
    67         exec->clearException();
    68 #if ENABLE(REMOTE_INSPECTOR)
    69         exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
    70 #endif
    71         return ExceptionStatus::DidThrow;
    72     }
    73     return ExceptionStatus::DidNotThrow;
    74 }
    75 
    7657#if PLATFORM(MAC)
    7758static bool evernoteHackNeeded()
  • trunk/Source/JavaScriptCore/API/JSValueRef.h

    r182297 r197983  
    5353} JSType;
    5454
     55/*!
     56 @enum JSTypedArrayType
     57 @abstract     A constant identifying the Typed Array type of a JSObjectRef.
     58 @constant     kJSTypedArrayTypeInt8Array            Int8Array
     59 @constant     kJSTypedArrayTypeInt16Array           Int16Array
     60 @constant     kJSTypedArrayTypeInt32Array           Int32Array
     61 @constant     kJSTypedArrayTypeUint8Array           Uint8Array
     62 @constant     kJSTypedArrayTypeUint8ClampedArray    Uint8ClampedArray
     63 @constant     kJSTypedArrayTypeUint16Array          Uint16Array
     64 @constant     kJSTypedArrayTypeUint32Array          Uint32Array
     65 @constant     kJSTypedArrayTypeFloat32Array         Float32Array
     66 @constant     kJSTypedArrayTypeFloat64Array         Float64Array
     67 @constant     kJSTypedArrayTypeArrayBuffer          ArrayBuffer
     68 @constant     kJSTypedArrayTypeNone                 Not a Typed Array
     69
     70 */
     71typedef enum {
     72    kJSTypedArrayTypeInt8Array,
     73    kJSTypedArrayTypeInt16Array,
     74    kJSTypedArrayTypeInt32Array,
     75    kJSTypedArrayTypeUint8Array,
     76    kJSTypedArrayTypeUint8ClampedArray,
     77    kJSTypedArrayTypeUint16Array,
     78    kJSTypedArrayTypeUint32Array,
     79    kJSTypedArrayTypeFloat32Array,
     80    kJSTypedArrayTypeFloat64Array,
     81    kJSTypedArrayTypeArrayBuffer,
     82    kJSTypedArrayTypeNone,
     83} JSTypedArrayType CF_ENUM_AVAILABLE(10_12, 10_0);
     84
    5585#ifdef __cplusplus
    5686extern "C" {
     
    147177*/
    148178JS_EXPORT bool JSValueIsDate(JSContextRef ctx, JSValueRef value) CF_AVAILABLE(10_11, 9_0);
     179
     180/*!
     181@function
     182@abstract           Returns a JavaScript value's Typed Array type.
     183@param ctx          The execution context to use.
     184@param value        The JSValue whose Typed Array type to return.
     185@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.
     186@result             A value of type JSTypedArrayType that identifies value's Typed Array type, or kJSTypedArrayTypeNone if the value is not a Typed Array object.
     187 */
     188JS_EXPORT JSTypedArrayType JSValueGetTypedArrayType(JSContextRef ctx, JSValueRef value, JSValueRef* exception) CF_AVAILABLE(10_12, 10_0);
    149189
    150190/* Comparing values */
  • trunk/Source/JavaScriptCore/API/JavaScript.h

    r165676 r197983  
    3232#include <JavaScriptCore/JSStringRef.h>
    3333#include <JavaScriptCore/JSObjectRef.h>
     34#include <JavaScriptCore/JSTypedArray.h>
    3435#include <JavaScriptCore/JSValueRef.h>
    3536
  • trunk/Source/JavaScriptCore/API/WebKitAvailability.h

    r195184 r197983  
    6868#undef CF_AVAILABLE
    6969#define CF_AVAILABLE(_mac, _ios)
     70#undef CF_ENUM_AVAILABLE
     71#define CF_ENUM_AVAILABLE(_mac, _ios)
    7072#endif
    7173
    7274#else
    7375#define CF_AVAILABLE(_mac, _ios)
     76#define CF_ENUM_AVAILABLE(_mac, _ios)
    7477#endif
    7578
  • trunk/Source/JavaScriptCore/API/tests/testapi.c

    r189454 r197983  
    11/*
    2  * Copyright (C) 2006, 2015 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2006, 2015-2016 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4545#include "GlobalContextWithFinalizerTest.h"
    4646#include "PingPongStackOverflowTest.h"
     47#include "TypedArrayCTest.h"
    4748
    4849#if JSC_OBJC_API_ENABLED
     
    5152
    5253bool assertTrue(bool value, const char* message);
    53 extern void JSSynchronousGarbageCollectForDebugging(JSContextRef);
    5454
    5555static JSGlobalContextRef context;
     
    11141114}
    11151115
    1116 
    11171116int main(int argc, char* argv[])
    11181117{
     
    11381137    testObjectiveCAPI();
    11391138#endif
     1139
     1140
    11401141
    11411142    const char *scriptPath = "testapi.js";
     
    18921893    }
    18931894
     1895    failed = testTypedArrayCAPI() || failed;
    18941896    failed = testExecutionTimeLimit() || failed;
    18951897    failed = testGlobalContextWithFinalizer() || failed;
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r197794 r197983  
    5555    API/JSObjectRef.cpp
    5656    API/JSProfilerPrivate.cpp
     57    API/JSTypedArray.cpp
    5758    API/JSScriptRef.cpp
    5859    API/JSStringRef.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r197970 r197983  
     12016-03-10  Keith Miller  <keith_miller@apple.com>
     2
     3        Typed Arrays have no public facing API
     4        https://bugs.webkit.org/show_bug.cgi?id=120112
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        This patch adds a new C-API (an Obj-C API will follow in the future) for Typed Arrays. The API has two sets of
     9        functions. One for Typed Arrays and another for Array Buffers. This API is intended to reflect the use of Typed
     10        Array objects in JS code. There is a method for each of the core TypedArray and Array Buffer methods.
     11        Originally, we were planning on using a separate non-JS object as the backing store instead of a JS Array Buffer
     12        but we decide to defer that idea since there was no good CF/NS API that met all the constraints we needed
     13        (Discussed further below). We also wanted to want until Shared Array Buffers had reached a more finished state
     14        to see what impact they might have on an API.
     15
     16        The API has the following Typed Array construction methods:
     17        1) Create with length (the backing buffer is zero initialized). -- JSObjectMakeTypedArray
     18        2) Create with an existing pointer and a destructor. -- JSObjectMakeTypedArrayFromBytesNoCopy
     19        3) Create with an Array Buffer object. -- JSObjectMakeTypedArrayFromArrayBuffer
     20        4) Create with an Array Buffer object with a given offset and length. -- JSObjectMakeTypedArrayFromArrayBufferWithOffset
     21
     22        The API has the following functions on Typed Array JSObjectRefs:
     23        5) Get access to a temporary void* of the backing store's data. -- JSObjectGetTypedArrayBytesPtr
     24        6) Get the length of a Typed Array object (returns 0 if it is not a Typed Array object). -- JSObjectGetTypedArrayLength
     25        7) Get the byte length of a Typed Array object (returns 0 if it is not a Typed Array object). -- JSObjectGetTypedArrayByteLength
     26        8) Get the byte offset of a Typed Array object (returns 0 if it is not a Typed Array object). -- JSObjectGetTypedArrayByteOffset
     27        9) Get a Typed Array object's Array Buffer  backing store. -- JSObjectGetTypedArrayBuffer
     28
     29        The API has the following Array Buffer construction method:
     30        10) Create with an existing pointer and a destructor. -- JSObjectMakeArrayBufferWithBytesNoCopy
     31
     32        The API has the following functions on Array Buffer JSObjectRefs:
     33        11) Get access to a temporary void* of the backing store's data. -- JSObjectGetArrayBufferBytesPtr
     34        12) Get the byte length of an Array Buffer object (returns 0 if it is not an Array Buffer object). -- JSObjectGetArrayBufferByteLength
     35
     36        The API adds the following new typedefs and enumerations:
     37        13) A typedef representing the function pointer type used to deallocate byte pointers provided to constructors. -- JSTypedArrayByesDeallocator
     38        14) An enumeration indicating the Typed Array API type of a JSValueRef. -- JSTypedArrayType
     39
     40        Finally, The API has the following function to get Typed Array Types:
     41        15)  Get the Typed Array type of a JS value. -- JSValueGetTypedArrayType
     42
     43        There are a couple of things to note about these functions. Calling JSObjectGetTypedArrayBytesPtr (5) or
     44        JSObjectGetArrayBufferBytesPtr (12) will pin and lock the ArrayBuffer's data for the remaining lifetime of that
     45        ArrayBuffer. This is because, currently, we do not have finalizers for our Array Buffers or Typed Arrays with a
     46        backing ArrayBuffer and adding one would likely incur a non-trivial cost to GC. Also, we do not have a direct
     47        way to make a Typed Array from a pointer with an offset as we do not expect using offsets to be a common use
     48        case of the API.
     49
     50        While it would have been nice to integrate our backing store with CFData or one of its subclasses, it is not
     51        possible to force a CFData/CFMutableData to be both writable and have a fixed size/backing store pointer.
     52        NSData is not writable and CFMutableData can have a fixed pointer if it is allocated with a non-zero capacity
     53        but there is no way for us to force an existing CFMutableData into this state.
     54
     55        * API/APIUtils.h: Copied from Source/JavaScriptCore/runtime/ArrayBuffer.cpp.
     56        (handleExceptionIfNeeded):
     57        (setException):
     58        * API/JSBase.h:
     59        * API/JSObjectRef.cpp:
     60        (handleExceptionIfNeeded): Deleted.
     61        * API/JSTypedArray.cpp: Added.
     62        (toJSTypedArrayType):
     63        (toTypedArrayType):
     64        (createTypedArray):
     65        (JSValueGetTypedArrayType):
     66        (JSObjectMakeTypedArray):
     67        (JSObjectMakeTypedArrayWithBytesNoCopy):
     68        (JSObjectMakeTypedArrayWithArrayBuffer):
     69        (JSObjectMakeTypedArrayWithArrayBufferAndOffset):
     70        (JSObjectGetTypedArrayBytesPtr):
     71        (JSObjectGetTypedArrayLength):
     72        (JSObjectGetTypedArrayByteLength):
     73        (JSObjectGetTypedArrayByteOffset):
     74        (JSObjectGetTypedArrayBuffer):
     75        (JSObjectMakeArrayBufferWithBytesNoCopy):
     76        (JSObjectGetArrayBufferBytesPtr):
     77        (JSObjectGetArrayBufferByteLength):
     78        * API/JSTypedArray.h: Added.
     79        * API/JSValueRef.cpp:
     80        (handleExceptionIfNeeded): Deleted.
     81        * API/JSValueRef.h:
     82        * API/JavaScript.h:
     83        * API/WebKitAvailability.h:
     84        * API/tests/TypedArrayCTest.cpp: Added.
     85        (id):
     86        (freePtr):
     87        (assertEqualsAsNumber):
     88        (testAccess):
     89        (testConstructors):
     90        (forEachTypedArrayType):
     91        (testTypedArrayCAPI):
     92        * API/tests/TypedArrayCTest.h: Added.
     93        * API/tests/testapi.c:
     94        (main):
     95        * CMakeLists.txt:
     96        * ForwardingHeaders/JavaScriptCore/JSTypedArray.h: Added.
     97        * JavaScriptCore.xcodeproj/project.pbxproj:
     98        * PlatformEfl.cmake:
     99        * PlatformGTK.cmake:
     100        * runtime/ArrayBuffer.cpp:
     101        (JSC::ArrayBuffer::transfer):
     102        * runtime/ArrayBuffer.h:
     103        (JSC::arrayBufferDestructorNull):
     104        (JSC::arrayBufferDestructorDefault):
     105        (JSC::ArrayBufferContents::ArrayBufferContents):
     106        (JSC::ArrayBufferContents::transfer):
     107        (JSC::ArrayBuffer::createAdopted):
     108        (JSC::ArrayBuffer::createFromBytes):
     109        (JSC::ArrayBuffer::ArrayBuffer):
     110        (JSC::ArrayBuffer::pinAndLock):
     111        (JSC::ArrayBufferContents::tryAllocate):
     112        (JSC::ArrayBufferContents::~ArrayBufferContents):
     113        * shell/PlatformWin.cmake:
     114
    11152016-03-10  Saam barati  <sbarati@apple.com>
    2116
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r197796 r197983  
    11781178                52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11791179                52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; };
     1180                53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
     1181                53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */; };
     1182                534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */; };
    11801183                534C457C1BC72411007476A7 /* JSTypedArrayViewConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 534C457B1BC72411007476A7 /* JSTypedArrayViewConstructor.h */; };
    11811184                534C457E1BC72549007476A7 /* JSTypedArrayViewConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 534C457D1BC72549007476A7 /* JSTypedArrayViewConstructor.cpp */; };
     1185                53529A4C1C457B75000B49C6 /* APIUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 53529A4B1C457B75000B49C6 /* APIUtils.h */; };
    11821186                5370B4F51BF26202005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5370B4F31BF25EA2005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.cpp */; };
    11831187                5370B4F61BF26205005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 5370B4F41BF25EA2005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.h */; };
     
    33013305                52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
    33023306                52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
     3307                53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = "<group>"; };
     3308                53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = "<group>"; };
     3309                534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayCTest.cpp; path = API/tests/TypedArrayCTest.cpp; sourceTree = "<group>"; };
     3310                534902831C7242C80012BCB8 /* TypedArrayCTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TypedArrayCTest.h; path = API/tests/TypedArrayCTest.h; sourceTree = "<group>"; };
    33033311                534C457A1BC703DC007476A7 /* TypedArrayConstructor.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = TypedArrayConstructor.js; sourceTree = "<group>"; };
    33043312                534C457B1BC72411007476A7 /* JSTypedArrayViewConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArrayViewConstructor.h; sourceTree = "<group>"; };
    33053313                534C457D1BC72549007476A7 /* JSTypedArrayViewConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewConstructor.cpp; sourceTree = "<group>"; };
     3314                53529A4B1C457B75000B49C6 /* APIUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIUtils.h; sourceTree = "<group>"; };
    33063315                5370B4F31BF25EA2005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AdaptiveInferredPropertyValueWatchpointBase.cpp; sourceTree = "<group>"; };
    33073316                5370B4F41BF25EA2005C40FC /* AdaptiveInferredPropertyValueWatchpointBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdaptiveInferredPropertyValueWatchpointBase.h; sourceTree = "<group>"; };
     
    48974906                                FEF040521AAEC4ED00BD28B0 /* CompareAndSwapTest.h */,
    48984907                                C29ECB021804D0ED00D2CBB4 /* CurrentThisInsideBlockGetterTest.h */,
     4908                                534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */,
     4909                                534902831C7242C80012BCB8 /* TypedArrayCTest.h */,
    48994910                                C29ECB011804D0ED00D2CBB4 /* CurrentThisInsideBlockGetterTest.mm */,
    49004911                                C203281E1981979D0088B499 /* CustomGlobalObjectClassTest.c */,
     
    51845195                                C211B574176A224D000E2A23 /* APICallbackFunction.h */,
    51855196                                1482B78A0A4305AB00517CFC /* APICast.h */,
     5197                                53529A4B1C457B75000B49C6 /* APIUtils.h */,
    51865198                                1CAA8B4A0D32C39A0041BCFF /* JavaScript.h */,
    51875199                                1CAA8B4B0D32C39A0041BCFF /* JavaScriptCore.h */,
     
    52325244                                146AAB2A0B66A84900E55F16 /* JSStringRefCF.h */,
    52335245                                1A28D4A7177B71C80007FA3C /* JSStringRefPrivate.h */,
     5246                                53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */,
     5247                                53486BB61C1795C300F6F3AF /* JSTypedArray.h */,
    52345248                                86E3C606167BAB87006D760A /* JSValue.h */,
    52355249                                86E3C60D167BAB87006D760A /* JSValue.mm */,
     
    71117125                                0F5A52D017ADD717008ECB2D /* CopyToken.h in Headers */,
    71127126                                C2239D1816262BDD005AC5FD /* CopyVisitor.h in Headers */,
     7127                                53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */,
    71137128                                C2239D1916262BDD005AC5FD /* CopyVisitorInlines.h in Headers */,
    71147129                                C218D1401655CFD50062BB81 /* CopyWorkList.h in Headers */,
     
    71847199                                0F04396E1B03DC0B009598B7 /* DFGCombinedLiveness.h in Headers */,
    71857200                                0F7B294D14C3CD4C007C3DB1 /* DFGCommon.h in Headers */,
     7201                                53529A4C1C457B75000B49C6 /* APIUtils.h in Headers */,
    71867202                                0FEA0A32170D40BF00BB722C /* DFGCommonData.h in Headers */,
    71877203                                0F725CB01C506D3B00AD943A /* B3FoldPathConstants.h in Headers */,
     
    85598575                                65570F5A1AA4C3EA009B3C23 /* Regress141275.mm in Sources */,
    85608576                                FEB51F6C1A97B688001F921C /* Regress141809.mm in Sources */,
     8577                                534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */,
    85618578                                1440F6100A4F85670005F061 /* testapi.c in Sources */,
    85628579                                86D2221A167EF9440024C804 /* testapi.mm in Sources */,
     
    85898606                                0FEC85781BDACDC70080FF74 /* AirGenerate.cpp in Sources */,
    85908607                                0FEC85931BDB1E100080FF74 /* AirGenerated.cpp in Sources */,
     8608                                53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */,
    85918609                                0FEC857B1BDACDC70080FF74 /* AirHandleCalleeSaves.cpp in Sources */,
    85928610                                0FEC857D1BDACDC70080FF74 /* AirInsertionSet.cpp in Sources */,
  • trunk/Source/JavaScriptCore/PlatformEfl.cmake

    r191165 r197983  
    1616              API/JSStringRef.h
    1717              API/JSValueRef.h
     18              API/JSTypedArray.h
    1819              API/WebKitAvailability.h
    1920        DESTINATION "${HEADER_INSTALL_DIR}/JavaScriptCore"
  • trunk/Source/JavaScriptCore/PlatformGTK.cmake

    r196796 r197983  
    2525              API/JSObjectRef.h
    2626              API/JSStringRef.h
     27              API/JSTypedArray.h
    2728              API/JSValueRef.h
    2829              API/WebKitAvailability.h
  • trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp

    r195360 r197983  
    4343    }
    4444
    45     bool isNeuterable = !m_pinCount;
     45    bool isNeuterable = !m_pinCount && !m_locked;
    4646
    4747    if (!isNeuterable) {
  • trunk/Source/JavaScriptCore/runtime/ArrayBuffer.h

    r163444 r197983  
    11/*
    2  * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2013, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#include "GCIncomingRefCounted.h"
    3030#include "Weak.h"
     31#include <functional>
    3132#include <wtf/PassRefPtr.h>
    3233#include <wtf/StdLibExtras.h>
     
    3839class ArrayBufferView;
    3940class JSArrayBuffer;
     41
     42typedef std::function<void(void*)> ArrayBufferDestructorFunction;
     43static void arrayBufferDestructorNull(void*) { }
     44static void arrayBufferDestructorDefault(void* p) { fastFree(p); }
    4045
    4146class ArrayBufferContents {
     
    4348public:
    4449    ArrayBufferContents()
    45         : m_data(0)
     50        : m_destructor(arrayBufferDestructorNull)
     51        , m_data(nullptr)
    4652        , m_sizeInBytes(0)
    4753    { }
     
    5359
    5460private:
    55     ArrayBufferContents(void* data, unsigned sizeInBytes)
     61    ArrayBufferContents(void* data, unsigned sizeInBytes, ArrayBufferDestructorFunction&& destructor)
    5662        : m_data(data)
    5763        , m_sizeInBytes(sizeInBytes)
    58     { }
     64    {
     65        m_destructor = WTFMove(destructor);
     66    }
    5967
    6068    friend class ArrayBuffer;
     
    6977    {
    7078        ASSERT(!other.m_data);
    71         other.m_data = m_data;
    72         other.m_sizeInBytes = m_sizeInBytes;
    73         m_data = 0;
    74         m_sizeInBytes = 0;
     79        std::swap(m_data, other.m_data);
     80        std::swap(m_sizeInBytes, other.m_sizeInBytes);
     81        std::swap(m_destructor, other.m_destructor);
    7582    }
    7683
     
    8592    }
    8693
     94    ArrayBufferDestructorFunction m_destructor;
    8795    void* m_data;
    8896    unsigned m_sizeInBytes;
     
    96104    static inline PassRefPtr<ArrayBuffer> create(ArrayBufferContents&);
    97105    static inline PassRefPtr<ArrayBuffer> createAdopted(const void* data, unsigned byteLength);
     106    static inline PassRefPtr<ArrayBuffer> createFromBytes(const void* data, unsigned byteLength, ArrayBufferDestructorFunction&&);
    98107
    99108    // Only for use by Uint8ClampedArray::createUninitialized and SharedBuffer::createArrayBuffer.
     
    111120    inline void pin();
    112121    inline void unpin();
     122    inline void pinAndLock();
    113123
    114124    JS_EXPORT_PRIVATE bool transfer(ArrayBufferContents&);
     
    127137    static inline int clampValue(int x, int left, int right);
    128138
    129     unsigned m_pinCount;
    130139    ArrayBufferContents m_contents;
     140    unsigned m_pinCount : 31;
     141    bool m_locked : 1; // m_locked == true means that some API user fetched m_contents directly from a TypedArray object.
    131142
    132143public:
     
    173184PassRefPtr<ArrayBuffer> ArrayBuffer::createAdopted(const void* data, unsigned byteLength)
    174185{
    175     ArrayBufferContents contents(const_cast<void*>(data), byteLength);
     186    return createFromBytes(data, byteLength, WTFMove(arrayBufferDestructorDefault));
     187}
     188
     189PassRefPtr<ArrayBuffer> ArrayBuffer::createFromBytes(const void* data, unsigned byteLength, ArrayBufferDestructorFunction&& destructor)
     190{
     191    ArrayBufferContents contents(const_cast<void*>(data), byteLength, WTFMove(destructor));
    176192    return create(contents);
    177193}
     
    193209ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents)
    194210    : m_pinCount(0)
     211    , m_locked(false)
    195212{
    196213    contents.transfer(m_contents);
     
    249266{
    250267    m_pinCount--;
     268}
     269
     270void ArrayBuffer::pinAndLock()
     271{
     272    m_locked = true;
    251273}
    252274
     
    272294    if (allocationSucceeded) {
    273295        result.m_sizeInBytes = numElements * elementByteSize;
     296        result.m_destructor = arrayBufferDestructorDefault;
    274297        return;
    275298    }
     
    279302ArrayBufferContents::~ArrayBufferContents()
    280303{
    281     WTF::fastFree(m_data);
     304    m_destructor(m_data);
    282305}
    283306
  • trunk/Source/JavaScriptCore/shell/PlatformWin.cmake

    r194705 r197983  
    3535    ../API/tests/PingPongStackOverflowTest.cpp
    3636    ../API/tests/testapi.c
     37   ../API/tests/TypedArrayCTest.cpp
    3738)
    3839set_source_files_properties(../API/tests/CustomGlobalObjectClassTest.c PROPERTIES COMPILE_FLAGS "/TP /MT")
Note: See TracChangeset for help on using the changeset viewer.