diff options
author | Moonchild <moonchild@palemoon.org> | 2023-10-03 17:23:19 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-10-03 17:23:19 +0000 |
commit | 5d76f359905f10fbd5b4c53ac458e26d22ffe2a1 (patch) | |
tree | 912d084cee32880dad7b06fcd1fdc1fc71ce5b95 /dom/bindings | |
parent | 682e5a4727b8bdf33a670c5d08e9cb382f019a57 (diff) | |
parent | 054f135a5455967009587e12c14908904ab4105a (diff) | |
download | uxp-5d76f359905f10fbd5b4c53ac458e26d22ffe2a1.tar.gz |
Merge pull request 'Initial implementation of readable streams' (#2324) from dbsoft/UXP:readablestreams into master
Reviewed-on: https://repo.palemoon.org/MoonchildProductions/UXP/pulls/2324
Diffstat (limited to 'dom/bindings')
-rw-r--r-- | dom/bindings/Bindings.conf | 7 | ||||
-rw-r--r-- | dom/bindings/Codegen.py | 164 | ||||
-rw-r--r-- | dom/bindings/ReadableStream.h | 28 | ||||
-rw-r--r-- | dom/bindings/SpiderMonkeyInterface.h | 144 | ||||
-rw-r--r-- | dom/bindings/TypedArray.h | 134 | ||||
-rw-r--r-- | dom/bindings/moz.build | 2 | ||||
-rw-r--r-- | dom/bindings/parser/WebIDL.py | 39 |
7 files changed, 308 insertions, 210 deletions
diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index a12a294766..17bbed79d5 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -103,11 +103,13 @@ DOMInterfaces = { }, 'Cache': { - 'implicitJSContext': [ 'add', 'addAll' ], + 'implicitJSContext': [ 'add', 'addAll', 'match', 'matchAll', 'put', + 'delete', 'keys' ], 'nativeType': 'mozilla::dom::cache::Cache', }, 'CacheStorage': { + 'implicitJSContext': [ 'match' ], 'nativeType': 'mozilla::dom::cache::CacheStorage', }, @@ -705,6 +707,7 @@ DOMInterfaces = { 'headers': 'headers_', 'referrerPolicy': 'referrerPolicy_' }, + 'implicitJSContext': [ 'arrayBuffer', 'blob', 'formData', 'json', 'text' ], }, 'ResizeObservation': { @@ -729,6 +732,8 @@ DOMInterfaces = { 'Response': { 'binaryNames': { 'headers': 'headers_' }, + 'implicitJSContext': [ 'arrayBuffer', 'blob', 'formData', 'json', 'text', + 'clone', 'cloneUnfiltered' ], }, 'RGBColor': { diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index a70253fc3a..b7caaad7bb 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1156,7 +1156,10 @@ class CGHeaders(CGWrapper): # just include their header if we need to have functions # taking references to them declared in that header. headerSet = declareIncludes - headerSet.add("mozilla/dom/TypedArray.h") + if unrolled.isReadableStream(): + headerSet.add("mozilla/dom/ReadableStream.h") + else: + headerSet.add("mozilla/dom/TypedArray.h") else: try: typeDesc = config.getDescriptor(unrolled.inner.identifier.name) @@ -1371,7 +1374,10 @@ def UnionTypes(unionTypes, config): elif f.isInterface(): if f.isSpiderMonkeyInterface(): headers.add("jsfriendapi.h") - headers.add("mozilla/dom/TypedArray.h") + if f.isReadableStream(): + headers.add("mozilla/dom/ReadableStream.h") + else: + headers.add("mozilla/dom/TypedArray.h") else: try: typeDesc = config.getDescriptor(f.inner.identifier.name) @@ -1457,7 +1463,10 @@ def UnionConversions(unionTypes, config): elif f.isInterface(): if f.isSpiderMonkeyInterface(): headers.add("jsfriendapi.h") - headers.add("mozilla/dom/TypedArray.h") + if f.isReadableStream(): + headers.add("mozilla/dom/ReadableStream.h") + else: + headers.add("mozilla/dom/TypedArray.h") elif f.inner.isExternal(): try: typeDesc = config.getDescriptor(f.inner.identifier.name) @@ -5582,8 +5591,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, if type.isSpiderMonkeyInterface(): assert not isEnforceRange and not isClamp name = type.unroll().name # unroll() because it may be nullable - arrayType = CGGeneric(name) - declType = arrayType + interfaceType = CGGeneric(name) + declType = interfaceType if type.nullable(): declType = CGTemplatedType("Nullable", declType) objRef = "${declName}.SetValue()" @@ -5607,22 +5616,23 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, # 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 # want to have a holder, so that the callee doesn't see - # Optional<RootedTypedArray<ArrayType> >. So do a holder if we're - # optional and use a RootedTypedArray otherwise. + # Optional<RootedSpiderMonkeyInterface<InterfaceType>>. So do a + # holder if we're optional and use a RootedSpiderMonkeyInterface + # otherwise. if isOptional: - holderType = CGTemplatedType("TypedArrayRooter", arrayType) - # If our typed array is nullable, this will set the Nullable to - # be not-null, but that's ok because we make an explicit - # SetNull() call on it as needed if our JS value is actually - # null. XXXbz Because "Maybe" takes const refs for constructor - # arguments, we can't pass a reference here; have to pass a - # pointer. + holderType = CGTemplatedType("SpiderMonkeyInterfaceRooter", interfaceType) + # If our SpiderMonkey interface is nullable, this will set the + # Nullable to be not-null, but that's ok because we make an + # explicit SetNull() call on it as needed if our JS value is + # actually null. XXXbz Because "Maybe" takes const refs for + # constructor arguments, we can't pass a reference here; have + # to pass a pointer. holderArgs = "cx, &%s" % objRef declArgs = None else: holderType = None holderArgs = None - declType = CGTemplatedType("RootedTypedArray", declType) + declType = CGTemplatedType("RootedSpiderMonkeyInterface", declType) declArgs = "cx" else: holderType = None @@ -6371,7 +6381,7 @@ def getMaybeWrapValueFuncForType(type): if type.nullable(): return "MaybeWrapObjectOrNullValue" 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. if type.isSpiderMonkeyInterface() or type.isDictionary() or type.isSequence(): if type.nullable(): @@ -6391,7 +6401,8 @@ recordWrapLevel = 0 def getWrapTemplateForType(type, descriptorProvider, result, successCode, - returnsNewObject, exceptionCode, typedArraysAreStructs, + returnsNewObject, exceptionCode, + spiderMonkeyInterfacesAreStructs, isConstructorRetval=False): """ Reflect a C++ value stored in "result", of IDL type "type" into JS. The @@ -6401,8 +6412,9 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, doing a 'break' if the entire conversion template is inside a block that the 'break' will exit). - If typedArraysAreStructs is true, then if the type is a typed array, - "result" is one of the dom::TypedArray subclasses, not a JSObject*. + If spiderMonkeyInterfacesAreStructs is true, then if the type is a + SpiderMonkey interface, "result" is one of the + dom::SpiderMonkeyInterfaceObjectStorage subclasses, not a JSObject*. The resulting string should be used with string.Template. It needs the following keys when substituting: @@ -6497,7 +6509,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, recTemplate, recInfall = getWrapTemplateForType(type.inner, descriptorProvider, "%s.Value()" % result, successCode, returnsNewObject, exceptionCode, - typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs) code = fill( """ @@ -6529,7 +6541,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, 'returnsNewObject': returnsNewObject, 'exceptionCode': exceptionCode, 'obj': "returnArray", - 'typedArraysAreStructs': typedArraysAreStructs + 'spiderMonkeyInterfacesAreStructs': spiderMonkeyInterfacesAreStructs }) sequenceWrapLevel -= 1 code = fill( @@ -6583,7 +6595,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, 'returnsNewObject': returnsNewObject, 'exceptionCode': exceptionCode, 'obj': "returnObj", - 'typedArraysAreStructs': typedArraysAreStructs + 'spiderMonkeyInterfacesAreStructs': spiderMonkeyInterfacesAreStructs }) recordWrapLevel -= 1 if type.keyType.isByteString(): @@ -6749,7 +6761,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, return (head + _setValue(result, wrapAsType=type), False) if (type.isObject() or (type.isSpiderMonkeyInterface() and - not typedArraysAreStructs)): + not spiderMonkeyInterfacesAreStructs)): # See comments in GetOrCreateDOMReflector explaining why we need # to wrap here. if type.nullable(): @@ -6768,21 +6780,21 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or type.isDate() or - (type.isSpiderMonkeyInterface() and typedArraysAreStructs)): + (type.isSpiderMonkeyInterface() and spiderMonkeyInterfacesAreStructs)): raise TypeError("Need to learn to wrap %s" % type) if type.nullable(): recTemplate, recInfal = getWrapTemplateForType(type.inner, descriptorProvider, "%s.Value()" % result, successCode, returnsNewObject, exceptionCode, - typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs) return ("if (%s.IsNull()) {\n" % result + indent(setNull()) + "}\n" + recTemplate, recInfal) if type.isSpiderMonkeyInterface(): - assert typedArraysAreStructs + assert spiderMonkeyInterfacesAreStructs # See comments in GetOrCreateDOMReflector explaining why we need # to wrap here. # NB: setObject(..., some-object-type) calls JS_WrapValue(), so is fallible @@ -6864,7 +6876,7 @@ def wrapForType(type, descriptorProvider, templateValues): templateValues.get('successCode', None), templateValues.get('returnsNewObject', False), templateValues.get('exceptionCode', "return false;\n"), - templateValues.get('typedArraysAreStructs', False), + templateValues.get('spiderMonkeyInterfacesAreStructs', False), isConstructorRetval=templateValues.get('isConstructorRetval', False))[0] defaultValues = {'obj': 'obj'} @@ -8193,10 +8205,10 @@ class CGMethodCall(CGThing): # "object" arg. # First grab all the overloads that have a non-callback interface - # (which includes typed arrays and arraybuffers) at the - # distinguishing index. We can also include the ones that have an - # "object" here, since if those are present no other object-typed - # argument will be. + # (which includes SpiderMonkey interfaces) at the distinguishing + # index. We can also include the ones that have an "object" here, + # since if those are present no other object-typed argument will + # be. objectSigs = [ s for s in possibleSignatures if (distinguishingType(s).isObject() or @@ -8227,16 +8239,17 @@ class CGMethodCall(CGThing): # There might be more than one thing in objectSigs; we need to check # which ones we unwrap to. if len(objectSigs) > 0: - # Here it's enough to guard on our argument being an object. The - # code for unwrapping non-callback interfaces, typed arrays, - # sequences, and Dates will just bail out and move on to - # the next overload if the object fails to unwrap correctly, - # while "object" accepts any object anyway. We could even not - # do the isObject() check up front here, but in cases where we - # have multiple object overloads it makes sense to do it only - # once instead of for each overload. That will also allow the - # unwrapping test to skip having to do codegen for the - # null-or-undefined case, which we already handled above. + # Here it's enough to guard on our argument being an object. + # The code for unwrapping non-callback interfaces, spiderMonkey + # interfaces, sequences, and Dates will just bail out and move + # on to the next overload if the object fails to unwrap + # correctly, while "object" accepts any object anyway. We + # could even not do the isObject() check up front here, but in + # cases where we have multiple object overloads it makes sense + # to do it only once instead of for each overload. That will + # also allow the unwrapping test to skip having to do codegen + # for the null-or-undefined case, which we already handled + # above. caseBody.append(CGGeneric("if (%s.isObject()) {\n" % distinguishingArg)) for sig in objectSigs: @@ -10239,7 +10252,7 @@ class CGUnionStruct(CGThing): "jsvalHandle": "rval", "obj": "scopeObj", "result": val, - "typedArraysAreStructs": True + "spiderMonkeyInterfacesAreStructs": True }) return CGGeneric(wrapCode) @@ -13219,7 +13232,7 @@ class CGDictionary(CGThing): # 'obj' can just be allowed to be the string "obj", since that # will be our dictionary object, which is presumably itself in # the right scope. - 'typedArraysAreStructs': True + 'spiderMonkeyInterfacesAreStructs': True }) conversion = CGGeneric(innerTemplate) conversion = CGWrapper(conversion, @@ -13679,7 +13692,7 @@ class ForwardDeclarationBuilder: except NoSuchDescriptorError: pass - # Note: Spidermonkey interfaces are typedefs, so can't be + # Note: SpiderMonkey interfaces are typedefs, so can't be # forward-declared elif t.isPromise(): self.addInMozillaDom("Promise") @@ -13988,7 +14001,7 @@ class CGBindingRoot(CGThing): return {desc.getDescriptor(desc.interface.parent.identifier.name)} for x in dependencySortObjects(jsImplemented, getParentDescriptor, lambda d: d.interface.identifier.name): - cgthings.append(CGCallbackInterface(x, typedArraysAreStructs=True)) + cgthings.append(CGCallbackInterface(x, spiderMonkeyInterfacesAreStructs=True)) cgthings.append(CGJSImplClass(x)) # And make sure we have the right number of newlines at the end @@ -14050,14 +14063,13 @@ class CGBindingRoot(CGThing): class CGNativeMember(ClassMethod): def __init__(self, descriptorProvider, member, name, signature, extendedAttrs, breakAfter=True, passJSBitsAsNeeded=True, visibility="public", - typedArraysAreStructs=True, variadicIsSequence=False, - resultNotAddRefed=False, - virtual=False, - override=False): + spiderMonkeyInterfacesAreStructs=True, + variadicIsSequence=False, resultNotAddRefed=False, + virtual=False, override=False): """ - If typedArraysAreStructs is false, typed arrays will be passed as - JS::Handle<JSObject*>. If it's true they will be passed as one of the - dom::TypedArray subclasses. + If spiderMonkeyInterfacesAreStructs is false, SpiderMonkey interfaces + will be passed as JS::Handle<JSObject*>. If it's true they will be + passed as one of the dom::SpiderMonkeyInterfaceObjectStorage subclasses. If passJSBitsAsNeeded is false, we don't automatically pass in a JSContext* or a JSObject* based on the return and argument types. We @@ -14068,7 +14080,7 @@ class CGNativeMember(ClassMethod): self.extendedAttrs = extendedAttrs self.resultAlreadyAddRefed = not resultNotAddRefed self.passJSBitsAsNeeded = passJSBitsAsNeeded - self.typedArraysAreStructs = typedArraysAreStructs + self.spiderMonkeyInterfacesAreStructs = spiderMonkeyInterfacesAreStructs self.variadicIsSequence = variadicIsSequence breakAfterSelf = "\n" if breakAfter else "" ClassMethod.__init__(self, name, @@ -14375,7 +14387,7 @@ class CGNativeMember(ClassMethod): False, False) if type.isSpiderMonkeyInterface(): - if not self.typedArraysAreStructs: + if not self.spiderMonkeyInterfacesAreStructs: return "JS::Handle<JSObject*>", False, False # Unroll for the name, in case we're nullable. @@ -15547,16 +15559,16 @@ class CGFastCallback(CGClass): class CGCallbackInterface(CGCallback): - def __init__(self, descriptor, typedArraysAreStructs=False): + def __init__(self, descriptor, spiderMonkeyInterfacesAreStructs=False): iface = descriptor.interface attrs = [m for m in iface.members if m.isAttr() and not m.isStatic()] - getters = [CallbackGetter(a, descriptor, typedArraysAreStructs) + getters = [CallbackGetter(a, descriptor, spiderMonkeyInterfacesAreStructs) for a in attrs] - setters = [CallbackSetter(a, descriptor, typedArraysAreStructs) + setters = [CallbackSetter(a, descriptor, spiderMonkeyInterfacesAreStructs) for a in attrs if not a.readonly] methods = [m for m in iface.members if m.isMethod() and not m.isStatic() and not m.isIdentifierLess()] - methods = [CallbackOperation(m, sig, descriptor, typedArraysAreStructs) + methods = [CallbackOperation(m, sig, descriptor, spiderMonkeyInterfacesAreStructs) for m in methods for sig in m.signatures()] if iface.isJSImplemented() and iface.ctor(): sigs = descriptor.interface.ctor().signatures() @@ -15601,7 +15613,8 @@ class CallbackMember(CGNativeMember): # CallSetup already handled the unmark-gray bits for us. we don't have # anything better to use for 'obj', really... def __init__(self, sig, name, descriptorProvider, needThisHandling, - rethrowContentException=False, typedArraysAreStructs=False, + rethrowContentException=False, + spiderMonkeyInterfacesAreStructs=False, wrapScope='CallbackKnownNotGray()'): """ needThisHandling is True if we need to be able to accept a specified @@ -15636,7 +15649,7 @@ class CallbackMember(CGNativeMember): extendedAttrs={}, passJSBitsAsNeeded=False, visibility=visibility, - typedArraysAreStructs=typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs) # We have to do all the generation of our body now, because # the caller relies on us throwing if we can't manage it. self.exceptionCode = ("aRv.Throw(NS_ERROR_UNEXPECTED);\n" @@ -15753,7 +15766,7 @@ class CallbackMember(CGNativeMember): 'obj': self.wrapScope, 'returnsNewObject': False, 'exceptionCode': self.exceptionCode, - 'typedArraysAreStructs': self.typedArraysAreStructs + 'spiderMonkeyInterfacesAreStructs': self.spiderMonkeyInterfacesAreStructs }) except MethodNotNewObjectError as err: raise TypeError("%s being passed as an argument to %s but is not " @@ -15857,10 +15870,11 @@ class CallbackMember(CGNativeMember): class CallbackMethod(CallbackMember): def __init__(self, sig, name, descriptorProvider, needThisHandling, - rethrowContentException=False, typedArraysAreStructs=False): + rethrowContentException=False, + spiderMonkeyInterfacesAreStructs=False): CallbackMember.__init__(self, sig, name, descriptorProvider, needThisHandling, rethrowContentException, - typedArraysAreStructs=typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs) def getRvalDecl(self): return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n" @@ -15919,12 +15933,12 @@ class CallbackOperationBase(CallbackMethod): """ def __init__(self, signature, jsName, nativeName, descriptor, singleOperation, rethrowContentException=False, - typedArraysAreStructs=False): + spiderMonkeyInterfacesAreStructs=False): self.singleOperation = singleOperation self.methodName = descriptor.binaryNameFor(jsName) CallbackMethod.__init__(self, signature, nativeName, descriptor, singleOperation, rethrowContentException, - typedArraysAreStructs=typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs) def getThisDecl(self): if not self.singleOperation: @@ -15975,7 +15989,8 @@ class CallbackOperation(CallbackOperationBase): """ Codegen actual WebIDL operations on callback interfaces. """ - def __init__(self, method, signature, descriptor, typedArraysAreStructs): + def __init__(self, method, signature, descriptor, + spiderMonkeyInterfacesAreStructs): self.ensureASCIIName(method) self.method = method jsName = method.identifier.name @@ -15984,7 +15999,7 @@ class CallbackOperation(CallbackOperationBase): MakeNativeName(descriptor.binaryNameFor(jsName)), descriptor, descriptor.interface.isSingleOperationInterface(), rethrowContentException=descriptor.interface.isJSImplemented(), - typedArraysAreStructs=typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs) def getPrettyName(self): return "%s.%s" % (self.descriptorProvider.interface.identifier.name, @@ -15995,13 +16010,14 @@ class CallbackAccessor(CallbackMember): """ Shared superclass for CallbackGetter and CallbackSetter. """ - def __init__(self, attr, sig, name, descriptor, typedArraysAreStructs): + def __init__(self, attr, sig, name, descriptor, + spiderMonkeyInterfacesAreStructs): self.ensureASCIIName(attr) self.attrName = attr.identifier.name CallbackMember.__init__(self, sig, name, descriptor, needThisHandling=False, rethrowContentException=descriptor.interface.isJSImplemented(), - typedArraysAreStructs=typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs) def getPrettyName(self): return "%s.%s" % (self.descriptorProvider.interface.identifier.name, @@ -16009,12 +16025,12 @@ class CallbackAccessor(CallbackMember): class CallbackGetter(CallbackAccessor): - def __init__(self, attr, descriptor, typedArraysAreStructs): + def __init__(self, attr, descriptor, spiderMonkeyInterfacesAreStructs): CallbackAccessor.__init__(self, attr, (attr.type, []), callbackGetterName(attr, descriptor), descriptor, - typedArraysAreStructs) + spiderMonkeyInterfacesAreStructs) def getRvalDecl(self): return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n" @@ -16036,12 +16052,12 @@ class CallbackGetter(CallbackAccessor): class CallbackSetter(CallbackAccessor): - def __init__(self, attr, descriptor, typedArraysAreStructs): + def __init__(self, attr, descriptor, spiderMonkeyInterfacesAreStructs): CallbackAccessor.__init__(self, attr, (BuiltinTypes[IDLBuiltinType.Types.void], [FakeArgument(attr.type, attr)]), callbackSetterName(attr, descriptor), - descriptor, typedArraysAreStructs) + descriptor, spiderMonkeyInterfacesAreStructs) def getRvalDecl(self): # We don't need an rval @@ -16076,7 +16092,7 @@ class CGJSImplInitOperation(CallbackOperationBase): "__init", "__Init", descriptor, singleOperation=False, rethrowContentException=True, - typedArraysAreStructs=True) + spiderMonkeyInterfacesAreStructs=True) def getPrettyName(self): return "__init" diff --git a/dom/bindings/ReadableStream.h b/dom/bindings/ReadableStream.h new file mode 100644 index 0000000000..1ea7ac4d88 --- /dev/null +++ b/dom/bindings/ReadableStream.h @@ -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 */ diff --git a/dom/bindings/SpiderMonkeyInterface.h b/dom/bindings/SpiderMonkeyInterface.h new file mode 100644 index 0000000000..f852afddaf --- /dev/null +++ b/dom/bindings/SpiderMonkeyInterface.h @@ -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 */ diff --git a/dom/bindings/TypedArray.h b/dom/bindings/TypedArray.h index 631707579b..8de0621d46 100644 --- a/dom/bindings/TypedArray.h +++ b/dom/bindings/TypedArray.h @@ -6,52 +6,16 @@ #ifndef 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/Move.h" #include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/SpiderMonkeyInterface.h" #include "nsWrapperCache.h" namespace mozilla { 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 * that has a way of initializing a TypedArray from an existing typed array, and * a subclass of the base class that supports creation of a relevant typed array @@ -60,7 +24,9 @@ private: template<typename T, JSObject* UnwrapArray(JSObject*), void GetLengthAndDataAndSharedness(JSObject*, uint32_t*, bool*, T**)> -struct TypedArray_base : public TypedArrayObjectStorage { +struct TypedArray_base : public SpiderMonkeyInterfaceObjectStorage, + AllTypedArraysBase +{ typedef T element_type; TypedArray_base() @@ -72,7 +38,7 @@ struct TypedArray_base : public TypedArrayObjectStorage { } TypedArray_base(TypedArray_base&& aOther) - : TypedArrayObjectStorage(Move(aOther)), + : SpiderMonkeyInterfaceObjectStorage(Move(aOther)), mData(aOther.mData), mLength(aOther.mLength), mShared(aOther.mShared), @@ -94,14 +60,10 @@ public: inline bool Init(JSObject* obj) { MOZ_ASSERT(!inited()); - mTypedObj = mWrappedObj = UnwrapArray(obj); + mImplObj = mWrappedObj = UnwrapArray(obj); return inited(); } - inline bool inited() const { - return !!mTypedObj; - } - // About shared memory: // // Any DOM TypedArray as well as any DOM ArrayBufferView that does @@ -173,22 +135,11 @@ public: 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 { MOZ_ASSERT(inited()); MOZ_ASSERT(!mComputed); - GetLengthAndDataAndSharedness(mTypedObj, &mLength, &mShared, &mData); + GetLengthAndDataAndSharedness(mImplObj, &mLength, &mShared, &mData); mComputed = true; } @@ -363,77 +314,6 @@ class TypedArrayCreator 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 mozilla diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index 9afaf4fd45..60309080e4 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -38,9 +38,11 @@ EXPORTS.mozilla.dom += [ 'NonRefcountedDOMObject.h', 'Nullable.h', 'PrimitiveConversions.h', + 'ReadableStream.h', 'Record.h', 'RootedDictionary.h', 'SimpleGlobalObject.h', + 'SpiderMonkeyInterface.h', 'StructuredClone.h', 'ToJSValue.h', 'TypedArray.h', diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 59db43f6bd..0aa3afa4e8 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -2054,6 +2054,9 @@ class IDLType(IDLObject): def isRecord(self): return False + def isReadableStream(self): + return False + def isArrayBuffer(self): return False @@ -2081,12 +2084,12 @@ class IDLType(IDLObject): def isSpiderMonkeyInterface(self): """ Returns a boolean indicating whether this type is an 'interface' - type that is implemented in Spidermonkey. At the moment, this - only returns true for the types from the TypedArray spec. """ + type that is implemented in SpiderMonkey. """ return self.isInterface() and (self.isArrayBuffer() or self.isArrayBufferView() or self.isSharedArrayBuffer() or - self.isTypedArray()) + self.isTypedArray() or + self.isReadableStream()) def isDictionary(self): return False @@ -2275,6 +2278,9 @@ class IDLNullableType(IDLParameterizedType): def isRecord(self): return self.inner.isRecord() + def isReadableStream(self): + return self.inner.isReadableStream() + def isArrayBuffer(self): return self.inner.isArrayBuffer() @@ -2634,6 +2640,9 @@ class IDLTypedefType(IDLType): def isRecord(self): return self.inner.isRecord() + def isReadableStream(self): + return self.inner.isReadableStream() + def isDictionary(self): return self.inner.isDictionary() @@ -2945,7 +2954,8 @@ class IDLBuiltinType(IDLType): 'Int32Array', 'Uint32Array', 'Float32Array', - 'Float64Array' + 'Float64Array', + 'ReadableStream', ) TagLookup = { @@ -2980,7 +2990,8 @@ class IDLBuiltinType(IDLType): Types.Int32Array: IDLType.Tags.interface, Types.Uint32Array: 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): @@ -3027,6 +3038,9 @@ class IDLBuiltinType(IDLType): return (self._typeTag >= IDLBuiltinType.Types.Int8Array and self._typeTag <= IDLBuiltinType.Types.Float64Array) + def isReadableStream(self): + return self._typeTag == IDLBuiltinType.Types.ReadableStream + def isInterface(self): # TypedArray things are interface types per the TypedArray spec, # but we handle them as builtins because SpiderMonkey implements @@ -3034,7 +3048,8 @@ class IDLBuiltinType(IDLType): return (self.isArrayBuffer() or self.isArrayBufferView() or self.isSharedArrayBuffer() or - self.isTypedArray()) + self.isTypedArray() or + self.isReadableStream()) def isNonCallbackInterface(self): # 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 (self.isArrayBuffer() and not other.isArrayBuffer()) or (self.isSharedArrayBuffer() and not other.isSharedArrayBuffer()) or + (self.isReadableStream() and not other.isReadableStream()) or # ArrayBufferView is distinguishable from everything # that's not an ArrayBufferView or typed array. (self.isArrayBufferView() and not other.isArrayBufferView() and @@ -3213,7 +3229,10 @@ BuiltinTypes = { IDLBuiltinType.Types.Float32Array), IDLBuiltinType.Types.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", "setlike": "SETLIKE", "iterable": "ITERABLE", - "namespace": "NAMESPACE" + "namespace": "NAMESPACE", + "ReadableStream": "READABLESTREAM", } tokens.extend(keywords.values()) @@ -6420,6 +6440,7 @@ class Parser(Tokenizer): NonAnyType : PrimitiveType Null | ARRAYBUFFER Null | SHAREDARRAYBUFFER Null + | READABLESTREAM Null | OBJECT Null """ if p[1] == "object": @@ -6428,6 +6449,8 @@ class Parser(Tokenizer): type = BuiltinTypes[IDLBuiltinType.Types.ArrayBuffer] elif p[1] == "SharedArrayBuffer": type = BuiltinTypes[IDLBuiltinType.Types.SharedArrayBuffer] + elif p[1] == "ReadableStream": + type = BuiltinTypes[IDLBuiltinType.Types.ReadableStream] else: type = BuiltinTypes[p[1]] |