mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
Issue #1442 - Part 5: Implement WebIDL bindings for Streams. https://bugzilla.mozilla.org/show_bug.cgi?id=1128959
This commit is contained in:
parent
9b9075eef6
commit
0701dccaca
14 changed files with 255 additions and 157 deletions
|
|
@ -1156,6 +1156,9 @@ class CGHeaders(CGWrapper):
|
||||||
# just include their header if we need to have functions
|
# just include their header if we need to have functions
|
||||||
# taking references to them declared in that header.
|
# taking references to them declared in that header.
|
||||||
headerSet = declareIncludes
|
headerSet = declareIncludes
|
||||||
|
if unrolled.isReadableStream():
|
||||||
|
headerSet.add("mozilla/dom/ReadableStream.h")
|
||||||
|
else:
|
||||||
headerSet.add("mozilla/dom/TypedArray.h")
|
headerSet.add("mozilla/dom/TypedArray.h")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
@ -1371,6 +1374,9 @@ def UnionTypes(unionTypes, config):
|
||||||
elif f.isInterface():
|
elif f.isInterface():
|
||||||
if f.isSpiderMonkeyInterface():
|
if f.isSpiderMonkeyInterface():
|
||||||
headers.add("jsfriendapi.h")
|
headers.add("jsfriendapi.h")
|
||||||
|
if f.isReadableStream():
|
||||||
|
headers.add("mozilla/dom/ReadableStream.h")
|
||||||
|
else:
|
||||||
headers.add("mozilla/dom/TypedArray.h")
|
headers.add("mozilla/dom/TypedArray.h")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
@ -1457,6 +1463,9 @@ def UnionConversions(unionTypes, config):
|
||||||
elif f.isInterface():
|
elif f.isInterface():
|
||||||
if f.isSpiderMonkeyInterface():
|
if f.isSpiderMonkeyInterface():
|
||||||
headers.add("jsfriendapi.h")
|
headers.add("jsfriendapi.h")
|
||||||
|
if f.isReadableStream():
|
||||||
|
headers.add("mozilla/dom/ReadableStream.h")
|
||||||
|
else:
|
||||||
headers.add("mozilla/dom/TypedArray.h")
|
headers.add("mozilla/dom/TypedArray.h")
|
||||||
elif f.inner.isExternal():
|
elif f.inner.isExternal():
|
||||||
try:
|
try:
|
||||||
|
|
@ -5582,8 +5591,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
if type.isSpiderMonkeyInterface():
|
if type.isSpiderMonkeyInterface():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
name = type.unroll().name # unroll() because it may be nullable
|
name = type.unroll().name # unroll() because it may be nullable
|
||||||
arrayType = CGGeneric(name)
|
interfaceType = CGGeneric(name)
|
||||||
declType = arrayType
|
declType = interfaceType
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
declType = CGTemplatedType("Nullable", declType)
|
declType = CGTemplatedType("Nullable", declType)
|
||||||
objRef = "${declName}.SetValue()"
|
objRef = "${declName}.SetValue()"
|
||||||
|
|
@ -5607,10 +5616,11 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
# This is a bit annoying. In a union we don't want to have a
|
# This is a bit annoying. In a union we don't want to have a
|
||||||
# holder, since unions don't support that. But if we're optional we
|
# holder, since unions don't support that. But if we're optional we
|
||||||
# want to have a holder, so that the callee doesn't see
|
# want to have a holder, so that the callee doesn't see
|
||||||
# Optional<RootedTypedArray<ArrayType> >. So do a holder if we're
|
# Optional<RootedSpiderMonkeyInterface<InterfaceType>>. So do a
|
||||||
# optional and use a RootedTypedArray otherwise.
|
# holder if we're optional and use a RootedSpiderMonkeyInterface
|
||||||
|
# otherwise.
|
||||||
if isOptional:
|
if isOptional:
|
||||||
holderType = CGTemplatedType("TypedArrayRooter", arrayType)
|
holderType = CGTemplatedType("SpiderMonkeyInterfaceRooter", interfaceType)
|
||||||
# If our typed array is nullable, this will set the Nullable to
|
# If our typed array is nullable, this will set the Nullable to
|
||||||
# be not-null, but that's ok because we make an explicit
|
# be not-null, but that's ok because we make an explicit
|
||||||
# SetNull() call on it as needed if our JS value is actually
|
# SetNull() call on it as needed if our JS value is actually
|
||||||
|
|
@ -5622,7 +5632,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
else:
|
else:
|
||||||
holderType = None
|
holderType = None
|
||||||
holderArgs = None
|
holderArgs = None
|
||||||
declType = CGTemplatedType("RootedTypedArray", declType)
|
declType = CGTemplatedType("RootedSpiderMonkeyInterface", declType)
|
||||||
declArgs = "cx"
|
declArgs = "cx"
|
||||||
else:
|
else:
|
||||||
holderType = None
|
holderType = None
|
||||||
|
|
@ -6371,7 +6381,7 @@ def getMaybeWrapValueFuncForType(type):
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
return "MaybeWrapObjectOrNullValue"
|
return "MaybeWrapObjectOrNullValue"
|
||||||
return "MaybeWrapObjectValue"
|
return "MaybeWrapObjectValue"
|
||||||
# Spidermonkey interfaces are never DOM objects. Neither are sequences or
|
# SpiderMonkey interfaces are never DOM objects. Neither are sequences or
|
||||||
# dictionaries, since those are always plain JS objects.
|
# dictionaries, since those are always plain JS objects.
|
||||||
if type.isSpiderMonkeyInterface() or type.isDictionary() or type.isSequence():
|
if type.isSpiderMonkeyInterface() or type.isDictionary() or type.isSequence():
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
|
|
@ -13679,7 +13689,7 @@ class ForwardDeclarationBuilder:
|
||||||
except NoSuchDescriptorError:
|
except NoSuchDescriptorError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Note: Spidermonkey interfaces are typedefs, so can't be
|
# Note: SpiderMonkey interfaces are typedefs, so can't be
|
||||||
# forward-declared
|
# forward-declared
|
||||||
elif t.isPromise():
|
elif t.isPromise():
|
||||||
self.addInMozillaDom("Promise")
|
self.addInMozillaDom("Promise")
|
||||||
|
|
|
||||||
28
dom/bindings/ReadableStream.h
Normal file
28
dom/bindings/ReadableStream.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef mozilla_dom_ReadableStream_h
|
||||||
|
#define mozilla_dom_ReadableStream_h
|
||||||
|
|
||||||
|
#include "mozilla/dom/SpiderMonkeyInterface.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
struct ReadableStream : public SpiderMonkeyInterfaceObjectStorage
|
||||||
|
{
|
||||||
|
inline bool Init(JSObject* obj)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!inited());
|
||||||
|
mImplObj = mWrappedObj = js::UnwrapReadableStream(obj);
|
||||||
|
return inited();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif /* mozilla_dom_ReadableStream_h */
|
||||||
144
dom/bindings/SpiderMonkeyInterface.h
Normal file
144
dom/bindings/SpiderMonkeyInterface.h
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef mozilla_dom_SpiderMonkeyInterface_h
|
||||||
|
#define mozilla_dom_SpiderMonkeyInterface_h
|
||||||
|
|
||||||
|
#include "jsapi.h"
|
||||||
|
#include "jsfriendapi.h"
|
||||||
|
#include "js/TracingAPI.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class that just handles the JSObject storage and tracing for spidermonkey
|
||||||
|
* interfaces
|
||||||
|
*/
|
||||||
|
struct SpiderMonkeyInterfaceObjectStorage
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
JSObject* mImplObj;
|
||||||
|
JSObject* mWrappedObj;
|
||||||
|
|
||||||
|
SpiderMonkeyInterfaceObjectStorage()
|
||||||
|
: mImplObj(nullptr),
|
||||||
|
mWrappedObj(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiderMonkeyInterfaceObjectStorage(SpiderMonkeyInterfaceObjectStorage&& aOther)
|
||||||
|
: mImplObj(aOther.mImplObj),
|
||||||
|
mWrappedObj(aOther.mWrappedObj)
|
||||||
|
{
|
||||||
|
aOther.mImplObj = nullptr;
|
||||||
|
aOther.mWrappedObj = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline void TraceSelf(JSTracer* trc)
|
||||||
|
{
|
||||||
|
JS::UnsafeTraceRoot(trc, &mImplObj, "SpiderMonkeyInterfaceObjectStorage.mImplObj");
|
||||||
|
JS::UnsafeTraceRoot(trc, &mWrappedObj, "SpiderMonkeyInterfaceObjectStorage.mWrappedObj");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool inited() const
|
||||||
|
{
|
||||||
|
return !!mImplObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool WrapIntoNewCompartment(JSContext* cx)
|
||||||
|
{
|
||||||
|
return JS_WrapObject(cx,
|
||||||
|
JS::MutableHandle<JSObject*>::fromMarkedLocation(&mWrappedObj));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline JSObject *Obj() const
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(inited());
|
||||||
|
return mWrappedObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SpiderMonkeyInterfaceObjectStorage(const SpiderMonkeyInterfaceObjectStorage&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
// A class for rooting an existing SpiderMonkey Interface struct
|
||||||
|
template<typename InterfaceType>
|
||||||
|
class MOZ_RAII SpiderMonkeyInterfaceRooter : private JS::CustomAutoRooter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename CX>
|
||||||
|
SpiderMonkeyInterfaceRooter(const CX& cx,
|
||||||
|
InterfaceType* aInterface MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||||
|
: JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT),
|
||||||
|
mInterface(aInterface)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void trace(JSTracer* trc) override
|
||||||
|
{
|
||||||
|
mInterface->TraceSelf(trc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SpiderMonkeyInterfaceObjectStorage* const mInterface;
|
||||||
|
};
|
||||||
|
|
||||||
|
// And a specialization for dealing with nullable SpiderMonkey interfaces
|
||||||
|
template<typename Inner> struct Nullable;
|
||||||
|
template<typename InterfaceType>
|
||||||
|
class MOZ_RAII SpiderMonkeyInterfaceRooter<Nullable<InterfaceType>> :
|
||||||
|
private JS::CustomAutoRooter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename CX>
|
||||||
|
SpiderMonkeyInterfaceRooter(const CX& cx,
|
||||||
|
Nullable<InterfaceType>* aInterface MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||||
|
: JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT),
|
||||||
|
mInterface(aInterface)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void trace(JSTracer* trc) override
|
||||||
|
{
|
||||||
|
if (!mInterface->IsNull()) {
|
||||||
|
mInterface->Value().TraceSelf(trc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Nullable<InterfaceType>* const mInterface;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Class for easily setting up a rooted SpiderMonkey interface object on the
|
||||||
|
// stack
|
||||||
|
template<typename InterfaceType>
|
||||||
|
class MOZ_RAII RootedSpiderMonkeyInterface final : public InterfaceType,
|
||||||
|
private SpiderMonkeyInterfaceRooter<InterfaceType>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename CX>
|
||||||
|
explicit RootedSpiderMonkeyInterface(const CX& cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||||
|
: InterfaceType(),
|
||||||
|
SpiderMonkeyInterfaceRooter<InterfaceType>(cx, this
|
||||||
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename CX>
|
||||||
|
RootedSpiderMonkeyInterface(const CX& cx, JSObject* obj MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||||
|
: InterfaceType(obj),
|
||||||
|
SpiderMonkeyInterfaceRooter<InterfaceType>(cx, this
|
||||||
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif /* mozilla_dom_SpiderMonkeyInterface_h */
|
||||||
|
|
@ -6,51 +6,15 @@
|
||||||
#ifndef mozilla_dom_TypedArray_h
|
#ifndef mozilla_dom_TypedArray_h
|
||||||
#define mozilla_dom_TypedArray_h
|
#define mozilla_dom_TypedArray_h
|
||||||
|
|
||||||
#include "jsapi.h"
|
|
||||||
#include "jsfriendapi.h"
|
|
||||||
#include "js/RootingAPI.h"
|
|
||||||
#include "js/TracingAPI.h"
|
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/Move.h"
|
#include "mozilla/Move.h"
|
||||||
#include "mozilla/dom/BindingDeclarations.h"
|
#include "mozilla/dom/BindingDeclarations.h"
|
||||||
|
#include "mozilla/dom/SpiderMonkeyInterface.h"
|
||||||
#include "nsWrapperCache.h"
|
#include "nsWrapperCache.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
/*
|
|
||||||
* Class that just handles the JSObject storage and tracing for typed arrays
|
|
||||||
*/
|
|
||||||
struct TypedArrayObjectStorage : AllTypedArraysBase {
|
|
||||||
protected:
|
|
||||||
JSObject* mTypedObj;
|
|
||||||
JSObject* mWrappedObj;
|
|
||||||
|
|
||||||
TypedArrayObjectStorage()
|
|
||||||
: mTypedObj(nullptr),
|
|
||||||
mWrappedObj(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TypedArrayObjectStorage(TypedArrayObjectStorage&& aOther)
|
|
||||||
: mTypedObj(aOther.mTypedObj),
|
|
||||||
mWrappedObj(aOther.mWrappedObj)
|
|
||||||
{
|
|
||||||
aOther.mTypedObj = nullptr;
|
|
||||||
aOther.mWrappedObj = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline void TraceSelf(JSTracer* trc)
|
|
||||||
{
|
|
||||||
JS::UnsafeTraceRoot(trc, &mTypedObj, "TypedArray.mTypedObj");
|
|
||||||
JS::UnsafeTraceRoot(trc, &mWrappedObj, "TypedArray.mWrappedObj");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
TypedArrayObjectStorage(const TypedArrayObjectStorage&) = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Various typed array classes for argument conversion. We have a base class
|
* Various typed array classes for argument conversion. We have a base class
|
||||||
* that has a way of initializing a TypedArray from an existing typed array, and
|
* that has a way of initializing a TypedArray from an existing typed array, and
|
||||||
|
|
@ -60,7 +24,9 @@ private:
|
||||||
template<typename T,
|
template<typename T,
|
||||||
JSObject* UnwrapArray(JSObject*),
|
JSObject* UnwrapArray(JSObject*),
|
||||||
void GetLengthAndDataAndSharedness(JSObject*, uint32_t*, bool*, T**)>
|
void GetLengthAndDataAndSharedness(JSObject*, uint32_t*, bool*, T**)>
|
||||||
struct TypedArray_base : public TypedArrayObjectStorage {
|
struct TypedArray_base : public SpiderMonkeyInterfaceObjectStorage,
|
||||||
|
AllTypedArraysBase
|
||||||
|
{
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
|
||||||
TypedArray_base()
|
TypedArray_base()
|
||||||
|
|
@ -72,7 +38,7 @@ struct TypedArray_base : public TypedArrayObjectStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedArray_base(TypedArray_base&& aOther)
|
TypedArray_base(TypedArray_base&& aOther)
|
||||||
: TypedArrayObjectStorage(Move(aOther)),
|
: SpiderMonkeyInterfaceObjectStorage(Move(aOther)),
|
||||||
mData(aOther.mData),
|
mData(aOther.mData),
|
||||||
mLength(aOther.mLength),
|
mLength(aOther.mLength),
|
||||||
mShared(aOther.mShared),
|
mShared(aOther.mShared),
|
||||||
|
|
@ -94,14 +60,10 @@ public:
|
||||||
inline bool Init(JSObject* obj)
|
inline bool Init(JSObject* obj)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(!inited());
|
MOZ_ASSERT(!inited());
|
||||||
mTypedObj = mWrappedObj = UnwrapArray(obj);
|
mImplObj = mWrappedObj = UnwrapArray(obj);
|
||||||
return inited();
|
return inited();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool inited() const {
|
|
||||||
return !!mTypedObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
// About shared memory:
|
// About shared memory:
|
||||||
//
|
//
|
||||||
// Any DOM TypedArray as well as any DOM ArrayBufferView that does
|
// Any DOM TypedArray as well as any DOM ArrayBufferView that does
|
||||||
|
|
@ -173,22 +135,11 @@ public:
|
||||||
return mLength;
|
return mLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline JSObject *Obj() const {
|
|
||||||
MOZ_ASSERT(inited());
|
|
||||||
return mWrappedObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool WrapIntoNewCompartment(JSContext* cx)
|
|
||||||
{
|
|
||||||
return JS_WrapObject(cx,
|
|
||||||
JS::MutableHandle<JSObject*>::fromMarkedLocation(&mWrappedObj));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void ComputeLengthAndData() const
|
inline void ComputeLengthAndData() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(inited());
|
MOZ_ASSERT(inited());
|
||||||
MOZ_ASSERT(!mComputed);
|
MOZ_ASSERT(!mComputed);
|
||||||
GetLengthAndDataAndSharedness(mTypedObj, &mLength, &mShared, &mData);
|
GetLengthAndDataAndSharedness(mImplObj, &mLength, &mShared, &mData);
|
||||||
mComputed = true;
|
mComputed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -363,77 +314,6 @@ class TypedArrayCreator
|
||||||
const ArrayType& mArray;
|
const ArrayType& mArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A class for rooting an existing TypedArray struct
|
|
||||||
template<typename ArrayType>
|
|
||||||
class MOZ_RAII TypedArrayRooter : private JS::CustomAutoRooter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template <typename CX>
|
|
||||||
TypedArrayRooter(const CX& cx,
|
|
||||||
ArrayType* aArray MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
||||||
JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT),
|
|
||||||
mArray(aArray)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void trace(JSTracer* trc) override
|
|
||||||
{
|
|
||||||
mArray->TraceSelf(trc);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
TypedArrayObjectStorage* const mArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
// And a specialization for dealing with nullable typed arrays
|
|
||||||
template<typename Inner> struct Nullable;
|
|
||||||
template<typename ArrayType>
|
|
||||||
class MOZ_RAII TypedArrayRooter<Nullable<ArrayType> > :
|
|
||||||
private JS::CustomAutoRooter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template <typename CX>
|
|
||||||
TypedArrayRooter(const CX& cx,
|
|
||||||
Nullable<ArrayType>* aArray MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
||||||
JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT),
|
|
||||||
mArray(aArray)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void trace(JSTracer* trc) override
|
|
||||||
{
|
|
||||||
if (!mArray->IsNull()) {
|
|
||||||
mArray->Value().TraceSelf(trc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Nullable<ArrayType>* const mArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Class for easily setting up a rooted typed array object on the stack
|
|
||||||
template<typename ArrayType>
|
|
||||||
class MOZ_RAII RootedTypedArray final : public ArrayType,
|
|
||||||
private TypedArrayRooter<ArrayType>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template <typename CX>
|
|
||||||
explicit RootedTypedArray(const CX& cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
||||||
ArrayType(),
|
|
||||||
TypedArrayRooter<ArrayType>(cx, this
|
|
||||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename CX>
|
|
||||||
RootedTypedArray(const CX& cx, JSObject* obj MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
||||||
ArrayType(obj),
|
|
||||||
TypedArrayRooter<ArrayType>(cx, this
|
|
||||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,11 @@ EXPORTS.mozilla.dom += [
|
||||||
'NonRefcountedDOMObject.h',
|
'NonRefcountedDOMObject.h',
|
||||||
'Nullable.h',
|
'Nullable.h',
|
||||||
'PrimitiveConversions.h',
|
'PrimitiveConversions.h',
|
||||||
|
'ReadableStream.h',
|
||||||
'Record.h',
|
'Record.h',
|
||||||
'RootedDictionary.h',
|
'RootedDictionary.h',
|
||||||
'SimpleGlobalObject.h',
|
'SimpleGlobalObject.h',
|
||||||
|
'SpiderMonkeyInterface.h',
|
||||||
'StructuredClone.h',
|
'StructuredClone.h',
|
||||||
'ToJSValue.h',
|
'ToJSValue.h',
|
||||||
'TypedArray.h',
|
'TypedArray.h',
|
||||||
|
|
|
||||||
|
|
@ -2054,6 +2054,9 @@ class IDLType(IDLObject):
|
||||||
def isRecord(self):
|
def isRecord(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def isReadableStream(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def isArrayBuffer(self):
|
def isArrayBuffer(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -2081,12 +2084,12 @@ class IDLType(IDLObject):
|
||||||
|
|
||||||
def isSpiderMonkeyInterface(self):
|
def isSpiderMonkeyInterface(self):
|
||||||
""" Returns a boolean indicating whether this type is an 'interface'
|
""" Returns a boolean indicating whether this type is an 'interface'
|
||||||
type that is implemented in Spidermonkey. At the moment, this
|
type that is implemented in SpiderMonkey. """
|
||||||
only returns true for the types from the TypedArray spec. """
|
|
||||||
return self.isInterface() and (self.isArrayBuffer() or
|
return self.isInterface() and (self.isArrayBuffer() or
|
||||||
self.isArrayBufferView() or
|
self.isArrayBufferView() or
|
||||||
self.isSharedArrayBuffer() or
|
self.isSharedArrayBuffer() or
|
||||||
self.isTypedArray())
|
self.isTypedArray() or
|
||||||
|
self.isReadableStream())
|
||||||
|
|
||||||
def isDictionary(self):
|
def isDictionary(self):
|
||||||
return False
|
return False
|
||||||
|
|
@ -2275,6 +2278,9 @@ class IDLNullableType(IDLParameterizedType):
|
||||||
def isRecord(self):
|
def isRecord(self):
|
||||||
return self.inner.isRecord()
|
return self.inner.isRecord()
|
||||||
|
|
||||||
|
def isReadableStream(self):
|
||||||
|
return self.inner.isReadableStream()
|
||||||
|
|
||||||
def isArrayBuffer(self):
|
def isArrayBuffer(self):
|
||||||
return self.inner.isArrayBuffer()
|
return self.inner.isArrayBuffer()
|
||||||
|
|
||||||
|
|
@ -2634,6 +2640,9 @@ class IDLTypedefType(IDLType):
|
||||||
def isRecord(self):
|
def isRecord(self):
|
||||||
return self.inner.isRecord()
|
return self.inner.isRecord()
|
||||||
|
|
||||||
|
def isReadableStream(self):
|
||||||
|
return self.inner.isReadableStream()
|
||||||
|
|
||||||
def isDictionary(self):
|
def isDictionary(self):
|
||||||
return self.inner.isDictionary()
|
return self.inner.isDictionary()
|
||||||
|
|
||||||
|
|
@ -2945,7 +2954,8 @@ class IDLBuiltinType(IDLType):
|
||||||
'Int32Array',
|
'Int32Array',
|
||||||
'Uint32Array',
|
'Uint32Array',
|
||||||
'Float32Array',
|
'Float32Array',
|
||||||
'Float64Array'
|
'Float64Array',
|
||||||
|
'ReadableStream',
|
||||||
)
|
)
|
||||||
|
|
||||||
TagLookup = {
|
TagLookup = {
|
||||||
|
|
@ -2980,7 +2990,8 @@ class IDLBuiltinType(IDLType):
|
||||||
Types.Int32Array: IDLType.Tags.interface,
|
Types.Int32Array: IDLType.Tags.interface,
|
||||||
Types.Uint32Array: IDLType.Tags.interface,
|
Types.Uint32Array: IDLType.Tags.interface,
|
||||||
Types.Float32Array: IDLType.Tags.interface,
|
Types.Float32Array: IDLType.Tags.interface,
|
||||||
Types.Float64Array: IDLType.Tags.interface
|
Types.Float64Array: IDLType.Tags.interface,
|
||||||
|
Types.ReadableStream: IDLType.Tags.interface,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, location, name, type):
|
def __init__(self, location, name, type):
|
||||||
|
|
@ -3027,6 +3038,9 @@ class IDLBuiltinType(IDLType):
|
||||||
return (self._typeTag >= IDLBuiltinType.Types.Int8Array and
|
return (self._typeTag >= IDLBuiltinType.Types.Int8Array and
|
||||||
self._typeTag <= IDLBuiltinType.Types.Float64Array)
|
self._typeTag <= IDLBuiltinType.Types.Float64Array)
|
||||||
|
|
||||||
|
def isReadableStream(self):
|
||||||
|
return self._typeTag == IDLBuiltinType.Types.ReadableStream
|
||||||
|
|
||||||
def isInterface(self):
|
def isInterface(self):
|
||||||
# TypedArray things are interface types per the TypedArray spec,
|
# TypedArray things are interface types per the TypedArray spec,
|
||||||
# but we handle them as builtins because SpiderMonkey implements
|
# but we handle them as builtins because SpiderMonkey implements
|
||||||
|
|
@ -3034,7 +3048,8 @@ class IDLBuiltinType(IDLType):
|
||||||
return (self.isArrayBuffer() or
|
return (self.isArrayBuffer() or
|
||||||
self.isArrayBufferView() or
|
self.isArrayBufferView() or
|
||||||
self.isSharedArrayBuffer() or
|
self.isSharedArrayBuffer() or
|
||||||
self.isTypedArray())
|
self.isTypedArray() or
|
||||||
|
self.isReadableStream())
|
||||||
|
|
||||||
def isNonCallbackInterface(self):
|
def isNonCallbackInterface(self):
|
||||||
# All the interfaces we can be are non-callback
|
# All the interfaces we can be are non-callback
|
||||||
|
|
@ -3104,6 +3119,7 @@ class IDLBuiltinType(IDLType):
|
||||||
# that's not an ArrayBuffer or a callback interface
|
# that's not an ArrayBuffer or a callback interface
|
||||||
(self.isArrayBuffer() and not other.isArrayBuffer()) or
|
(self.isArrayBuffer() and not other.isArrayBuffer()) or
|
||||||
(self.isSharedArrayBuffer() and not other.isSharedArrayBuffer()) or
|
(self.isSharedArrayBuffer() and not other.isSharedArrayBuffer()) or
|
||||||
|
(self.isReadableStream() and not other.isReadableStream()) or
|
||||||
# ArrayBufferView is distinguishable from everything
|
# ArrayBufferView is distinguishable from everything
|
||||||
# that's not an ArrayBufferView or typed array.
|
# that's not an ArrayBufferView or typed array.
|
||||||
(self.isArrayBufferView() and not other.isArrayBufferView() and
|
(self.isArrayBufferView() and not other.isArrayBufferView() and
|
||||||
|
|
@ -3213,7 +3229,10 @@ BuiltinTypes = {
|
||||||
IDLBuiltinType.Types.Float32Array),
|
IDLBuiltinType.Types.Float32Array),
|
||||||
IDLBuiltinType.Types.Float64Array:
|
IDLBuiltinType.Types.Float64Array:
|
||||||
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Float64Array",
|
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Float64Array",
|
||||||
IDLBuiltinType.Types.Float64Array)
|
IDLBuiltinType.Types.Float64Array),
|
||||||
|
IDLBuiltinType.Types.ReadableStream:
|
||||||
|
IDLBuiltinType(BuiltinLocation("<builtin type>"), "ReadableStream",
|
||||||
|
IDLBuiltinType.Types.ReadableStream),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5232,7 +5251,8 @@ class Tokenizer(object):
|
||||||
"maplike": "MAPLIKE",
|
"maplike": "MAPLIKE",
|
||||||
"setlike": "SETLIKE",
|
"setlike": "SETLIKE",
|
||||||
"iterable": "ITERABLE",
|
"iterable": "ITERABLE",
|
||||||
"namespace": "NAMESPACE"
|
"namespace": "NAMESPACE",
|
||||||
|
"ReadableStream": "READABLESTREAM",
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens.extend(keywords.values())
|
tokens.extend(keywords.values())
|
||||||
|
|
@ -6420,6 +6440,7 @@ class Parser(Tokenizer):
|
||||||
NonAnyType : PrimitiveType Null
|
NonAnyType : PrimitiveType Null
|
||||||
| ARRAYBUFFER Null
|
| ARRAYBUFFER Null
|
||||||
| SHAREDARRAYBUFFER Null
|
| SHAREDARRAYBUFFER Null
|
||||||
|
| READABLESTREAM Null
|
||||||
| OBJECT Null
|
| OBJECT Null
|
||||||
"""
|
"""
|
||||||
if p[1] == "object":
|
if p[1] == "object":
|
||||||
|
|
@ -6428,6 +6449,8 @@ class Parser(Tokenizer):
|
||||||
type = BuiltinTypes[IDLBuiltinType.Types.ArrayBuffer]
|
type = BuiltinTypes[IDLBuiltinType.Types.ArrayBuffer]
|
||||||
elif p[1] == "SharedArrayBuffer":
|
elif p[1] == "SharedArrayBuffer":
|
||||||
type = BuiltinTypes[IDLBuiltinType.Types.SharedArrayBuffer]
|
type = BuiltinTypes[IDLBuiltinType.Types.SharedArrayBuffer]
|
||||||
|
elif p[1] == "ReadableStream":
|
||||||
|
type = BuiltinTypes[IDLBuiltinType.Types.ReadableStream]
|
||||||
else:
|
else:
|
||||||
type = BuiltinTypes[p[1]]
|
type = BuiltinTypes[p[1]]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2974,8 +2974,8 @@ ValidateRect(double& aX, double& aY, double& aWidth, double& aHeight, bool aIsZe
|
||||||
// The values of canvas API input are in double precision, but Moz2D APIs are
|
// The values of canvas API input are in double precision, but Moz2D APIs are
|
||||||
// using float precision. Bypass canvas API calls when the input is out of
|
// using float precision. Bypass canvas API calls when the input is out of
|
||||||
// float precision to avoid precision problem
|
// float precision to avoid precision problem
|
||||||
if (!std::isfinite((float)aX) | !std::isfinite((float)aY) |
|
if (!std::isfinite((float)aX) || !std::isfinite((float)aY) ||
|
||||||
!std::isfinite((float)aWidth) | !std::isfinite((float)aHeight)) {
|
!std::isfinite((float)aWidth) || !std::isfinite((float)aHeight)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5961,7 +5961,7 @@ void
|
||||||
CanvasRenderingContext2D::PutImageData(ImageData& aImageData, double aDx,
|
CanvasRenderingContext2D::PutImageData(ImageData& aImageData, double aDx,
|
||||||
double aDy, ErrorResult& aError)
|
double aDy, ErrorResult& aError)
|
||||||
{
|
{
|
||||||
RootedTypedArray<Uint8ClampedArray> arr(RootingCx());
|
RootedSpiderMonkeyInterface<Uint8ClampedArray> arr(RootingCx());
|
||||||
DebugOnly<bool> inited = arr.Init(aImageData.GetDataObject());
|
DebugOnly<bool> inited = arr.Init(aImageData.GetDataObject());
|
||||||
MOZ_ASSERT(inited);
|
MOZ_ASSERT(inited);
|
||||||
|
|
||||||
|
|
@ -5977,7 +5977,7 @@ CanvasRenderingContext2D::PutImageData(ImageData& aImageData, double aDx,
|
||||||
double aDirtyHeight,
|
double aDirtyHeight,
|
||||||
ErrorResult& aError)
|
ErrorResult& aError)
|
||||||
{
|
{
|
||||||
RootedTypedArray<Uint8ClampedArray> arr(RootingCx());
|
RootedSpiderMonkeyInterface<Uint8ClampedArray> arr(RootingCx());
|
||||||
DebugOnly<bool> inited = arr.Init(aImageData.GetDataObject());
|
DebugOnly<bool> inited = arr.Init(aImageData.GetDataObject());
|
||||||
MOZ_ASSERT(inited);
|
MOZ_ASSERT(inited);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -929,7 +929,7 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, ImageData& aImageData,
|
||||||
const Maybe<IntRect>& aCropRect, ErrorResult& aRv)
|
const Maybe<IntRect>& aCropRect, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
// Copy data into SourceSurface.
|
// Copy data into SourceSurface.
|
||||||
RootedTypedArray<Uint8ClampedArray> array(RootingCx());
|
RootedSpiderMonkeyInterface<Uint8ClampedArray> array(RootingCx());
|
||||||
DebugOnly<bool> inited = array.Init(aImageData.GetDataObject());
|
DebugOnly<bool> inited = array.Init(aImageData.GetDataObject());
|
||||||
MOZ_ASSERT(inited);
|
MOZ_ASSERT(inited);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -475,7 +475,7 @@ WebGLTexture::TexImage(const char* funcName, TexImageTarget target, GLint level,
|
||||||
GLsizei depth, GLint border, const webgl::PackingInfo& pi,
|
GLsizei depth, GLint border, const webgl::PackingInfo& pi,
|
||||||
const TexImageSource& src)
|
const TexImageSource& src)
|
||||||
{
|
{
|
||||||
dom::RootedTypedArray<dom::Uint8ClampedArray> scopedArr(dom::RootingCx());
|
dom::RootedSpiderMonkeyInterface<dom::Uint8ClampedArray> scopedArr(dom::RootingCx());
|
||||||
const auto blob = ValidateTexOrSubImage(mContext, funcName, target, width, height,
|
const auto blob = ValidateTexOrSubImage(mContext, funcName, target, width, height,
|
||||||
depth, border, pi, src, &scopedArr);
|
depth, border, pi, src, &scopedArr);
|
||||||
if (!blob)
|
if (!blob)
|
||||||
|
|
@ -491,7 +491,7 @@ WebGLTexture::TexSubImage(const char* funcName, TexImageTarget target, GLint lev
|
||||||
const webgl::PackingInfo& pi, const TexImageSource& src)
|
const webgl::PackingInfo& pi, const TexImageSource& src)
|
||||||
{
|
{
|
||||||
const GLint border = 0;
|
const GLint border = 0;
|
||||||
dom::RootedTypedArray<dom::Uint8ClampedArray> scopedArr(dom::RootingCx());
|
dom::RootedSpiderMonkeyInterface<dom::Uint8ClampedArray> scopedArr(dom::RootingCx());
|
||||||
const auto blob = ValidateTexOrSubImage(mContext, funcName, target, width, height,
|
const auto blob = ValidateTexOrSubImage(mContext, funcName, target, width, height,
|
||||||
depth, border, pi, src, &scopedArr);
|
depth, border, pi, src, &scopedArr);
|
||||||
if (!blob)
|
if (!blob)
|
||||||
|
|
|
||||||
|
|
@ -1366,7 +1366,7 @@ public:
|
||||||
mDataIsJwk = false;
|
mDataIsJwk = false;
|
||||||
|
|
||||||
// Try ArrayBuffer
|
// Try ArrayBuffer
|
||||||
RootedTypedArray<ArrayBuffer> ab(aCx);
|
RootedSpiderMonkeyInterface<ArrayBuffer> ab(aCx);
|
||||||
if (ab.Init(aKeyData)) {
|
if (ab.Init(aKeyData)) {
|
||||||
if (!mKeyData.Assign(ab)) {
|
if (!mKeyData.Assign(ab)) {
|
||||||
mEarlyRv = NS_ERROR_DOM_OPERATION_ERR;
|
mEarlyRv = NS_ERROR_DOM_OPERATION_ERR;
|
||||||
|
|
@ -1375,7 +1375,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try ArrayBufferView
|
// Try ArrayBufferView
|
||||||
RootedTypedArray<ArrayBufferView> abv(aCx);
|
RootedSpiderMonkeyInterface<ArrayBufferView> abv(aCx);
|
||||||
if (abv.Init(aKeyData)) {
|
if (abv.Init(aKeyData)) {
|
||||||
if (!mKeyData.Assign(abv)) {
|
if (!mKeyData.Assign(abv)) {
|
||||||
mEarlyRv = NS_ERROR_DOM_OPERATION_ERR;
|
mEarlyRv = NS_ERROR_DOM_OPERATION_ERR;
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ TCPSocketParent::RecvData(const SendableData& aData,
|
||||||
const nsTArray<uint8_t>& buffer = aData.get_ArrayOfuint8_t();
|
const nsTArray<uint8_t>& buffer = aData.get_ArrayOfuint8_t();
|
||||||
bool ok = IPC::DeserializeArrayBuffer(autoCx, buffer, &val);
|
bool ok = IPC::DeserializeArrayBuffer(autoCx, buffer, &val);
|
||||||
NS_ENSURE_TRUE(ok, true);
|
NS_ENSURE_TRUE(ok, true);
|
||||||
RootedTypedArray<ArrayBuffer> data(autoCx);
|
RootedSpiderMonkeyInterface<ArrayBuffer> data(autoCx);
|
||||||
data.Init(&val.toObject());
|
data.Init(&val.toObject());
|
||||||
Optional<uint32_t> byteLength(buffer.Length());
|
Optional<uint32_t> byteLength(buffer.Length());
|
||||||
mSocket->SendWithTrackingNumber(autoCx, data, 0, byteLength, aTrackingNumber, rv);
|
mSocket->SendWithTrackingNumber(autoCx, data, 0, byteLength, aTrackingNumber, rv);
|
||||||
|
|
|
||||||
|
|
@ -2827,7 +2827,7 @@ XMLHttpRequestMainThread::Send(nsIVariant* aVariant)
|
||||||
nsresult rv = aVariant->GetAsJSVal(&realVal);
|
nsresult rv = aVariant->GetAsJSVal(&realVal);
|
||||||
if (NS_SUCCEEDED(rv) && !realVal.isPrimitive()) {
|
if (NS_SUCCEEDED(rv) && !realVal.isPrimitive()) {
|
||||||
JS::Rooted<JSObject*> obj(rootingCx, realVal.toObjectOrNull());
|
JS::Rooted<JSObject*> obj(rootingCx, realVal.toObjectOrNull());
|
||||||
RootedTypedArray<ArrayBuffer> buf(rootingCx);
|
RootedSpiderMonkeyInterface<ArrayBuffer> buf(rootingCx);
|
||||||
if (buf.Init(obj)) {
|
if (buf.Init(obj)) {
|
||||||
RequestBody<const ArrayBuffer> body(&buf);
|
RequestBody<const ArrayBuffer> body(&buf);
|
||||||
return SendInternal(&body);
|
return SendInternal(&body);
|
||||||
|
|
|
||||||
|
|
@ -5487,3 +5487,11 @@ ReadableStream::getReader(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
return CreateReadableStreamDefaultReader(cx, stream);
|
return CreateReadableStreamDefaultReader(cx, stream);
|
||||||
return CreateReadableStreamBYOBReader(cx, stream);
|
return CreateReadableStreamBYOBReader(cx, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS_FRIEND_API(JSObject*)
|
||||||
|
js::UnwrapReadableStream(JSObject* obj)
|
||||||
|
{
|
||||||
|
if (JSObject* unwrapped = CheckedUnwrap(obj))
|
||||||
|
return unwrapped->is<ReadableStream>() ? unwrapped : nullptr;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1787,6 +1787,9 @@ UnwrapArrayBufferView(JSObject* obj);
|
||||||
extern JS_FRIEND_API(JSObject*)
|
extern JS_FRIEND_API(JSObject*)
|
||||||
UnwrapSharedArrayBuffer(JSObject* obj);
|
UnwrapSharedArrayBuffer(JSObject* obj);
|
||||||
|
|
||||||
|
extern JS_FRIEND_API(JSObject*)
|
||||||
|
UnwrapReadableStream(JSObject* obj);
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue