WebKit Bugzilla
Attachment 368836 Details for
Bug 197535
: [GLib] Expose typed arrays in the public API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP Patch v1
bug-197535-20190503020506.patch (text/plain), 7.54 KB, created by
Adrian Perez
on 2019-05-02 16:05:07 PDT
(
hide
)
Description:
WIP Patch v1
Filename:
MIME Type:
Creator:
Adrian Perez
Created:
2019-05-02 16:05:07 PDT
Size:
7.54 KB
patch
obsolete
>Subversion Revision: 244877 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 2d4298f08d20dd98f883dbbfe618fde93d256207..f91b4e725490f72cf98850da425c39e0ebfc5318 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,21 @@ >+2019-05-02 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GLib] Expose typed arrays in the API >+ https://bugs.webkit.org/show_bug.cgi?id=197535 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ wip >+ >+ * API/glib/JSCValue.cpp: >+ (jscTypedArrayTypeToJSType): >+ (jsc_value_typed_array_new): >+ (jsc_value_typed_array_new_from_data): >+ (jsc_value_is_typed_array): >+ (jsc_value_typed_array_get_length): >+ (jsc_value_typed_array_get_contents): >+ * API/glib/JSCValue.h: >+ > 2019-05-02 Michael Saboff <msaboff@apple.com> > > Unreviewed rollout of r244862. >diff --git a/Source/JavaScriptCore/API/glib/JSCValue.cpp b/Source/JavaScriptCore/API/glib/JSCValue.cpp >index 76b892fea30fdfc0d8e29144db28bf66afe375d2..f23ff23355c7e4e7d29415c8848d51061651aeb2 100644 >--- a/Source/JavaScriptCore/API/glib/JSCValue.cpp >+++ b/Source/JavaScriptCore/API/glib/JSCValue.cpp >@@ -28,6 +28,7 @@ > #include "JSCInlines.h" > #include "JSCValuePrivate.h" > #include "JSRetainPtr.h" >+#include "JSTypedArray.h" > #include "OpaqueJSString.h" > #include <gobject/gvaluecollector.h> > #include <wtf/glib/GRefPtr.h> >@@ -1441,3 +1442,102 @@ JSCValue* jsc_value_constructor_callv(JSCValue* value, unsigned parametersCount, > > return jscContextGetOrCreateValue(priv->context.get(), result).leakRef(); > } >+ >+static inline JSTypedArrayType jscTypedArrayTypeToJSType(JSCTypedArrayType type) >+{ >+ switch (type) { >+ case JSC_TYPED_ARRAY_INT8: return kJSTypedArrayTypeInt8Array; >+ case JSC_TYPED_ARRAY_INT16: return kJSTypedArrayTypeInt16Array; >+ case JSC_TYPED_ARRAY_INT32: return kJSTypedArrayTypeInt32Array; >+ case JSC_TYPED_ARRAY_UINT8: return kJSTypedArrayTypeUint8Array; >+ case JSC_TYPED_ARRAY_UINT16: return kJSTypedArrayTypeUint16Array; >+ case JSC_TYPED_ARRAY_UINT32: return kJSTypedArrayTypeUint32Array; >+ case JSC_TYPED_ARRAY_FLOAT32: return kJSTypedArrayTypeFloat32Array; >+ case JSC_TYPED_ARRAY_FLOAT64: return kJSTypedArrayTypeFloat64Array; >+ default: ASSERT_NOT_REACHED(); >+ } >+ return kJSTypedArrayTypeNone; >+} >+ >+JSCValue* jsc_value_typed_array_new(JSCContext* context, JSCTypedArrayType type, size_t len) >+{ >+ g_return_val_if_fail(JSC_IS_CONTEXT(context), nullptr); >+ >+ JSValueRef exception = nullptr; >+ auto* jsContext = jscContextGetJSContext(context); >+ auto* jsTypedArray = JSObjectMakeTypedArray(jsContext, jscTypedArrayTypeToJSType(type), len, &exception); >+ if (jscContextHandleExceptionIfNeeded(context, exception)) >+ return nullptr; >+ >+ return jscContextGetOrCreateValue(context, jsTypedArray).leakRef(); >+} >+ >+JSCValue* jsc_value_typed_array_new_from_data(JSCContext* context, JSCTypedArrayType type, gpointer data, gsize dataBytes, GDestroyNotify destroyNotify) >+{ >+ g_return_val_if_fail(JSC_IS_CONTEXT(context), nullptr); >+ >+ JSValueRef exception = nullptr; >+ auto* jsContext = jscContextGetJSContext(context); >+ auto* jsTypedArray = JSObjectMakeTypedArrayWithBytesNoCopy(jsContext, jscTypedArrayTypeToJSType(type), data, dataBytes, [](void* bytes, void* context) { reinterpret_cast<GDestroyNotify>(context)(bytes); }, reinterpret_cast<void*>(destroyNotify), &exception); >+ if (jscContextHandleExceptionIfNeeded(context, exception)) >+ return nullptr; >+ >+ return jscContextGetOrCreateValue(context, jsTypedArray).leakRef(); >+} >+ >+gboolean jsc_value_is_typed_array(JSCValue* value) >+{ >+ g_return_val_if_fail(JSC_IS_VALUE(value), FALSE); >+ >+ auto* jsContext = jscContextGetJSContext(value->priv->context.get()); >+ >+ JSValueRef exception = nullptr; >+ auto jsTypedArrayType = JSValueGetTypedArrayType(jsContext, value->priv->jsValue, &exception); >+ if (jscContextHandleExceptionIfNeeded(value->priv->context.get(), exception)) >+ return FALSE; >+ >+ return jsTypedArrayType != kJSTypedArrayTypeNone && jsTypedArrayType != kJSTypedArrayTypeArrayBuffer; >+} >+ >+gsize jsc_value_typed_array_get_length(JSCValue* value) >+{ >+ g_return_val_if_fail(JSC_IS_VALUE(value), 0); >+ >+ auto* jsContext = jscContextGetJSContext(value->priv->context.get()); >+ >+ JSValueRef exception = nullptr; >+ auto* jsObject = JSValueToObject(jsContext, value->priv->jsValue, &exception); >+ if (jscContextHandleExceptionIfNeeded(value->priv->context.get(), exception)) >+ return 0; >+ >+ size_t len = JSObjectGetTypedArrayLength(jsContext, jsObject, &exception); >+ if (jscContextHandleExceptionIfNeeded(value->priv->context.get(), exception)) >+ return 0; >+ >+ return len; >+} >+ >+char* jsc_value_typed_array_get_contents(JSCValue* value, gsize* len) >+{ >+ g_return_val_if_fail(JSC_IS_VALUE(value), nullptr); >+ >+ auto* jsContext = jscContextGetJSContext(value->priv->context.get()); >+ >+ JSValueRef exception = nullptr; >+ auto* jsObject = JSValueToObject(jsContext, value->priv->jsValue, &exception); >+ if (jscContextHandleExceptionIfNeeded(value->priv->context.get(), exception)) >+ return nullptr; >+ >+ auto* ptr = JSObjectGetTypedArrayBytesPtr(jsContext, jsObject, &exception); >+ if (jscContextHandleExceptionIfNeeded(value->priv->context.get(), exception)) >+ return nullptr; >+ >+ if (len) { >+ auto byteLength = JSObjectGetTypedArrayByteLength(jsContext, jsObject, &exception); >+ if (jscContextHandleExceptionIfNeeded(value->priv->context.get(), exception)) >+ return nullptr; >+ *len = byteLength; >+ } >+ >+ return static_cast<char*>(ptr); >+} >diff --git a/Source/JavaScriptCore/API/glib/JSCValue.h b/Source/JavaScriptCore/API/glib/JSCValue.h >index fae6267a6ee46960124b8c398be7c4fe803c9ba4..653cc76fcdc5130372784024adbb1dab8e67680a 100644 >--- a/Source/JavaScriptCore/API/glib/JSCValue.h >+++ b/Source/JavaScriptCore/API/glib/JSCValue.h >@@ -260,6 +260,43 @@ jsc_value_constructor_callv (JSCValue *value, > guint n_parameters, > JSCValue **parameters); > >+typedef enum { >+ JSC_TYPED_ARRAY_INT8, >+ JSC_TYPED_ARRAY_INT16, >+ JSC_TYPED_ARRAY_INT32, >+ JSC_TYPED_ARRAY_UINT8, >+ JSC_TYPED_ARRAY_UINT16, >+ JSC_TYPED_ARRAY_UINT32, >+ JSC_TYPED_ARRAY_FLOAT32, >+ JSC_TYPED_ARRAY_FLOAT64, >+} JSCTypedArrayType; >+ >+JSC_API JSCValue * >+jsc_value_typed_array_new (JSCContext *context, >+ JSCTypedArrayType type, >+ gsize len); >+ >+JSC_API JSCValue * >+jsc_value_typed_array_new_from_data (JSCContext *context, >+ JSCTypedArrayType type, >+ gpointer *data, >+ gsize data_bytes, >+ GDestroyNotify destroy_notify); >+ >+JSC_API gboolean >+jsc_value_is_typed_array (JSCValue *value); >+ >+JSC_API JSCTypedArrayType >+jsc_value_typed_array_get_type (JSCValue *value); >+ >+JSC_API gsize >+jsc_value_typed_array_get_length (JSCValue *value); >+ >+JSC_API char * >+jsc_value_typed_array_get_contents (JSCValue *value, >+ gsize *len); >+ >+ > G_END_DECLS > > #endif /* JSCValue_h */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197535
:
368836
|
368852
|
369379
|
369480
|
454040
|
454112
|
454538
|
454578