Skip to content

Commit

Permalink
Renamed Typed Array functions as suggested in https://bugs.webkit.org…
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Oct 13, 2015
1 parent 5570d06 commit ac4a764
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
26 changes: 12 additions & 14 deletions JavaScriptCore/API/JSTypedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "JSTypedArray.h"

#include <wtf/RefPtr.h>

#include "JSObjectRef.h"
#include "APICast.h"
#include "InitializeThreading.h"
Expand Down Expand Up @@ -76,23 +78,22 @@ const CreateTypedArrayFuncPtr CreateTypedArrayFunc[] = {



JSTypedArrayType JSTypedArrayGetType(JSContextRef ctx, JSValueRef value) {
JSTypedArrayType JSObjectGetTypedArrayType(JSContextRef ctx, JSObjectRef object) {
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);

JSValue jsValue = toJS(exec, value);
JSObject* jsObject = toJS(object);
JSTypedArrayType type = kJSTypedArrayTypeNone;
if( jsValue.inherits(JSArrayBufferView::info()) ) {
JSObject* object = jsValue.getObject();
type = TypedArrayTypes[object->classInfo()->typedArrayStorageType];
if( jsObject->inherits(JSArrayBufferView::info()) ) {
type = TypedArrayTypes[jsObject->classInfo()->typedArrayStorageType];
}
else if( jsValue.inherits(JSArrayBuffer::info()) ) {
else if( jsObject->inherits(JSArrayBuffer::info()) ) {
type = kJSTypedArrayTypeArrayBuffer;
}
return type;
}

JSObjectRef JSTypedArrayMake(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements) {
JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements) {
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);

Expand All @@ -104,18 +105,18 @@ JSObjectRef JSTypedArrayMake(JSContextRef ctx, JSTypedArrayType arrayType, size_
return toRef(result);
}

void * JSTypedArrayGetDataPtr(JSContextRef ctx, JSValueRef value, size_t * byteLength) {
void* JSObjectGetTypedArrayDataPtr(JSContextRef ctx, JSObjectRef object, size_t* byteLength) {
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);

JSValue jsValue = toJS(exec, value);
if( JSArrayBufferView * view = jsDynamicCast<JSArrayBufferView*>(jsValue) ) {
JSObject* jsObject = toJS(object);
if( JSArrayBufferView * view = jsDynamicCast<JSArrayBufferView*>(jsObject) ) {
if( byteLength ) {
*byteLength = view->impl()->byteLength();
}
return view->impl()->baseAddress();
}
else if( ArrayBuffer * buffer = toArrayBuffer(jsValue) ) {
else if( ArrayBuffer* buffer = toArrayBuffer(jsObject) ) {
if( byteLength ) {
*byteLength = buffer->byteLength();
}
Expand All @@ -127,6 +128,3 @@ void * JSTypedArrayGetDataPtr(JSContextRef ctx, JSValueRef value, size_t * byteL
}
return NULL;
}



8 changes: 4 additions & 4 deletions JavaScriptCore/API/JSTypedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef enum {
@param value The JSValue whose Typed Array type you want to obtain.
@result A value of type JSTypedArrayType that identifies value's Typed Array type.
*/
JS_EXPORT JSTypedArrayType JSTypedArrayGetType(JSContextRef ctx, JSValueRef value);
JS_EXPORT JSTypedArrayType JSObjectGetTypedArrayType(JSContextRef ctx, JSObjectRef object);

/*!
@function
Expand All @@ -53,17 +53,17 @@ JS_EXPORT JSTypedArrayType JSTypedArrayGetType(JSContextRef ctx, JSValueRef valu
@param numElements The number of elements for the array.
@result A JSObjectRef that is a Typed Array or NULL if there was an error
*/
JS_EXPORT JSObjectRef JSTypedArrayMake(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements);
JS_EXPORT JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements);

/*!
@function
@abstract Returns a pointer to a Typed Array's data in memory
@param ctx The execution context to use.
@param value The JSValue whose Typed Array type data pointer you want to obtain.
@param byteLength A pointer to a size_t in which to store the byte length of the Typed Array
@result A pointer to the Typed Array's data or NULL if the JSValue is not a Typed Array
@result A pointer to the Typed Array's data or NULL if the JSValue is not a Typed Array.
*/
JS_EXPORT void * JSTypedArrayGetDataPtr(JSContextRef ctx, JSValueRef value, size_t * byteLength);
JS_EXPORT void * JSObjectGetTypedArrayDataPtr(JSContextRef ctx, JSObjectRef object, size_t* byteLength);


#ifdef __cplusplus
Expand Down

0 comments on commit ac4a764

Please sign in to comment.