mirror of
https://github.com/Basilisk-Development-Team/UXP-mirror.git
synced 2026-11-13 12:52:02 -05:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14f9893f1c | ||
|
|
142ed0c544 | ||
|
|
db0aa7989c | ||
|
|
46b9c17c57 | ||
|
|
da102ef405 | ||
|
|
336ffb82fd | ||
|
|
64e1117cba | ||
|
|
bda38927be | ||
|
|
83eb44d357 | ||
|
|
dff20616b7 | ||
|
|
bc8b279e5f | ||
|
|
bb35b25ef9 | ||
|
|
1059830a73 |
No files matched your search
@@ -8527,6 +8527,25 @@ nsContentUtils::PushEnabled(JSContext* aCx, JSObject* aObj)
|
|||||||
return workerPrivate->PushEnabled();
|
return workerPrivate->PushEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool
|
||||||
|
nsContentUtils::StreamsEnabled(JSContext* aCx, JSObject* aObj)
|
||||||
|
{
|
||||||
|
if (NS_IsMainThread()) {
|
||||||
|
return Preferences::GetBool("dom.streams.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace workers;
|
||||||
|
|
||||||
|
// Otherwise, check the pref via the WorkerPrivate
|
||||||
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||||
|
if (!workerPrivate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return workerPrivate->StreamsEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
bool
|
bool
|
||||||
nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel)
|
nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel)
|
||||||
|
|||||||
@@ -2623,6 +2623,8 @@ public:
|
|||||||
|
|
||||||
static bool PushEnabled(JSContext* aCx, JSObject* aObj);
|
static bool PushEnabled(JSContext* aCx, JSObject* aObj);
|
||||||
|
|
||||||
|
static bool StreamsEnabled(JSContext* aCx, JSObject* aObj);
|
||||||
|
|
||||||
static bool IsNonSubresourceRequest(nsIChannel* aChannel);
|
static bool IsNonSubresourceRequest(nsIChannel* aChannel);
|
||||||
|
|
||||||
static uint32_t CookiesBehavior()
|
static uint32_t CookiesBehavior()
|
||||||
|
|||||||
@@ -714,6 +714,7 @@ DOMInterfaces = {
|
|||||||
'headers': 'headers_',
|
'headers': 'headers_',
|
||||||
'referrerPolicy': 'referrerPolicy_'
|
'referrerPolicy': 'referrerPolicy_'
|
||||||
},
|
},
|
||||||
|
'implicitJSContext': [ 'arrayBuffer', 'blob', 'formData', 'json', 'text' ],
|
||||||
},
|
},
|
||||||
|
|
||||||
'ResizeObservation': {
|
'ResizeObservation': {
|
||||||
@@ -733,6 +734,8 @@ DOMInterfaces = {
|
|||||||
|
|
||||||
'Response': {
|
'Response': {
|
||||||
'binaryNames': { 'headers': 'headers_' },
|
'binaryNames': { 'headers': 'headers_' },
|
||||||
|
'implicitJSContext': [ 'arrayBuffer', 'blob', 'formData', 'json', 'text',
|
||||||
|
'clone', 'cloneUnfiltered' ],
|
||||||
},
|
},
|
||||||
|
|
||||||
'RGBColor': {
|
'RGBColor': {
|
||||||
|
|||||||
+90
-74
@@ -1156,7 +1156,10 @@ 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
|
||||||
headerSet.add("mozilla/dom/TypedArray.h")
|
if unrolled.isReadableStream():
|
||||||
|
headerSet.add("mozilla/dom/ReadableStream.h")
|
||||||
|
else:
|
||||||
|
headerSet.add("mozilla/dom/TypedArray.h")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
typeDesc = config.getDescriptor(unrolled.inner.identifier.name)
|
typeDesc = config.getDescriptor(unrolled.inner.identifier.name)
|
||||||
@@ -1371,7 +1374,10 @@ def UnionTypes(unionTypes, config):
|
|||||||
elif f.isInterface():
|
elif f.isInterface():
|
||||||
if f.isSpiderMonkeyInterface():
|
if f.isSpiderMonkeyInterface():
|
||||||
headers.add("jsfriendapi.h")
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
typeDesc = config.getDescriptor(f.inner.identifier.name)
|
typeDesc = config.getDescriptor(f.inner.identifier.name)
|
||||||
@@ -1457,7 +1463,10 @@ def UnionConversions(unionTypes, config):
|
|||||||
elif f.isInterface():
|
elif f.isInterface():
|
||||||
if f.isSpiderMonkeyInterface():
|
if f.isSpiderMonkeyInterface():
|
||||||
headers.add("jsfriendapi.h")
|
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():
|
elif f.inner.isExternal():
|
||||||
try:
|
try:
|
||||||
typeDesc = config.getDescriptor(f.inner.identifier.name)
|
typeDesc = config.getDescriptor(f.inner.identifier.name)
|
||||||
@@ -5593,8 +5602,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()"
|
||||||
@@ -5618,22 +5627,23 @@ 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 SpiderMonkey interface is nullable, this will set the
|
||||||
# be not-null, but that's ok because we make an explicit
|
# Nullable to be not-null, but that's ok because we make an
|
||||||
# SetNull() call on it as needed if our JS value is actually
|
# explicit SetNull() call on it as needed if our JS value is
|
||||||
# null. XXXbz Because "Maybe" takes const refs for constructor
|
# actually null. XXXbz Because "Maybe" takes const refs for
|
||||||
# arguments, we can't pass a reference here; have to pass a
|
# constructor arguments, we can't pass a reference here; have
|
||||||
# pointer.
|
# to pass a pointer.
|
||||||
holderArgs = "cx, &%s" % objRef
|
holderArgs = "cx, &%s" % objRef
|
||||||
declArgs = None
|
declArgs = 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
|
||||||
@@ -6382,7 +6392,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():
|
||||||
@@ -6402,7 +6412,8 @@ recordWrapLevel = 0
|
|||||||
|
|
||||||
|
|
||||||
def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
||||||
returnsNewObject, exceptionCode, typedArraysAreStructs,
|
returnsNewObject, exceptionCode,
|
||||||
|
spiderMonkeyInterfacesAreStructs,
|
||||||
isConstructorRetval=False):
|
isConstructorRetval=False):
|
||||||
"""
|
"""
|
||||||
Reflect a C++ value stored in "result", of IDL type "type" into JS. The
|
Reflect a C++ value stored in "result", of IDL type "type" into JS. The
|
||||||
@@ -6412,8 +6423,9 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
|||||||
doing a 'break' if the entire conversion template is inside a block that
|
doing a 'break' if the entire conversion template is inside a block that
|
||||||
the 'break' will exit).
|
the 'break' will exit).
|
||||||
|
|
||||||
If typedArraysAreStructs is true, then if the type is a typed array,
|
If spiderMonkeyInterfacesAreStructs is true, then if the type is a
|
||||||
"result" is one of the dom::TypedArray subclasses, not a JSObject*.
|
SpiderMonkey interface, "result" is one of the
|
||||||
|
dom::SpiderMonkeyInterfaceObjectStorage subclasses, not a JSObject*.
|
||||||
|
|
||||||
The resulting string should be used with string.Template. It
|
The resulting string should be used with string.Template. It
|
||||||
needs the following keys when substituting:
|
needs the following keys when substituting:
|
||||||
@@ -6508,7 +6520,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
|||||||
recTemplate, recInfall = getWrapTemplateForType(type.inner, descriptorProvider,
|
recTemplate, recInfall = getWrapTemplateForType(type.inner, descriptorProvider,
|
||||||
"%s.Value()" % result, successCode,
|
"%s.Value()" % result, successCode,
|
||||||
returnsNewObject, exceptionCode,
|
returnsNewObject, exceptionCode,
|
||||||
typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs)
|
||||||
code = fill(
|
code = fill(
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -6540,7 +6552,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
|||||||
'returnsNewObject': returnsNewObject,
|
'returnsNewObject': returnsNewObject,
|
||||||
'exceptionCode': exceptionCode,
|
'exceptionCode': exceptionCode,
|
||||||
'obj': "returnArray",
|
'obj': "returnArray",
|
||||||
'typedArraysAreStructs': typedArraysAreStructs
|
'spiderMonkeyInterfacesAreStructs': spiderMonkeyInterfacesAreStructs
|
||||||
})
|
})
|
||||||
sequenceWrapLevel -= 1
|
sequenceWrapLevel -= 1
|
||||||
code = fill(
|
code = fill(
|
||||||
@@ -6594,7 +6606,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
|||||||
'returnsNewObject': returnsNewObject,
|
'returnsNewObject': returnsNewObject,
|
||||||
'exceptionCode': exceptionCode,
|
'exceptionCode': exceptionCode,
|
||||||
'obj': "returnObj",
|
'obj': "returnObj",
|
||||||
'typedArraysAreStructs': typedArraysAreStructs
|
'spiderMonkeyInterfacesAreStructs': spiderMonkeyInterfacesAreStructs
|
||||||
})
|
})
|
||||||
recordWrapLevel -= 1
|
recordWrapLevel -= 1
|
||||||
if type.keyType.isByteString():
|
if type.keyType.isByteString():
|
||||||
@@ -6760,7 +6772,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
|||||||
return (head + _setValue(result, wrapAsType=type), False)
|
return (head + _setValue(result, wrapAsType=type), False)
|
||||||
|
|
||||||
if (type.isObject() or (type.isSpiderMonkeyInterface() and
|
if (type.isObject() or (type.isSpiderMonkeyInterface() and
|
||||||
not typedArraysAreStructs)):
|
not spiderMonkeyInterfacesAreStructs)):
|
||||||
# See comments in GetOrCreateDOMReflector explaining why we need
|
# See comments in GetOrCreateDOMReflector explaining why we need
|
||||||
# to wrap here.
|
# to wrap here.
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
@@ -6779,21 +6791,21 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
|||||||
|
|
||||||
if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or
|
if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or
|
||||||
type.isDate() or
|
type.isDate() or
|
||||||
(type.isSpiderMonkeyInterface() and typedArraysAreStructs)):
|
(type.isSpiderMonkeyInterface() and spiderMonkeyInterfacesAreStructs)):
|
||||||
raise TypeError("Need to learn to wrap %s" % type)
|
raise TypeError("Need to learn to wrap %s" % type)
|
||||||
|
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
recTemplate, recInfal = getWrapTemplateForType(type.inner, descriptorProvider,
|
recTemplate, recInfal = getWrapTemplateForType(type.inner, descriptorProvider,
|
||||||
"%s.Value()" % result, successCode,
|
"%s.Value()" % result, successCode,
|
||||||
returnsNewObject, exceptionCode,
|
returnsNewObject, exceptionCode,
|
||||||
typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs)
|
||||||
return ("if (%s.IsNull()) {\n" % result +
|
return ("if (%s.IsNull()) {\n" % result +
|
||||||
indent(setNull()) +
|
indent(setNull()) +
|
||||||
"}\n" +
|
"}\n" +
|
||||||
recTemplate, recInfal)
|
recTemplate, recInfal)
|
||||||
|
|
||||||
if type.isSpiderMonkeyInterface():
|
if type.isSpiderMonkeyInterface():
|
||||||
assert typedArraysAreStructs
|
assert spiderMonkeyInterfacesAreStructs
|
||||||
# See comments in GetOrCreateDOMReflector explaining why we need
|
# See comments in GetOrCreateDOMReflector explaining why we need
|
||||||
# to wrap here.
|
# to wrap here.
|
||||||
# NB: setObject(..., some-object-type) calls JS_WrapValue(), so is fallible
|
# NB: setObject(..., some-object-type) calls JS_WrapValue(), so is fallible
|
||||||
@@ -6875,7 +6887,7 @@ def wrapForType(type, descriptorProvider, templateValues):
|
|||||||
templateValues.get('successCode', None),
|
templateValues.get('successCode', None),
|
||||||
templateValues.get('returnsNewObject', False),
|
templateValues.get('returnsNewObject', False),
|
||||||
templateValues.get('exceptionCode', "return false;\n"),
|
templateValues.get('exceptionCode', "return false;\n"),
|
||||||
templateValues.get('typedArraysAreStructs', False),
|
templateValues.get('spiderMonkeyInterfacesAreStructs', False),
|
||||||
isConstructorRetval=templateValues.get('isConstructorRetval', False))[0]
|
isConstructorRetval=templateValues.get('isConstructorRetval', False))[0]
|
||||||
|
|
||||||
defaultValues = {'obj': 'obj'}
|
defaultValues = {'obj': 'obj'}
|
||||||
@@ -8215,10 +8227,10 @@ class CGMethodCall(CGThing):
|
|||||||
# "object" arg.
|
# "object" arg.
|
||||||
|
|
||||||
# First grab all the overloads that have a non-callback interface
|
# First grab all the overloads that have a non-callback interface
|
||||||
# (which includes typed arrays and arraybuffers) at the
|
# (which includes SpiderMonkey interfaces) at the distinguishing
|
||||||
# distinguishing index. We can also include the ones that have an
|
# index. We can also include the ones that have an "object" here,
|
||||||
# "object" here, since if those are present no other object-typed
|
# since if those are present no other object-typed argument will
|
||||||
# argument will be.
|
# be.
|
||||||
objectSigs = [
|
objectSigs = [
|
||||||
s for s in possibleSignatures
|
s for s in possibleSignatures
|
||||||
if (distinguishingType(s).isObject() or
|
if (distinguishingType(s).isObject() or
|
||||||
@@ -8249,16 +8261,17 @@ class CGMethodCall(CGThing):
|
|||||||
# There might be more than one thing in objectSigs; we need to check
|
# There might be more than one thing in objectSigs; we need to check
|
||||||
# which ones we unwrap to.
|
# which ones we unwrap to.
|
||||||
if len(objectSigs) > 0:
|
if len(objectSigs) > 0:
|
||||||
# Here it's enough to guard on our argument being an object. The
|
# Here it's enough to guard on our argument being an object.
|
||||||
# code for unwrapping non-callback interfaces, typed arrays,
|
# The code for unwrapping non-callback interfaces, spiderMonkey
|
||||||
# sequences, and Dates will just bail out and move on to
|
# interfaces, sequences, and Dates will just bail out and move
|
||||||
# the next overload if the object fails to unwrap correctly,
|
# on to the next overload if the object fails to unwrap
|
||||||
# while "object" accepts any object anyway. We could even not
|
# correctly, while "object" accepts any object anyway. We
|
||||||
# do the isObject() check up front here, but in cases where we
|
# could even not do the isObject() check up front here, but in
|
||||||
# have multiple object overloads it makes sense to do it only
|
# cases where we have multiple object overloads it makes sense
|
||||||
# once instead of for each overload. That will also allow the
|
# to do it only once instead of for each overload. That will
|
||||||
# unwrapping test to skip having to do codegen for the
|
# also allow the unwrapping test to skip having to do codegen
|
||||||
# null-or-undefined case, which we already handled above.
|
# for the null-or-undefined case, which we already handled
|
||||||
|
# above.
|
||||||
caseBody.append(CGGeneric("if (%s.isObject()) {\n" %
|
caseBody.append(CGGeneric("if (%s.isObject()) {\n" %
|
||||||
distinguishingArg))
|
distinguishingArg))
|
||||||
for sig in objectSigs:
|
for sig in objectSigs:
|
||||||
@@ -10271,7 +10284,7 @@ class CGUnionStruct(CGThing):
|
|||||||
"jsvalHandle": "rval",
|
"jsvalHandle": "rval",
|
||||||
"obj": "scopeObj",
|
"obj": "scopeObj",
|
||||||
"result": val,
|
"result": val,
|
||||||
"typedArraysAreStructs": True
|
"spiderMonkeyInterfacesAreStructs": True
|
||||||
})
|
})
|
||||||
return CGGeneric(wrapCode)
|
return CGGeneric(wrapCode)
|
||||||
|
|
||||||
@@ -13251,7 +13264,7 @@ class CGDictionary(CGThing):
|
|||||||
# 'obj' can just be allowed to be the string "obj", since that
|
# 'obj' can just be allowed to be the string "obj", since that
|
||||||
# will be our dictionary object, which is presumably itself in
|
# will be our dictionary object, which is presumably itself in
|
||||||
# the right scope.
|
# the right scope.
|
||||||
'typedArraysAreStructs': True
|
'spiderMonkeyInterfacesAreStructs': True
|
||||||
})
|
})
|
||||||
conversion = CGGeneric(innerTemplate)
|
conversion = CGGeneric(innerTemplate)
|
||||||
conversion = CGWrapper(conversion,
|
conversion = CGWrapper(conversion,
|
||||||
@@ -13711,7 +13724,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")
|
||||||
@@ -14026,7 +14039,7 @@ class CGBindingRoot(CGThing):
|
|||||||
return {desc.getDescriptor(desc.interface.parent.identifier.name)}
|
return {desc.getDescriptor(desc.interface.parent.identifier.name)}
|
||||||
for x in dependencySortObjects(jsImplemented, getParentDescriptor,
|
for x in dependencySortObjects(jsImplemented, getParentDescriptor,
|
||||||
lambda d: d.interface.identifier.name):
|
lambda d: d.interface.identifier.name):
|
||||||
cgthings.append(CGCallbackInterface(x, typedArraysAreStructs=True))
|
cgthings.append(CGCallbackInterface(x, spiderMonkeyInterfacesAreStructs=True))
|
||||||
cgthings.append(CGJSImplClass(x))
|
cgthings.append(CGJSImplClass(x))
|
||||||
|
|
||||||
# And make sure we have the right number of newlines at the end
|
# And make sure we have the right number of newlines at the end
|
||||||
@@ -14088,14 +14101,13 @@ class CGBindingRoot(CGThing):
|
|||||||
class CGNativeMember(ClassMethod):
|
class CGNativeMember(ClassMethod):
|
||||||
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
||||||
breakAfter=True, passJSBitsAsNeeded=True, visibility="public",
|
breakAfter=True, passJSBitsAsNeeded=True, visibility="public",
|
||||||
typedArraysAreStructs=True, variadicIsSequence=False,
|
spiderMonkeyInterfacesAreStructs=True,
|
||||||
resultNotAddRefed=False,
|
variadicIsSequence=False, resultNotAddRefed=False,
|
||||||
virtual=False,
|
virtual=False, override=False):
|
||||||
override=False):
|
|
||||||
"""
|
"""
|
||||||
If typedArraysAreStructs is false, typed arrays will be passed as
|
If spiderMonkeyInterfacesAreStructs is false, SpiderMonkey interfaces
|
||||||
JS::Handle<JSObject*>. If it's true they will be passed as one of the
|
will be passed as JS::Handle<JSObject*>. If it's true they will be
|
||||||
dom::TypedArray subclasses.
|
passed as one of the dom::SpiderMonkeyInterfaceObjectStorage subclasses.
|
||||||
|
|
||||||
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
||||||
JSContext* or a JSObject* based on the return and argument types. We
|
JSContext* or a JSObject* based on the return and argument types. We
|
||||||
@@ -14106,7 +14118,7 @@ class CGNativeMember(ClassMethod):
|
|||||||
self.extendedAttrs = extendedAttrs
|
self.extendedAttrs = extendedAttrs
|
||||||
self.resultAlreadyAddRefed = not resultNotAddRefed
|
self.resultAlreadyAddRefed = not resultNotAddRefed
|
||||||
self.passJSBitsAsNeeded = passJSBitsAsNeeded
|
self.passJSBitsAsNeeded = passJSBitsAsNeeded
|
||||||
self.typedArraysAreStructs = typedArraysAreStructs
|
self.spiderMonkeyInterfacesAreStructs = spiderMonkeyInterfacesAreStructs
|
||||||
self.variadicIsSequence = variadicIsSequence
|
self.variadicIsSequence = variadicIsSequence
|
||||||
breakAfterSelf = "\n" if breakAfter else ""
|
breakAfterSelf = "\n" if breakAfter else ""
|
||||||
ClassMethod.__init__(self, name,
|
ClassMethod.__init__(self, name,
|
||||||
@@ -14413,7 +14425,7 @@ class CGNativeMember(ClassMethod):
|
|||||||
False, False)
|
False, False)
|
||||||
|
|
||||||
if type.isSpiderMonkeyInterface():
|
if type.isSpiderMonkeyInterface():
|
||||||
if not self.typedArraysAreStructs:
|
if not self.spiderMonkeyInterfacesAreStructs:
|
||||||
return "JS::Handle<JSObject*>", False, False
|
return "JS::Handle<JSObject*>", False, False
|
||||||
|
|
||||||
# Unroll for the name, in case we're nullable.
|
# Unroll for the name, in case we're nullable.
|
||||||
@@ -15585,16 +15597,16 @@ class CGFastCallback(CGClass):
|
|||||||
|
|
||||||
|
|
||||||
class CGCallbackInterface(CGCallback):
|
class CGCallbackInterface(CGCallback):
|
||||||
def __init__(self, descriptor, typedArraysAreStructs=False):
|
def __init__(self, descriptor, spiderMonkeyInterfacesAreStructs=False):
|
||||||
iface = descriptor.interface
|
iface = descriptor.interface
|
||||||
attrs = [m for m in iface.members if m.isAttr() and not m.isStatic()]
|
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]
|
for a in attrs]
|
||||||
setters = [CallbackSetter(a, descriptor, typedArraysAreStructs)
|
setters = [CallbackSetter(a, descriptor, spiderMonkeyInterfacesAreStructs)
|
||||||
for a in attrs if not a.readonly]
|
for a in attrs if not a.readonly]
|
||||||
methods = [m for m in iface.members
|
methods = [m for m in iface.members
|
||||||
if m.isMethod() and not m.isStatic() and not m.isIdentifierLess()]
|
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()]
|
for m in methods for sig in m.signatures()]
|
||||||
if iface.isJSImplemented() and iface.ctor():
|
if iface.isJSImplemented() and iface.ctor():
|
||||||
sigs = descriptor.interface.ctor().signatures()
|
sigs = descriptor.interface.ctor().signatures()
|
||||||
@@ -15639,7 +15651,8 @@ class CallbackMember(CGNativeMember):
|
|||||||
# CallSetup already handled the unmark-gray bits for us. we don't have
|
# CallSetup already handled the unmark-gray bits for us. we don't have
|
||||||
# anything better to use for 'obj', really...
|
# anything better to use for 'obj', really...
|
||||||
def __init__(self, sig, name, descriptorProvider, needThisHandling,
|
def __init__(self, sig, name, descriptorProvider, needThisHandling,
|
||||||
rethrowContentException=False, typedArraysAreStructs=False,
|
rethrowContentException=False,
|
||||||
|
spiderMonkeyInterfacesAreStructs=False,
|
||||||
wrapScope='CallbackKnownNotGray()'):
|
wrapScope='CallbackKnownNotGray()'):
|
||||||
"""
|
"""
|
||||||
needThisHandling is True if we need to be able to accept a specified
|
needThisHandling is True if we need to be able to accept a specified
|
||||||
@@ -15674,7 +15687,7 @@ class CallbackMember(CGNativeMember):
|
|||||||
extendedAttrs={},
|
extendedAttrs={},
|
||||||
passJSBitsAsNeeded=False,
|
passJSBitsAsNeeded=False,
|
||||||
visibility=visibility,
|
visibility=visibility,
|
||||||
typedArraysAreStructs=typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
|
||||||
# We have to do all the generation of our body now, because
|
# We have to do all the generation of our body now, because
|
||||||
# the caller relies on us throwing if we can't manage it.
|
# the caller relies on us throwing if we can't manage it.
|
||||||
self.exceptionCode = ("aRv.Throw(NS_ERROR_UNEXPECTED);\n"
|
self.exceptionCode = ("aRv.Throw(NS_ERROR_UNEXPECTED);\n"
|
||||||
@@ -15791,7 +15804,7 @@ class CallbackMember(CGNativeMember):
|
|||||||
'obj': self.wrapScope,
|
'obj': self.wrapScope,
|
||||||
'returnsNewObject': False,
|
'returnsNewObject': False,
|
||||||
'exceptionCode': self.exceptionCode,
|
'exceptionCode': self.exceptionCode,
|
||||||
'typedArraysAreStructs': self.typedArraysAreStructs
|
'spiderMonkeyInterfacesAreStructs': self.spiderMonkeyInterfacesAreStructs
|
||||||
})
|
})
|
||||||
except MethodNotNewObjectError as err:
|
except MethodNotNewObjectError as err:
|
||||||
raise TypeError("%s being passed as an argument to %s but is not "
|
raise TypeError("%s being passed as an argument to %s but is not "
|
||||||
@@ -15895,10 +15908,11 @@ class CallbackMember(CGNativeMember):
|
|||||||
|
|
||||||
class CallbackMethod(CallbackMember):
|
class CallbackMethod(CallbackMember):
|
||||||
def __init__(self, sig, name, descriptorProvider, needThisHandling,
|
def __init__(self, sig, name, descriptorProvider, needThisHandling,
|
||||||
rethrowContentException=False, typedArraysAreStructs=False):
|
rethrowContentException=False,
|
||||||
|
spiderMonkeyInterfacesAreStructs=False):
|
||||||
CallbackMember.__init__(self, sig, name, descriptorProvider,
|
CallbackMember.__init__(self, sig, name, descriptorProvider,
|
||||||
needThisHandling, rethrowContentException,
|
needThisHandling, rethrowContentException,
|
||||||
typedArraysAreStructs=typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
|
||||||
|
|
||||||
def getRvalDecl(self):
|
def getRvalDecl(self):
|
||||||
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
|
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
|
||||||
@@ -15957,12 +15971,12 @@ class CallbackOperationBase(CallbackMethod):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, signature, jsName, nativeName, descriptor,
|
def __init__(self, signature, jsName, nativeName, descriptor,
|
||||||
singleOperation, rethrowContentException=False,
|
singleOperation, rethrowContentException=False,
|
||||||
typedArraysAreStructs=False):
|
spiderMonkeyInterfacesAreStructs=False):
|
||||||
self.singleOperation = singleOperation
|
self.singleOperation = singleOperation
|
||||||
self.methodName = descriptor.binaryNameFor(jsName)
|
self.methodName = descriptor.binaryNameFor(jsName)
|
||||||
CallbackMethod.__init__(self, signature, nativeName, descriptor,
|
CallbackMethod.__init__(self, signature, nativeName, descriptor,
|
||||||
singleOperation, rethrowContentException,
|
singleOperation, rethrowContentException,
|
||||||
typedArraysAreStructs=typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
|
||||||
|
|
||||||
def getThisDecl(self):
|
def getThisDecl(self):
|
||||||
if not self.singleOperation:
|
if not self.singleOperation:
|
||||||
@@ -16013,7 +16027,8 @@ class CallbackOperation(CallbackOperationBase):
|
|||||||
"""
|
"""
|
||||||
Codegen actual WebIDL operations on callback interfaces.
|
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.ensureASCIIName(method)
|
||||||
self.method = method
|
self.method = method
|
||||||
jsName = method.identifier.name
|
jsName = method.identifier.name
|
||||||
@@ -16022,7 +16037,7 @@ class CallbackOperation(CallbackOperationBase):
|
|||||||
MakeNativeName(descriptor.binaryNameFor(jsName)),
|
MakeNativeName(descriptor.binaryNameFor(jsName)),
|
||||||
descriptor, descriptor.interface.isSingleOperationInterface(),
|
descriptor, descriptor.interface.isSingleOperationInterface(),
|
||||||
rethrowContentException=descriptor.interface.isJSImplemented(),
|
rethrowContentException=descriptor.interface.isJSImplemented(),
|
||||||
typedArraysAreStructs=typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
|
||||||
|
|
||||||
def getPrettyName(self):
|
def getPrettyName(self):
|
||||||
return "%s.%s" % (self.descriptorProvider.interface.identifier.name,
|
return "%s.%s" % (self.descriptorProvider.interface.identifier.name,
|
||||||
@@ -16033,13 +16048,14 @@ class CallbackAccessor(CallbackMember):
|
|||||||
"""
|
"""
|
||||||
Shared superclass for CallbackGetter and CallbackSetter.
|
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.ensureASCIIName(attr)
|
||||||
self.attrName = attr.identifier.name
|
self.attrName = attr.identifier.name
|
||||||
CallbackMember.__init__(self, sig, name, descriptor,
|
CallbackMember.__init__(self, sig, name, descriptor,
|
||||||
needThisHandling=False,
|
needThisHandling=False,
|
||||||
rethrowContentException=descriptor.interface.isJSImplemented(),
|
rethrowContentException=descriptor.interface.isJSImplemented(),
|
||||||
typedArraysAreStructs=typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
|
||||||
|
|
||||||
def getPrettyName(self):
|
def getPrettyName(self):
|
||||||
return "%s.%s" % (self.descriptorProvider.interface.identifier.name,
|
return "%s.%s" % (self.descriptorProvider.interface.identifier.name,
|
||||||
@@ -16047,12 +16063,12 @@ class CallbackAccessor(CallbackMember):
|
|||||||
|
|
||||||
|
|
||||||
class CallbackGetter(CallbackAccessor):
|
class CallbackGetter(CallbackAccessor):
|
||||||
def __init__(self, attr, descriptor, typedArraysAreStructs):
|
def __init__(self, attr, descriptor, spiderMonkeyInterfacesAreStructs):
|
||||||
CallbackAccessor.__init__(self, attr,
|
CallbackAccessor.__init__(self, attr,
|
||||||
(attr.type, []),
|
(attr.type, []),
|
||||||
callbackGetterName(attr, descriptor),
|
callbackGetterName(attr, descriptor),
|
||||||
descriptor,
|
descriptor,
|
||||||
typedArraysAreStructs)
|
spiderMonkeyInterfacesAreStructs)
|
||||||
|
|
||||||
def getRvalDecl(self):
|
def getRvalDecl(self):
|
||||||
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
|
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
|
||||||
@@ -16074,12 +16090,12 @@ class CallbackGetter(CallbackAccessor):
|
|||||||
|
|
||||||
|
|
||||||
class CallbackSetter(CallbackAccessor):
|
class CallbackSetter(CallbackAccessor):
|
||||||
def __init__(self, attr, descriptor, typedArraysAreStructs):
|
def __init__(self, attr, descriptor, spiderMonkeyInterfacesAreStructs):
|
||||||
CallbackAccessor.__init__(self, attr,
|
CallbackAccessor.__init__(self, attr,
|
||||||
(BuiltinTypes[IDLBuiltinType.Types.void],
|
(BuiltinTypes[IDLBuiltinType.Types.void],
|
||||||
[FakeArgument(attr.type, attr)]),
|
[FakeArgument(attr.type, attr)]),
|
||||||
callbackSetterName(attr, descriptor),
|
callbackSetterName(attr, descriptor),
|
||||||
descriptor, typedArraysAreStructs)
|
descriptor, spiderMonkeyInterfacesAreStructs)
|
||||||
|
|
||||||
def getRvalDecl(self):
|
def getRvalDecl(self):
|
||||||
# We don't need an rval
|
# We don't need an rval
|
||||||
@@ -16114,7 +16130,7 @@ class CGJSImplInitOperation(CallbackOperationBase):
|
|||||||
"__init", "__Init", descriptor,
|
"__init", "__Init", descriptor,
|
||||||
singleOperation=False,
|
singleOperation=False,
|
||||||
rethrowContentException=True,
|
rethrowContentException=True,
|
||||||
typedArraysAreStructs=True)
|
spiderMonkeyInterfacesAreStructs=True)
|
||||||
|
|
||||||
def getPrettyName(self):
|
def getPrettyName(self):
|
||||||
return "__init"
|
return "__init"
|
||||||
|
|||||||
@@ -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 */
|
||||||
@@ -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 */
|
||||||
+7
-127
@@ -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',
|
||||||
|
|||||||
@@ -2048,6 +2048,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
|
||||||
|
|
||||||
@@ -2075,12 +2078,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
|
||||||
@@ -2269,6 +2272,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()
|
||||||
|
|
||||||
@@ -2628,6 +2634,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()
|
||||||
|
|
||||||
@@ -2939,7 +2948,8 @@ class IDLBuiltinType(IDLType):
|
|||||||
'Int32Array',
|
'Int32Array',
|
||||||
'Uint32Array',
|
'Uint32Array',
|
||||||
'Float32Array',
|
'Float32Array',
|
||||||
'Float64Array'
|
'Float64Array',
|
||||||
|
'ReadableStream',
|
||||||
)
|
)
|
||||||
|
|
||||||
TagLookup = {
|
TagLookup = {
|
||||||
@@ -2974,7 +2984,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):
|
||||||
@@ -3021,6 +3032,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
|
||||||
@@ -3028,7 +3042,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
|
||||||
@@ -3098,6 +3113,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
|
||||||
@@ -3207,7 +3223,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),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5236,7 +5255,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())
|
||||||
@@ -6424,6 +6444,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":
|
||||||
@@ -6432,6 +6453,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]]
|
||||||
|
|
||||||
|
|||||||
@@ -5947,7 +5947,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);
|
||||||
|
|
||||||
@@ -5963,7 +5963,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);
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -1434,7 +1434,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;
|
||||||
@@ -1443,7 +1443,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;
|
||||||
|
|||||||
+239
-7
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "Fetch.h"
|
#include "Fetch.h"
|
||||||
#include "FetchConsumer.h"
|
#include "FetchConsumer.h"
|
||||||
|
#include "FetchStream.h"
|
||||||
|
|
||||||
#include "nsIDocument.h"
|
#include "nsIDocument.h"
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
|
|
||||||
#include "mozilla/ErrorResult.h"
|
#include "mozilla/ErrorResult.h"
|
||||||
#include "mozilla/dom/BodyUtil.h"
|
#include "mozilla/dom/BodyUtil.h"
|
||||||
|
#include "mozilla/dom/DOMError.h"
|
||||||
#include "mozilla/dom/EncodingUtils.h"
|
#include "mozilla/dom/EncodingUtils.h"
|
||||||
#include "mozilla/dom/Exceptions.h"
|
#include "mozilla/dom/Exceptions.h"
|
||||||
#include "mozilla/dom/FetchDriver.h"
|
#include "mozilla/dom/FetchDriver.h"
|
||||||
@@ -36,6 +38,7 @@
|
|||||||
#include "mozilla/dom/Response.h"
|
#include "mozilla/dom/Response.h"
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
#include "mozilla/dom/URLSearchParams.h"
|
#include "mozilla/dom/URLSearchParams.h"
|
||||||
|
#include "mozilla/dom/WorkerPrivate.h"
|
||||||
#include "mozilla/dom/workers/ServiceWorkerManager.h"
|
#include "mozilla/dom/workers/ServiceWorkerManager.h"
|
||||||
|
|
||||||
#include "FetchObserver.h"
|
#include "FetchObserver.h"
|
||||||
@@ -840,7 +843,7 @@ ExtractFromURLSearchParams(const URLSearchParams& aParams,
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
|
ExtractByteStreamFromBody(const fetch::OwningBodyInit& aBodyInit,
|
||||||
nsIInputStream** aStream,
|
nsIInputStream** aStream,
|
||||||
nsCString& aContentType,
|
nsCString& aContentType,
|
||||||
uint64_t& aContentLength)
|
uint64_t& aContentLength)
|
||||||
@@ -878,7 +881,7 @@ ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
|
ExtractByteStreamFromBody(const fetch::BodyInit& aBodyInit,
|
||||||
nsIInputStream** aStream,
|
nsIInputStream** aStream,
|
||||||
nsCString& aContentType,
|
nsCString& aContentType,
|
||||||
uint64_t& aContentLength)
|
uint64_t& aContentLength)
|
||||||
@@ -916,9 +919,54 @@ ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUS
|
|||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit,
|
||||||
|
nsIInputStream** aStream,
|
||||||
|
nsCString& aContentType,
|
||||||
|
uint64_t& aContentLength)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aStream);
|
||||||
|
MOZ_ASSERT(!*aStream);
|
||||||
|
|
||||||
|
// ReadableStreams should be handled by
|
||||||
|
// BodyExtractorReadableStream::GetAsStream.
|
||||||
|
MOZ_ASSERT(!aBodyInit.IsReadableStream());
|
||||||
|
|
||||||
|
if (aBodyInit.IsArrayBuffer()) {
|
||||||
|
const ArrayBuffer& buf = aBodyInit.GetAsArrayBuffer();
|
||||||
|
return ExtractFromArrayBuffer(buf, aStream, aContentLength);
|
||||||
|
}
|
||||||
|
if (aBodyInit.IsArrayBufferView()) {
|
||||||
|
const ArrayBufferView& buf = aBodyInit.GetAsArrayBufferView();
|
||||||
|
return ExtractFromArrayBufferView(buf, aStream, aContentLength);
|
||||||
|
}
|
||||||
|
if (aBodyInit.IsBlob()) {
|
||||||
|
const Blob& blob = aBodyInit.GetAsBlob();
|
||||||
|
return ExtractFromBlob(blob, aStream, aContentType, aContentLength);
|
||||||
|
}
|
||||||
|
if (aBodyInit.IsFormData()) {
|
||||||
|
FormData& form = aBodyInit.GetAsFormData();
|
||||||
|
return ExtractFromFormData(form, aStream, aContentType, aContentLength);
|
||||||
|
}
|
||||||
|
if (aBodyInit.IsUSVString()) {
|
||||||
|
nsAutoString str;
|
||||||
|
str.Assign(aBodyInit.GetAsUSVString());
|
||||||
|
return ExtractFromUSVString(str, aStream, aContentType, aContentLength);
|
||||||
|
}
|
||||||
|
if (aBodyInit.IsURLSearchParams()) {
|
||||||
|
URLSearchParams& params = aBodyInit.GetAsURLSearchParams();
|
||||||
|
return ExtractFromURLSearchParams(params, aStream, aContentType, aContentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_NOTREACHED("Should never reach here");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
FetchBody<Derived>::FetchBody()
|
FetchBody<Derived>::FetchBody()
|
||||||
: mWorkerPrivate(nullptr)
|
: mWorkerPrivate(nullptr)
|
||||||
|
, mReadableStreamBody(nullptr)
|
||||||
, mBodyUsed(false)
|
, mBodyUsed(false)
|
||||||
{
|
{
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
@@ -938,9 +986,46 @@ FetchBody<Derived>::~FetchBody()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
bool
|
||||||
|
FetchBody<Derived>::BodyUsed() const
|
||||||
|
{
|
||||||
|
if (mBodyUsed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this object is disturbed or locked, return false.
|
||||||
|
if (mReadableStreamBody) {
|
||||||
|
AutoJSAPI jsapi;
|
||||||
|
// If we start tracking ownership, we need something like this.
|
||||||
|
//if (!jsapi.Init(mOwner)) {
|
||||||
|
// return true;
|
||||||
|
//}
|
||||||
|
|
||||||
|
JSContext* cx = jsapi.cx();
|
||||||
|
|
||||||
|
JS::Rooted<JSObject*> body(cx, mReadableStreamBody);
|
||||||
|
if (JS::ReadableStreamIsDisturbed(body) ||
|
||||||
|
JS::ReadableStreamIsLocked(body) ||
|
||||||
|
!JS::ReadableStreamIsReadable(body)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template
|
||||||
|
bool
|
||||||
|
FetchBody<Request>::BodyUsed() const;
|
||||||
|
|
||||||
|
template
|
||||||
|
bool
|
||||||
|
FetchBody<Response>::BodyUsed() const;
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
FetchBody<Derived>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv)
|
FetchBody<Derived>::ConsumeBody(JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
RefPtr<AbortSignal> signal = DerivedClass()->GetSignal();
|
RefPtr<AbortSignal> signal = DerivedClass()->GetSignal();
|
||||||
if (signal && signal->Aborted()) {
|
if (signal && signal->Aborted()) {
|
||||||
@@ -955,9 +1040,20 @@ FetchBody<Derived>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv)
|
|||||||
|
|
||||||
SetBodyUsed();
|
SetBodyUsed();
|
||||||
|
|
||||||
|
// If we already created a ReadableStreamBody we have to lock it now because
|
||||||
|
// it may have been shared with other objects..
|
||||||
|
if (mReadableStreamBody) {
|
||||||
|
JS::Rooted<JSObject*> body(aCx, mReadableStreamBody);
|
||||||
|
LockStream(aCx, body, aRv);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIGlobalObject> global = DerivedClass()->GetParentObject();
|
||||||
|
|
||||||
RefPtr<Promise> promise =
|
RefPtr<Promise> promise =
|
||||||
FetchBodyConsumer<Derived>::Create(DerivedClass()->GetParentObject(),
|
FetchBodyConsumer<Derived>::Create(global, this, signal, aType, aRv);
|
||||||
this, signal, aType, aRv);
|
|
||||||
if (NS_WARN_IF(aRv.Failed())) {
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -967,11 +1063,11 @@ FetchBody<Derived>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv)
|
|||||||
|
|
||||||
template
|
template
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
FetchBody<Request>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv);
|
FetchBody<Request>::ConsumeBody(JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
|
||||||
|
|
||||||
template
|
template
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
FetchBody<Response>::ConsumeBody(FetchConsumeType aType, ErrorResult& aRv);
|
FetchBody<Response>::ConsumeBody(JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
void
|
void
|
||||||
@@ -1001,5 +1097,141 @@ template
|
|||||||
void
|
void
|
||||||
FetchBody<Response>::SetMimeType();
|
FetchBody<Response>::SetMimeType();
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
void
|
||||||
|
FetchBody<Derived>::SetReadableStreamBody(JSObject* aBody)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!mReadableStreamBody);
|
||||||
|
MOZ_ASSERT(aBody);
|
||||||
|
mReadableStreamBody = aBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Request>::SetReadableStreamBody(JSObject* aBody);
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Response>::SetReadableStreamBody(JSObject* aBody);
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
void
|
||||||
|
FetchBody<Derived>::GetBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aBodyOut,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIInputStream> inputStream;
|
||||||
|
DerivedClass()->GetBody(getter_AddRefs(inputStream));
|
||||||
|
|
||||||
|
if (!inputStream) {
|
||||||
|
aBodyOut.set(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mReadableStreamBody) {
|
||||||
|
JS::Rooted<JSObject*> body(aCx,
|
||||||
|
FetchStream::Create(aCx,
|
||||||
|
DerivedClass()->GetParentObject(),
|
||||||
|
inputStream,
|
||||||
|
aRv));
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_ASSERT(body);
|
||||||
|
|
||||||
|
// If the body has been already consumed, we close the stream.
|
||||||
|
if (BodyUsed()) {
|
||||||
|
LockStream(aCx, body, aRv);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mReadableStreamBody = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
aBodyOut.set(mReadableStreamBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Request>::GetBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aMessage,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Response>::GetBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aMessage,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
void
|
||||||
|
FetchBody<Derived>::LockStream(JSContext* aCx,
|
||||||
|
JS::HandleObject aStream,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
// XXXMC: TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Request>::LockStream(JSContext* aCx,
|
||||||
|
JS::HandleObject aStream,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Response>::LockStream(JSContext* aCx,
|
||||||
|
JS::HandleObject aStream,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
void
|
||||||
|
FetchBody<Derived>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aBodyOut,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(!BodyUsed());
|
||||||
|
|
||||||
|
if (!mReadableStreamBody) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::Rooted<JSObject*> stream(aCx, mReadableStreamBody);
|
||||||
|
|
||||||
|
// If this is a ReadableStream with an external source, this has been
|
||||||
|
// generated by a Fetch. In this case, Fetch will be able to recreate it
|
||||||
|
// again when GetBody() is called.
|
||||||
|
if (JS::ReadableStreamGetMode(stream) == JS::ReadableStreamMode::ExternalSource) {
|
||||||
|
aBodyOut.set(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::Rooted<JSObject*> branch1(aCx);
|
||||||
|
JS::Rooted<JSObject*> branch2(aCx);
|
||||||
|
|
||||||
|
if (!JS::ReadableStreamTee(aCx, stream, &branch1, &branch2)) {
|
||||||
|
aRv.StealExceptionFromJSContext(aCx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mReadableStreamBody = branch1;
|
||||||
|
aBodyOut.set(branch2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Request>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aMessage,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
template
|
||||||
|
void
|
||||||
|
FetchBody<Response>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aMessage,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
+71
-18
@@ -25,9 +25,11 @@ namespace mozilla {
|
|||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
|
class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
|
||||||
|
class BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString;
|
||||||
class BlobImpl;
|
class BlobImpl;
|
||||||
class InternalRequest;
|
class InternalRequest;
|
||||||
class OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
|
class OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
|
||||||
|
struct ReadableStream;
|
||||||
class RequestOrUSVString;
|
class RequestOrUSVString;
|
||||||
|
|
||||||
namespace workers {
|
namespace workers {
|
||||||
@@ -41,13 +43,20 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
|
|||||||
nsresult
|
nsresult
|
||||||
UpdateRequestReferrer(nsIGlobalObject* aGlobal, InternalRequest* aRequest);
|
UpdateRequestReferrer(nsIGlobalObject* aGlobal, InternalRequest* aRequest);
|
||||||
|
|
||||||
|
/* Deal with unwieldy long webIDL-generated type names */
|
||||||
|
namespace fetch {
|
||||||
|
typedef ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams BodyInit;
|
||||||
|
typedef BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString ResponseBodyInit;
|
||||||
|
typedef OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams OwningBodyInit;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates an nsIInputStream based on the fetch specifications 'extract a byte
|
* Creates an nsIInputStream based on the fetch specifications 'extract a byte
|
||||||
* stream algorithm' - http://fetch.spec.whatwg.org/#concept-bodyinit-extract.
|
* stream algorithm' - http://fetch.spec.whatwg.org/#concept-bodyinit-extract.
|
||||||
* Stores content type in out param aContentType.
|
* Stores content type in out param aContentType.
|
||||||
*/
|
*/
|
||||||
nsresult
|
nsresult
|
||||||
ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
|
ExtractByteStreamFromBody(const fetch::OwningBodyInit& aBodyInit,
|
||||||
nsIInputStream** aStream,
|
nsIInputStream** aStream,
|
||||||
nsCString& aContentType,
|
nsCString& aContentType,
|
||||||
uint64_t& aContentLength);
|
uint64_t& aContentLength);
|
||||||
@@ -56,7 +65,17 @@ ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDa
|
|||||||
* Non-owning version.
|
* Non-owning version.
|
||||||
*/
|
*/
|
||||||
nsresult
|
nsresult
|
||||||
ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
|
ExtractByteStreamFromBody(const fetch::BodyInit& aBodyInit,
|
||||||
|
nsIInputStream** aStream,
|
||||||
|
nsCString& aContentType,
|
||||||
|
uint64_t& aContentLength);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Non-owning version. This method should go away when BodyInit will contain
|
||||||
|
* ReadableStream.
|
||||||
|
*/
|
||||||
|
nsresult
|
||||||
|
ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit,
|
||||||
nsIInputStream** aStream,
|
nsIInputStream** aStream,
|
||||||
nsCString& aContentType,
|
nsCString& aContentType,
|
||||||
uint64_t& aContentLength);
|
uint64_t& aContentLength);
|
||||||
@@ -72,6 +91,15 @@ enum FetchConsumeType
|
|||||||
CONSUME_TEXT,
|
CONSUME_TEXT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FetchStreamHolder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
|
||||||
|
NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
|
||||||
|
|
||||||
|
virtual void NullifyStream() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FetchBody's body consumption uses nsIInputStreamPump to read from the
|
* FetchBody's body consumption uses nsIInputStreamPump to read from the
|
||||||
* underlying stream to a block of memory, which is then adopted by
|
* underlying stream to a block of memory, which is then adopted by
|
||||||
@@ -106,47 +134,56 @@ enum FetchConsumeType
|
|||||||
* The pump is always released on the main thread.
|
* The pump is always released on the main thread.
|
||||||
*/
|
*/
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
class FetchBody
|
class FetchBody : public FetchStreamHolder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class FetchBodyConsumer<Derived>;
|
friend class FetchBodyConsumer<Derived>;
|
||||||
|
|
||||||
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
|
|
||||||
NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BodyUsed() const { return mBodyUsed; }
|
BodyUsed() const;
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
ArrayBuffer(ErrorResult& aRv)
|
ArrayBuffer(JSContext* aCx, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return ConsumeBody(CONSUME_ARRAYBUFFER, aRv);
|
return ConsumeBody(aCx, CONSUME_ARRAYBUFFER, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
Blob(ErrorResult& aRv)
|
Blob(JSContext* aCx, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return ConsumeBody(CONSUME_BLOB, aRv);
|
return ConsumeBody(aCx, CONSUME_BLOB, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
FormData(ErrorResult& aRv)
|
FormData(JSContext* aCx, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return ConsumeBody(CONSUME_FORMDATA, aRv);
|
return ConsumeBody(aCx, CONSUME_FORMDATA, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
Json(ErrorResult& aRv)
|
Json(JSContext* aCx, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return ConsumeBody(CONSUME_JSON, aRv);
|
return ConsumeBody(aCx, CONSUME_JSON, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
Text(ErrorResult& aRv)
|
Text(JSContext* aCx, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return ConsumeBody(CONSUME_TEXT, aRv);
|
return ConsumeBody(aCx, CONSUME_TEXT, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GetBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aBodyOut,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
// If the body contains a ReadableStream body object, this method produces a
|
||||||
|
// tee() of it.
|
||||||
|
void
|
||||||
|
MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JSObject*> aBodyOut,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
// Utility public methods accessed by various runnables.
|
// Utility public methods accessed by various runnables.
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -161,6 +198,12 @@ public:
|
|||||||
return mMimeType;
|
return mMimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NullifyStream() override
|
||||||
|
{
|
||||||
|
mReadableStreamBody = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
virtual AbortSignal*
|
virtual AbortSignal*
|
||||||
GetSignal() const = 0;
|
GetSignal() const = 0;
|
||||||
|
|
||||||
@@ -170,10 +213,17 @@ protected:
|
|||||||
// Always set whenever the FetchBody is created on the worker thread.
|
// Always set whenever the FetchBody is created on the worker thread.
|
||||||
workers::WorkerPrivate* mWorkerPrivate;
|
workers::WorkerPrivate* mWorkerPrivate;
|
||||||
|
|
||||||
|
// This is the ReadableStream exposed to content. Its underlying source is a FetchStream object.
|
||||||
|
JS::Heap<JSObject*> mReadableStreamBody;
|
||||||
|
|
||||||
virtual ~FetchBody();
|
virtual ~FetchBody();
|
||||||
|
|
||||||
void
|
void
|
||||||
SetMimeType();
|
SetMimeType();
|
||||||
|
|
||||||
|
void
|
||||||
|
SetReadableStreamBody(JSObject* aBody);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Derived*
|
Derived*
|
||||||
DerivedClass() const
|
DerivedClass() const
|
||||||
@@ -182,7 +232,10 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Promise>
|
already_AddRefed<Promise>
|
||||||
ConsumeBody(FetchConsumeType aType, ErrorResult& aRv);
|
ConsumeBody(JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
|
||||||
|
|
||||||
|
void
|
||||||
|
LockStream(JSContext* aCx, JS::HandleObject aStream, ErrorResult& aRv);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
IsOnTargetThread()
|
IsOnTargetThread()
|
||||||
|
|||||||
@@ -0,0 +1,553 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#include "FetchStream.h"
|
||||||
|
#include "nsNetCID.h"
|
||||||
|
#include "nsITransport.h"
|
||||||
|
#include "nsIStreamTransportService.h"
|
||||||
|
#include "nsProxyRelease.h"
|
||||||
|
#include "WorkerPrivate.h"
|
||||||
|
#include "WorkerRunnable.h"
|
||||||
|
#include "Workers.h"
|
||||||
|
|
||||||
|
#include "mozilla/dom/DOMError.h"
|
||||||
|
|
||||||
|
#define FETCH_STREAM_FLAG 0
|
||||||
|
|
||||||
|
static NS_DEFINE_CID(kStreamTransportServiceCID,
|
||||||
|
NS_STREAMTRANSPORTSERVICE_CID);
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
using namespace workers;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class FetchStreamWorkerHolder final : public WorkerHolder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FetchStreamWorkerHolder(FetchStream* aStream)
|
||||||
|
: WorkerHolder()
|
||||||
|
, mStream(aStream)
|
||||||
|
, mWasNotified(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool Notify(Status aStatus) override
|
||||||
|
{
|
||||||
|
if (!mWasNotified) {
|
||||||
|
mWasNotified = true;
|
||||||
|
mStream->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkerPrivate* GetWorkerPrivate() const
|
||||||
|
{
|
||||||
|
return mWorkerPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefPtr<FetchStream> mStream;
|
||||||
|
bool mWasNotified;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FetchStreamWorkerHolderShutdown final : public WorkerControlRunnable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FetchStreamWorkerHolderShutdown(WorkerPrivate* aWorkerPrivate,
|
||||||
|
UniquePtr<WorkerHolder>&& aHolder,
|
||||||
|
nsCOMPtr<nsIGlobalObject>&& aGlobal,
|
||||||
|
RefPtr<FetchStreamHolder>&& aStreamHolder)
|
||||||
|
: WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
|
||||||
|
, mHolder(Move(aHolder))
|
||||||
|
, mGlobal(Move(aGlobal))
|
||||||
|
, mStreamHolder(Move(aStreamHolder))
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool
|
||||||
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
||||||
|
{
|
||||||
|
mHolder = nullptr;
|
||||||
|
mGlobal = nullptr;
|
||||||
|
|
||||||
|
mStreamHolder->NullifyStream();
|
||||||
|
mStreamHolder = nullptr;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This runnable starts from a JS Thread. We need to disable a couple of
|
||||||
|
// assertions by overriding the following methods.
|
||||||
|
|
||||||
|
bool
|
||||||
|
PreDispatch(WorkerPrivate* aWorkerPrivate) override
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
|
||||||
|
{}
|
||||||
|
|
||||||
|
private:
|
||||||
|
UniquePtr<WorkerHolder> mHolder;
|
||||||
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||||
|
RefPtr<FetchStreamHolder> mStreamHolder;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(FetchStream, nsIInputStreamCallback, nsIObserver,
|
||||||
|
nsISupportsWeakReference)
|
||||||
|
|
||||||
|
/* static */ JSObject*
|
||||||
|
FetchStream::Create(JSContext* aCx, FetchStreamHolder* aStreamHolder,
|
||||||
|
nsIGlobalObject* aGlobal, nsIInputStream* aInputStream,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aCx);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aInputStream);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aStreamHolder);
|
||||||
|
|
||||||
|
RefPtr<FetchStream> stream = new FetchStream(aGlobal, aStreamHolder, aInputStream);
|
||||||
|
|
||||||
|
if (NS_IsMainThread()) {
|
||||||
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||||
|
if (NS_WARN_IF(!os)) {
|
||||||
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
aRv = os->AddObserver(stream, DOM_WINDOW_DESTROYED_TOPIC, true);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||||
|
MOZ_ASSERT(workerPrivate);
|
||||||
|
|
||||||
|
UniquePtr<FetchStreamWorkerHolder> holder(
|
||||||
|
new FetchStreamWorkerHolder(stream));
|
||||||
|
if (NS_WARN_IF(!holder->HoldWorker(workerPrivate, Closing))) {
|
||||||
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note, this will create a ref-cycle between the holder and the stream.
|
||||||
|
// The cycle is broken when the stream is closed or the worker begins
|
||||||
|
// shutting down.
|
||||||
|
stream->mWorkerHolder = Move(holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!JS::HasReadableStreamCallbacks(aCx)) {
|
||||||
|
JS::SetReadableStreamCallbacks(aCx,
|
||||||
|
&FetchStream::RequestDataCallback,
|
||||||
|
&FetchStream::WriteIntoReadRequestCallback,
|
||||||
|
&FetchStream::CancelCallback,
|
||||||
|
&FetchStream::ClosedCallback,
|
||||||
|
&FetchStream::ErroredCallback,
|
||||||
|
&FetchStream::FinalizeCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::Rooted<JSObject*> body(aCx,
|
||||||
|
JS::NewReadableExternalSourceStreamObject(aCx, stream, FETCH_STREAM_FLAG));
|
||||||
|
if (!body) {
|
||||||
|
aRv.StealExceptionFromJSContext(aCx);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->mReadableStream = body;
|
||||||
|
|
||||||
|
// JS engine will call the finalize callback.
|
||||||
|
NS_ADDREF(stream.get());
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void
|
||||||
|
FetchStream::RequestDataCallback(JSContext* aCx,
|
||||||
|
JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource,
|
||||||
|
uint8_t aFlags,
|
||||||
|
size_t aDesiredSize)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aUnderlyingSource);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aFlags == FETCH_STREAM_FLAG);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(JS::ReadableStreamIsDisturbed(aStream));
|
||||||
|
|
||||||
|
RefPtr<FetchStream> stream = static_cast<FetchStream*>(aUnderlyingSource);
|
||||||
|
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(stream->mState == eWaiting ||
|
||||||
|
stream->mState == eChecking);
|
||||||
|
|
||||||
|
if (stream->mState == eChecking) {
|
||||||
|
// If we are looking for more data, there is nothing else we should do:
|
||||||
|
// let's move this checking operation in a reading.
|
||||||
|
MOZ_ASSERT(stream->mInputStream);
|
||||||
|
stream->mState = eReading;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->mState = eReading;
|
||||||
|
|
||||||
|
if (!stream->mInputStream) {
|
||||||
|
// This is the first use of the stream. Let's convert the
|
||||||
|
// mOriginalInputStream into an nsIAsyncInputStream.
|
||||||
|
MOZ_ASSERT(stream->mOriginalInputStream);
|
||||||
|
|
||||||
|
bool nonBlocking = false;
|
||||||
|
nsresult rv = stream->mOriginalInputStream->IsNonBlocking(&nonBlocking);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIAsyncInputStream> asyncStream =
|
||||||
|
do_QueryInterface(stream->mOriginalInputStream);
|
||||||
|
if (!nonBlocking || !asyncStream) {
|
||||||
|
nsCOMPtr<nsIStreamTransportService> sts =
|
||||||
|
do_GetService(kStreamTransportServiceCID, &rv);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsITransport> transport;
|
||||||
|
rv = sts->CreateInputTransport(stream->mOriginalInputStream,
|
||||||
|
/* aStartOffset */ 0,
|
||||||
|
/* aReadLimit */ -1,
|
||||||
|
/* aCloseWhenDone */ true,
|
||||||
|
getter_AddRefs(transport));
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIInputStream> wrapper;
|
||||||
|
rv = transport->OpenInputStream(/* aFlags */ 0,
|
||||||
|
/* aSegmentSize */ 0,
|
||||||
|
/* aSegmentCount */ 0,
|
||||||
|
getter_AddRefs(wrapper));
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
asyncStream = do_QueryInterface(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->mInputStream = asyncStream;
|
||||||
|
stream->mOriginalInputStream = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(stream->mInputStream);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(!stream->mOriginalInputStream);
|
||||||
|
|
||||||
|
nsresult rv =
|
||||||
|
stream->mInputStream->AsyncWait(stream, 0, 0, stream->mOwningEventTarget);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// All good.
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void
|
||||||
|
FetchStream::WriteIntoReadRequestCallback(JSContext* aCx,
|
||||||
|
JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource,
|
||||||
|
uint8_t aFlags, void* aBuffer,
|
||||||
|
size_t aLength, size_t* aByteWritten)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aUnderlyingSource);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aFlags == FETCH_STREAM_FLAG);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aBuffer);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aByteWritten);
|
||||||
|
|
||||||
|
RefPtr<FetchStream> stream = static_cast<FetchStream*>(aUnderlyingSource);
|
||||||
|
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(stream->mInputStream);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(stream->mState == eWriting);
|
||||||
|
stream->mState = eChecking;
|
||||||
|
|
||||||
|
uint32_t written;
|
||||||
|
nsresult rv =
|
||||||
|
stream->mInputStream->Read(static_cast<char*>(aBuffer), aLength, &written);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aByteWritten = written;
|
||||||
|
|
||||||
|
if (written == 0) {
|
||||||
|
stream->CloseAndReleaseObjects(aCx, aStream);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = stream->mInputStream->AsyncWait(stream, 0, 0, stream->mOwningEventTarget);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
stream->ErrorPropagation(aCx, aStream, rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// All good.
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ JS::Value
|
||||||
|
FetchStream::CancelCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags,
|
||||||
|
JS::HandleValue aReason)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aUnderlyingSource);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aFlags == FETCH_STREAM_FLAG);
|
||||||
|
|
||||||
|
RefPtr<FetchStream> stream = static_cast<FetchStream*>(aUnderlyingSource);
|
||||||
|
|
||||||
|
if (stream->mInputStream) {
|
||||||
|
stream->mInputStream->CloseWithStatus(NS_BASE_STREAM_CLOSED);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->ReleaseObjects();
|
||||||
|
|
||||||
|
return JS::UndefinedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void
|
||||||
|
FetchStream::ClosedCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aUnderlyingSource);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aFlags == FETCH_STREAM_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void
|
||||||
|
FetchStream::ErroredCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags,
|
||||||
|
JS::HandleValue aReason)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aUnderlyingSource);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aFlags == FETCH_STREAM_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FetchStream::FinalizeCallback(void* aUnderlyingSource, uint8_t aFlags)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aUnderlyingSource);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aFlags == FETCH_STREAM_FLAG);
|
||||||
|
|
||||||
|
// This can be called in any thread.
|
||||||
|
|
||||||
|
RefPtr<FetchStream> stream =
|
||||||
|
dont_AddRef(static_cast<FetchStream*>(aUnderlyingSource));
|
||||||
|
|
||||||
|
stream->ReleaseObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
FetchStream::FetchStream(nsIGlobalObject* aGlobal,
|
||||||
|
FetchStreamHolder* aStreamHolder,
|
||||||
|
nsIInputStream* aInputStream)
|
||||||
|
: mState(eWaiting)
|
||||||
|
, mGlobal(aGlobal)
|
||||||
|
, mStreamHolder(aStreamHolder)
|
||||||
|
, mOriginalInputStream(aInputStream)
|
||||||
|
, mOwningEventTarget(nullptr)
|
||||||
|
, mReadableStream(nullptr)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aInputStream);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aStreamHolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
FetchStream::~FetchStream()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FetchStream::ErrorPropagation(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
nsresult aError)
|
||||||
|
{
|
||||||
|
// Nothing to do.
|
||||||
|
if (mState == eClosed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's close the stream.
|
||||||
|
if (aError == NS_BASE_STREAM_CLOSED) {
|
||||||
|
CloseAndReleaseObjects(aCx, aStream);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
|
||||||
|
|
||||||
|
// Let's use a generic error.
|
||||||
|
RefPtr<DOMError> error = new DOMError(window, NS_ERROR_DOM_TYPE_ERR);
|
||||||
|
|
||||||
|
JS::Rooted<JS::Value> errorValue(aCx);
|
||||||
|
if (ToJSValue(aCx, error, &errorValue)) {
|
||||||
|
JS::ReadableStreamError(aCx, aStream, errorValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
FetchStream::OnInputStreamReady(nsIAsyncInputStream* aStream)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(aStream);
|
||||||
|
|
||||||
|
// Already closed. We have nothing else to do here.
|
||||||
|
if (mState == eClosed) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(mInputStream);
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(mState == eReading || mState == eChecking);
|
||||||
|
|
||||||
|
AutoJSAPI jsapi;
|
||||||
|
if (NS_WARN_IF(!jsapi.Init(mGlobal))) {
|
||||||
|
// Without JSContext we are not able to close the stream or to propagate the
|
||||||
|
// error.
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSContext* cx = jsapi.cx();
|
||||||
|
JS::Rooted<JSObject*> stream(cx, mReadableStream);
|
||||||
|
|
||||||
|
uint64_t size = 0;
|
||||||
|
nsresult rv = mInputStream->Available(&size);
|
||||||
|
if (NS_SUCCEEDED(rv) && size == 0) {
|
||||||
|
// In theory this should not happen. If size is 0, the stream should be
|
||||||
|
// considered closed.
|
||||||
|
rv = NS_BASE_STREAM_CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No warning for stream closed.
|
||||||
|
if (rv == NS_BASE_STREAM_CLOSED || NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
ErrorPropagation(cx, stream, rv);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This extra checking is completed. Let's wait for the next read request.
|
||||||
|
if (mState == eChecking) {
|
||||||
|
mState = eWaiting;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mState = eWriting;
|
||||||
|
JS::ReadableStreamUpdateDataAvailableFromSource(cx, stream, size);
|
||||||
|
|
||||||
|
// The WriteInto callback changes mState to eChecking.
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(mState == eChecking);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ nsresult
|
||||||
|
FetchStream::RetrieveInputStream(void* aUnderlyingReadableStreamSource,
|
||||||
|
nsIInputStream** aInputStream)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aUnderlyingReadableStreamSource);
|
||||||
|
MOZ_ASSERT(aInputStream);
|
||||||
|
|
||||||
|
RefPtr<FetchStream> stream =
|
||||||
|
static_cast<FetchStream*>(aUnderlyingReadableStreamSource);
|
||||||
|
|
||||||
|
// if mOriginalInputStream is null, the reading already started. We don't want
|
||||||
|
// to expose the internal inputStream.
|
||||||
|
if (NS_WARN_IF(!stream->mOriginalInputStream)) {
|
||||||
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIInputStream> inputStream = stream->mOriginalInputStream;
|
||||||
|
inputStream.forget(aInputStream);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FetchStream::Close()
|
||||||
|
{
|
||||||
|
if (mState == eClosed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoJSAPI jsapi;
|
||||||
|
if (NS_WARN_IF(!jsapi.Init(mGlobal))) {
|
||||||
|
ReleaseObjects();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSContext* cx = jsapi.cx();
|
||||||
|
JS::Rooted<JSObject*> stream(cx, mReadableStream);
|
||||||
|
|
||||||
|
CloseAndReleaseObjects(cx, stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FetchStream::CloseAndReleaseObjects(JSContext* aCx, JS::HandleObject aStream)
|
||||||
|
{
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(mState != eClosed);
|
||||||
|
|
||||||
|
ReleaseObjects();
|
||||||
|
|
||||||
|
if (JS::ReadableStreamIsReadable(aStream)) {
|
||||||
|
JS::ReadableStreamClose(aCx, aStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FetchStream::ReleaseObjects()
|
||||||
|
{
|
||||||
|
if (mState == eClosed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mState = eClosed;
|
||||||
|
|
||||||
|
if (mWorkerHolder) {
|
||||||
|
RefPtr<FetchStreamWorkerHolderShutdown> r =
|
||||||
|
new FetchStreamWorkerHolderShutdown(
|
||||||
|
static_cast<FetchStreamWorkerHolder*>(mWorkerHolder.get())->GetWorkerPrivate(),
|
||||||
|
Move(mWorkerHolder), Move(mGlobal), Move(mStreamHolder));
|
||||||
|
r->Dispatch();
|
||||||
|
} else {
|
||||||
|
RefPtr<FetchStream> self = this;
|
||||||
|
RefPtr<Runnable> r = NS_NewRunnableFunction(
|
||||||
|
[self] () {
|
||||||
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||||
|
if (os) {
|
||||||
|
os->RemoveObserver(self, DOM_WINDOW_DESTROYED_TOPIC);
|
||||||
|
}
|
||||||
|
self->mGlobal = nullptr;
|
||||||
|
|
||||||
|
self->mStreamHolder->NullifyStream();
|
||||||
|
self->mStreamHolder = nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
|
NS_DispatchToMainThread(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// nsIObserver
|
||||||
|
// -----------
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
FetchStream::Observe(nsISupports* aSubject, const char* aTopic,
|
||||||
|
const char16_t* aData)
|
||||||
|
{
|
||||||
|
AssertIsOnMainThread();
|
||||||
|
|
||||||
|
MOZ_ASSERT(strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0);
|
||||||
|
|
||||||
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
|
||||||
|
if (SameCOMIdentity(aSubject, window)) {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // dom namespace
|
||||||
|
} // mozilla namespace
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* 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_FetchStream_h
|
||||||
|
#define mozilla_dom_FetchStream_h
|
||||||
|
|
||||||
|
#include "Fetch.h"
|
||||||
|
#include "jsapi.h"
|
||||||
|
#include "nsIAsyncInputStream.h"
|
||||||
|
#include "nsIObserver.h"
|
||||||
|
#include "nsISupportsImpl.h"
|
||||||
|
#include "nsWeakReference.h"
|
||||||
|
|
||||||
|
class nsIGlobalObject;
|
||||||
|
|
||||||
|
class nsIInputStream;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
namespace workers {
|
||||||
|
class WorkerHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FetchStreamHolder;
|
||||||
|
|
||||||
|
class FetchStream final : public nsIInputStreamCallback
|
||||||
|
, public nsIObserver
|
||||||
|
, public nsSupportsWeakReference
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
||||||
|
NS_DECL_NSIOBSERVER
|
||||||
|
|
||||||
|
static JSObject*
|
||||||
|
Create(JSContext* aCx, FetchStreamHolder* aStreamHolder,
|
||||||
|
nsIGlobalObject* aGlobal, nsIInputStream* aInputStream,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
void
|
||||||
|
Close();
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
RetrieveInputStream(void* aUnderlyingReadableStreamSource,
|
||||||
|
nsIInputStream** aInputStream);
|
||||||
|
private:
|
||||||
|
FetchStream(nsIGlobalObject* aGlobal,
|
||||||
|
FetchStreamHolder* aStreamHolder,
|
||||||
|
nsIInputStream* aInputStream);
|
||||||
|
~FetchStream();
|
||||||
|
|
||||||
|
static void
|
||||||
|
RequestDataCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags,
|
||||||
|
size_t aDesiredSize);
|
||||||
|
|
||||||
|
static void
|
||||||
|
WriteIntoReadRequestCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags,
|
||||||
|
void* aBuffer, size_t aLength,
|
||||||
|
size_t* aByteWritten);
|
||||||
|
|
||||||
|
static JS::Value
|
||||||
|
CancelCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags,
|
||||||
|
JS::HandleValue aReason);
|
||||||
|
|
||||||
|
static void
|
||||||
|
ClosedCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags);
|
||||||
|
|
||||||
|
static void
|
||||||
|
ErroredCallback(JSContext* aCx, JS::HandleObject aStream,
|
||||||
|
void* aUnderlyingSource, uint8_t aFlags,
|
||||||
|
JS::HandleValue reason);
|
||||||
|
|
||||||
|
static void
|
||||||
|
FinalizeCallback(void* aUnderlyingSource, uint8_t aFlags);
|
||||||
|
|
||||||
|
void
|
||||||
|
ErrorPropagation(JSContext* aCx, JS::HandleObject aStream, nsresult aRv);
|
||||||
|
|
||||||
|
void
|
||||||
|
CloseAndReleaseObjects(JSContext* aCx, JS::HandleObject aStream);
|
||||||
|
|
||||||
|
void
|
||||||
|
ReleaseObjects();
|
||||||
|
|
||||||
|
// Common methods
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
// RequestDataCallback has not been called yet. We haven't started to read
|
||||||
|
// data from the stream yet.
|
||||||
|
eWaiting,
|
||||||
|
|
||||||
|
// We are reading data in a separate I/O thread.
|
||||||
|
eReading,
|
||||||
|
|
||||||
|
// We are ready to write something in the JS Buffer.
|
||||||
|
eWriting,
|
||||||
|
|
||||||
|
// After a writing, we want to check if the stream is closed. After the
|
||||||
|
// check, we go back to eWaiting. If a reading request happens in the
|
||||||
|
// meantime, we move to eReading state.
|
||||||
|
eChecking,
|
||||||
|
|
||||||
|
// Operation completed.
|
||||||
|
eClosed,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Touched only on the target thread.
|
||||||
|
State mState;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||||
|
RefPtr<FetchStreamHolder> mStreamHolder;
|
||||||
|
nsCOMPtr<nsIEventTarget> mOwningEventTarget;
|
||||||
|
|
||||||
|
// This is the original inputStream received during the CTOR. It will be
|
||||||
|
// converted into an nsIAsyncInputStream and stored into mInputStream at the
|
||||||
|
// first use.
|
||||||
|
nsCOMPtr<nsIInputStream> mOriginalInputStream;
|
||||||
|
nsCOMPtr<nsIAsyncInputStream> mInputStream;
|
||||||
|
|
||||||
|
UniquePtr<workers::WorkerHolder> mWorkerHolder;
|
||||||
|
|
||||||
|
JS::Heap<JSObject*> mReadableStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // dom namespace
|
||||||
|
} // mozilla namespace
|
||||||
|
|
||||||
|
#endif // mozilla_dom_FetchStream_h
|
||||||
+18
-1
@@ -29,7 +29,24 @@ using namespace workers;
|
|||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Request)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Request)
|
||||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Request)
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Request)
|
||||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Request, mOwner, mHeaders)
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Request)
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Request)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHeaders)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Request)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHeaders)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Request)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReadableStreamBody)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||||
|
|
||||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Request)
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Request)
|
||||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ public:
|
|||||||
void
|
void
|
||||||
GetBody(nsIInputStream** aStream) { return mRequest->GetBody(aStream); }
|
GetBody(nsIInputStream** aStream) { return mRequest->GetBody(aStream); }
|
||||||
|
|
||||||
|
using FetchBody::GetBody;
|
||||||
|
|
||||||
void
|
void
|
||||||
SetBody(nsIInputStream* aStream) { return mRequest->SetBody(aStream); }
|
SetBody(nsIInputStream* aStream) { return mRequest->SetBody(aStream); }
|
||||||
|
|
||||||
|
|||||||
+110
-11
@@ -12,12 +12,14 @@
|
|||||||
|
|
||||||
#include "mozilla/ErrorResult.h"
|
#include "mozilla/ErrorResult.h"
|
||||||
#include "mozilla/dom/FetchBinding.h"
|
#include "mozilla/dom/FetchBinding.h"
|
||||||
|
#include "mozilla/dom/ResponseBinding.h"
|
||||||
#include "mozilla/dom/Headers.h"
|
#include "mozilla/dom/Headers.h"
|
||||||
#include "mozilla/dom/Promise.h"
|
#include "mozilla/dom/Promise.h"
|
||||||
#include "mozilla/dom/URL.h"
|
#include "mozilla/dom/URL.h"
|
||||||
|
|
||||||
#include "nsDOMString.h"
|
#include "nsDOMString.h"
|
||||||
|
|
||||||
|
#include "FetchStream.h"
|
||||||
#include "InternalResponse.h"
|
#include "InternalResponse.h"
|
||||||
#include "WorkerPrivate.h"
|
#include "WorkerPrivate.h"
|
||||||
|
|
||||||
@@ -26,7 +28,27 @@ namespace dom {
|
|||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Response)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Response)
|
||||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Response)
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Response)
|
||||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Response, mOwner, mHeaders)
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Response)
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Response)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHeaders)
|
||||||
|
|
||||||
|
tmp->mReadableStreamBody = nullptr;
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Response)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHeaders)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Response)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReadableStreamBody)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||||
|
|
||||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Response)
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Response)
|
||||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
@@ -42,10 +64,14 @@ Response::Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse
|
|||||||
MOZ_ASSERT(aInternalResponse->Headers()->Guard() == HeadersGuardEnum::Immutable ||
|
MOZ_ASSERT(aInternalResponse->Headers()->Guard() == HeadersGuardEnum::Immutable ||
|
||||||
aInternalResponse->Headers()->Guard() == HeadersGuardEnum::Response);
|
aInternalResponse->Headers()->Guard() == HeadersGuardEnum::Response);
|
||||||
SetMimeType();
|
SetMimeType();
|
||||||
|
|
||||||
|
// Keep a firm grip!
|
||||||
|
mozilla::HoldJSObjects(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::~Response()
|
Response::~Response()
|
||||||
{
|
{
|
||||||
|
mozilla::DropJSObjects(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ already_AddRefed<Response>
|
/* static */ already_AddRefed<Response>
|
||||||
@@ -105,7 +131,7 @@ Response::Redirect(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Nullable<ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>> body;
|
Optional<Nullable<fetch::ResponseBodyInit>> body;
|
||||||
ResponseInit init;
|
ResponseInit init;
|
||||||
init.mStatus = aStatus;
|
init.mStatus = aStatus;
|
||||||
RefPtr<Response> r = Response::Constructor(aGlobal, body, init, aRv);
|
RefPtr<Response> r = Response::Constructor(aGlobal, body, init, aRv);
|
||||||
@@ -126,7 +152,7 @@ Response::Redirect(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|||||||
|
|
||||||
/*static*/ already_AddRefed<Response>
|
/*static*/ already_AddRefed<Response>
|
||||||
Response::Constructor(const GlobalObject& aGlobal,
|
Response::Constructor(const GlobalObject& aGlobal,
|
||||||
const Optional<Nullable<ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>>& aBody,
|
const Optional<Nullable<fetch::ResponseBodyInit>>& aBody,
|
||||||
const ResponseInit& aInit, ErrorResult& aRv)
|
const ResponseInit& aInit, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||||
@@ -201,13 +227,56 @@ Response::Constructor(const GlobalObject& aGlobal,
|
|||||||
nsCOMPtr<nsIInputStream> bodyStream;
|
nsCOMPtr<nsIInputStream> bodyStream;
|
||||||
nsCString contentType;
|
nsCString contentType;
|
||||||
uint64_t bodySize = 0;
|
uint64_t bodySize = 0;
|
||||||
aRv = ExtractByteStreamFromBody(aBody.Value().Value(),
|
|
||||||
getter_AddRefs(bodyStream),
|
if (aBody.Value().IsReadableStream()) {
|
||||||
contentType,
|
const ReadableStream& readableStream =
|
||||||
bodySize);
|
aBody.Value().GetAsReadableStream();
|
||||||
if (NS_WARN_IF(aRv.Failed())) {
|
|
||||||
return nullptr;
|
JS::Rooted<JSObject*> readableStreamObj(aGlobal.Context(),
|
||||||
|
readableStream.Obj());
|
||||||
|
|
||||||
|
if (JS::ReadableStreamIsDisturbed(readableStreamObj) ||
|
||||||
|
JS::ReadableStreamIsLocked(readableStreamObj) ||
|
||||||
|
!JS::ReadableStreamIsReadable(readableStreamObj)) {
|
||||||
|
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
r->SetReadableStreamBody(readableStreamObj);
|
||||||
|
|
||||||
|
// XXXMC: TODO
|
||||||
|
MOZ_ASSERT(JS::ReadableStreamGetMode(readableStreamObj) !=
|
||||||
|
JS::ReadableStreamMode::ExternalSource);
|
||||||
|
|
||||||
|
void* underlyingSource = nullptr;
|
||||||
|
if (!JS::ReadableStreamGetExternalUnderlyingSource(aGlobal.Context(),
|
||||||
|
readableStreamObj,
|
||||||
|
&underlyingSource)) {
|
||||||
|
aRv.StealExceptionFromJSContext(aGlobal.Context());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bodySize = InternalResponse::UNKNOWN_BODY_SIZE;
|
||||||
|
|
||||||
|
MOZ_ASSERT(underlyingSource);
|
||||||
|
aRv = FetchStream::RetrieveInputStream(underlyingSource,
|
||||||
|
getter_AddRefs(bodyStream));
|
||||||
|
|
||||||
|
// Releasing of the external source is needed in order to avoid an extra stream lock.
|
||||||
|
JS::ReadableStreamReleaseExternalUnderlyingSource(readableStreamObj);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
aRv = ExtractByteStreamFromBody(aBody.Value().Value(),
|
||||||
|
getter_AddRefs(bodyStream),
|
||||||
|
contentType,
|
||||||
|
bodySize);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internalResponse->SetBody(bodyStream, bodySize);
|
internalResponse->SetBody(bodyStream, bodySize);
|
||||||
|
|
||||||
if (!contentType.IsVoid() &&
|
if (!contentType.IsVoid() &&
|
||||||
@@ -228,7 +297,7 @@ Response::Constructor(const GlobalObject& aGlobal,
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Response>
|
already_AddRefed<Response>
|
||||||
Response::Clone(ErrorResult& aRv) const
|
Response::Clone(JSContext* aCx, ErrorResult& aRv) const
|
||||||
{
|
{
|
||||||
if (BodyUsed()) {
|
if (BodyUsed()) {
|
||||||
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
|
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
|
||||||
@@ -237,11 +306,26 @@ Response::Clone(ErrorResult& aRv) const
|
|||||||
|
|
||||||
RefPtr<InternalResponse> ir = mInternalResponse->Clone();
|
RefPtr<InternalResponse> ir = mInternalResponse->Clone();
|
||||||
RefPtr<Response> response = new Response(mOwner, ir, mSignal);
|
RefPtr<Response> response = new Response(mOwner, ir, mSignal);
|
||||||
|
|
||||||
|
JS::Rooted<JSObject*> body(aCx);
|
||||||
|
MaybeTeeReadableStreamBody(aCx, &body, aRv);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
// Maybe we have a body, but we receive null from MaybeTeeReadableStreamBody
|
||||||
|
// if this body is a native stream. In this case, the InternalResponse will
|
||||||
|
// have a clone of the native body and the ReadableStream will be created
|
||||||
|
// lazily if needed.
|
||||||
|
response->SetReadableStreamBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
return response.forget();
|
return response.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Response>
|
already_AddRefed<Response>
|
||||||
Response::CloneUnfiltered(ErrorResult& aRv) const
|
Response::CloneUnfiltered(JSContext* aCx, ErrorResult& aRv) const
|
||||||
{
|
{
|
||||||
if (BodyUsed()) {
|
if (BodyUsed()) {
|
||||||
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
|
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
|
||||||
@@ -251,6 +335,21 @@ Response::CloneUnfiltered(ErrorResult& aRv) const
|
|||||||
RefPtr<InternalResponse> clone = mInternalResponse->Clone();
|
RefPtr<InternalResponse> clone = mInternalResponse->Clone();
|
||||||
RefPtr<InternalResponse> ir = clone->Unfiltered();
|
RefPtr<InternalResponse> ir = clone->Unfiltered();
|
||||||
RefPtr<Response> ref = new Response(mOwner, ir, mSignal);
|
RefPtr<Response> ref = new Response(mOwner, ir, mSignal);
|
||||||
|
|
||||||
|
JS::Rooted<JSObject*> body(aCx);
|
||||||
|
MaybeTeeReadableStreamBody(aCx, &body, aRv);
|
||||||
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
// Maybe we have a body, but we receive null from MaybeTeeReadableStreamBody
|
||||||
|
// if this body is a native stream. In this case, the InternalResponse will
|
||||||
|
// have a clone of the native body and the ReadableStream will be created
|
||||||
|
// lazily if needed.
|
||||||
|
ref->SetReadableStreamBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
return ref.forget();
|
return ref.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ public:
|
|||||||
void
|
void
|
||||||
GetBody(nsIInputStream** aStream) { return mInternalResponse->GetBody(aStream); }
|
GetBody(nsIInputStream** aStream) { return mInternalResponse->GetBody(aStream); }
|
||||||
|
|
||||||
|
using FetchBody::GetBody;
|
||||||
|
|
||||||
static already_AddRefed<Response>
|
static already_AddRefed<Response>
|
||||||
Error(const GlobalObject& aGlobal);
|
Error(const GlobalObject& aGlobal);
|
||||||
|
|
||||||
@@ -113,7 +115,7 @@ public:
|
|||||||
|
|
||||||
static already_AddRefed<Response>
|
static already_AddRefed<Response>
|
||||||
Constructor(const GlobalObject& aGlobal,
|
Constructor(const GlobalObject& aGlobal,
|
||||||
const Optional<Nullable<ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>>& aBody,
|
const Optional<Nullable<fetch::ResponseBodyInit>>& aBody,
|
||||||
const ResponseInit& aInit, ErrorResult& rv);
|
const ResponseInit& aInit, ErrorResult& rv);
|
||||||
|
|
||||||
nsIGlobalObject* GetParentObject() const
|
nsIGlobalObject* GetParentObject() const
|
||||||
@@ -122,10 +124,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<Response>
|
already_AddRefed<Response>
|
||||||
Clone(ErrorResult& aRv) const;
|
Clone(JSContext* aCx, ErrorResult& aRv) const;
|
||||||
|
|
||||||
already_AddRefed<Response>
|
already_AddRefed<Response>
|
||||||
CloneUnfiltered(ErrorResult& aRv) const;
|
CloneUnfiltered(JSContext* aCx, ErrorResult& aRv) const;
|
||||||
|
|
||||||
void
|
void
|
||||||
SetBody(nsIInputStream* aBody, int64_t aBodySize);
|
SetBody(nsIInputStream* aBody, int64_t aBodySize);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ SOURCES += [
|
|||||||
'ChannelInfo.cpp',
|
'ChannelInfo.cpp',
|
||||||
'FetchDriver.cpp',
|
'FetchDriver.cpp',
|
||||||
'FetchObserver.cpp',
|
'FetchObserver.cpp',
|
||||||
|
'FetchStream.cpp',
|
||||||
'FetchUtil.cpp',
|
'FetchUtil.cpp',
|
||||||
'Headers.cpp',
|
'Headers.cpp',
|
||||||
'InternalHeaders.cpp',
|
'InternalHeaders.cpp',
|
||||||
|
|||||||
@@ -296,7 +296,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);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
typedef object JSON;
|
typedef object JSON;
|
||||||
typedef (ArrayBuffer or ArrayBufferView or Blob or FormData or USVString or URLSearchParams) BodyInit;
|
typedef (ArrayBuffer or ArrayBufferView or Blob or FormData or USVString or URLSearchParams) BodyInit;
|
||||||
|
typedef (Blob or ArrayBufferView or ArrayBuffer or FormData or URLSearchParams or ReadableStream or USVString) ResponseBodyInit;
|
||||||
|
|
||||||
[NoInterfaceObject, Exposed=(Window,Worker)]
|
[NoInterfaceObject, Exposed=(Window,Worker)]
|
||||||
interface Body {
|
interface Body {
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
* https://fetch.spec.whatwg.org/#response-class
|
* https://fetch.spec.whatwg.org/#response-class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[Constructor(optional BodyInit? body, optional ResponseInit init),
|
// This should be Constructor(optional BodyInit... but BodyInit doesn't include
|
||||||
|
// ReadableStream yet because we don't want to expose the Streams API to Request.
|
||||||
|
[Constructor(optional ResponseBodyInit? body, optional ResponseInit init),
|
||||||
Exposed=(Window,Worker)]
|
Exposed=(Window,Worker)]
|
||||||
interface Response {
|
interface Response {
|
||||||
[NewObject] static Response error();
|
[NewObject] static Response error();
|
||||||
@@ -30,6 +32,12 @@ interface Response {
|
|||||||
};
|
};
|
||||||
Response implements Body;
|
Response implements Body;
|
||||||
|
|
||||||
|
// This should be part of Body but we don't want to expose body to request yet.
|
||||||
|
partial interface Response {
|
||||||
|
[GetterThrows, Func="nsContentUtils::StreamsEnabled"]
|
||||||
|
readonly attribute ReadableStream? body;
|
||||||
|
};
|
||||||
|
|
||||||
dictionary ResponseInit {
|
dictionary ResponseInit {
|
||||||
unsigned short status = 200;
|
unsigned short status = 200;
|
||||||
ByteString statusText = "OK";
|
ByteString statusText = "OK";
|
||||||
|
|||||||
@@ -299,6 +299,7 @@ LoadContextOptions(const char* aPrefName, void* /* aClosure */)
|
|||||||
.setNativeRegExp(GetWorkerPref<bool>(NS_LITERAL_CSTRING("native_regexp")))
|
.setNativeRegExp(GetWorkerPref<bool>(NS_LITERAL_CSTRING("native_regexp")))
|
||||||
.setAsyncStack(GetWorkerPref<bool>(NS_LITERAL_CSTRING("asyncstack")))
|
.setAsyncStack(GetWorkerPref<bool>(NS_LITERAL_CSTRING("asyncstack")))
|
||||||
.setWerror(GetWorkerPref<bool>(NS_LITERAL_CSTRING("werror")))
|
.setWerror(GetWorkerPref<bool>(NS_LITERAL_CSTRING("werror")))
|
||||||
|
.setStreams(GetWorkerPref<bool>(NS_LITERAL_CSTRING("streams")))
|
||||||
.setExtraWarnings(GetWorkerPref<bool>(NS_LITERAL_CSTRING("strict")))
|
.setExtraWarnings(GetWorkerPref<bool>(NS_LITERAL_CSTRING("strict")))
|
||||||
.setArrayProtoValues(GetWorkerPref<bool>(
|
.setArrayProtoValues(GetWorkerPref<bool>(
|
||||||
NS_LITERAL_CSTRING("array_prototype_values")));
|
NS_LITERAL_CSTRING("array_prototype_values")));
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEn
|
|||||||
WORKER_SIMPLE_PREF("dom.serviceWorkers.openWindow.enabled", OpenWindowEnabled, OPEN_WINDOW_ENABLED)
|
WORKER_SIMPLE_PREF("dom.serviceWorkers.openWindow.enabled", OpenWindowEnabled, OPEN_WINDOW_ENABLED)
|
||||||
WORKER_SIMPLE_PREF("dom.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)
|
WORKER_SIMPLE_PREF("dom.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)
|
||||||
WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
|
WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
|
||||||
|
WORKER_SIMPLE_PREF("dom.streams.enabled", StreamsEnabled, STREAMS_ENABLED)
|
||||||
WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
|
WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
|
||||||
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
|
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
|
||||||
WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
|
WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
|
||||||
|
|||||||
@@ -2830,7 +2830,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);
|
||||||
|
|||||||
@@ -0,0 +1,510 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
* 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/. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JSAPI functions and callbacks related to WHATWG Stream objects.
|
||||||
|
*
|
||||||
|
* Much of the API here mirrors the JS API of ReadableStream and associated
|
||||||
|
* classes, e.g. ReadableStreamDefaultReader, ReadableStreamBYOBReader,
|
||||||
|
* ReadableStreamDefaultController, ReadableByteStreamController, and
|
||||||
|
* ReadableStreamBYOBRequest.
|
||||||
|
*
|
||||||
|
* There are some crucial differences, though: Functionality that's exposed
|
||||||
|
* as methods/accessors on controllers in JS is exposed as functions taking
|
||||||
|
* ReadableStream instances instead. This is because an analysis of how
|
||||||
|
* the API would be used showed that all functions that'd take controllers
|
||||||
|
* would do so by first getting the controller from the stream instance it's
|
||||||
|
* associated with and then call the function taking it. I.e., it would purely
|
||||||
|
* add boilerplate without any gains in ease of use of the API.
|
||||||
|
*
|
||||||
|
* Some functions exposed here deal with ReadableStream instances that have an
|
||||||
|
* embedding-provided underlying source. These instances are largely similar
|
||||||
|
* to byte streams as created using |new ReadableStream({type: "bytes"})|:
|
||||||
|
* They enable users to acquire ReadableStreamBYOBReaders and only vend chunks
|
||||||
|
* that're typed array instances.
|
||||||
|
*
|
||||||
|
* When creating an "external readable stream" using
|
||||||
|
* JS::NewReadableExternalSourceStreamObject, an underlying source and a set
|
||||||
|
* of flags can be passed to be stored on the stream. The underlying source is
|
||||||
|
* treated as an opaque void* pointer by the JS engine: it's purely meant as
|
||||||
|
* a reference to be used by the embedding to identify whatever actual source
|
||||||
|
* it uses to supply data for the stream. Similarly, the flags aren't
|
||||||
|
* interpreted by the JS engine, but are passed to some of the callbacks below
|
||||||
|
* and can be retrieved using JS::ReadableStreamGetEmbeddingFlags.
|
||||||
|
*
|
||||||
|
* External readable streams are optimized to allow the embedding to interact
|
||||||
|
* with them with a minimum of overhead: chunks aren't enqueued as individual
|
||||||
|
* typed array instances; instead, the embedding only updates the amount of
|
||||||
|
* data available using ReadableStreamUpdateDataAvailableFromSource.
|
||||||
|
* When content requests data by reading from a reader,
|
||||||
|
* WriteIntoReadRequestBufferCallback is invoked, asking the embedding to
|
||||||
|
* write data directly into the buffer we're about to hand to content.
|
||||||
|
*
|
||||||
|
* Additionally, ReadableStreamGetExternalUnderlyingSource can be used to
|
||||||
|
* get the void* pointer to the underlying source. This is equivalent to
|
||||||
|
* acquiring a reader for the stream in that it locks the stream until it
|
||||||
|
* is released again using JS::ReadableStreamReleaseExternalUnderlyingSource.
|
||||||
|
*
|
||||||
|
* Embeddings are expected to detect situations where an API exposed to JS
|
||||||
|
* takes a ReadableStream to read from that has an external underlying source.
|
||||||
|
* In those situations, it might be preferable to directly perform data
|
||||||
|
* transfers from the stream's underlying source to whatever sink the
|
||||||
|
* embedding uses, assuming that such direct transfers can be performed
|
||||||
|
* more efficiently.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef js_Stream_h
|
||||||
|
#define js_Stream_h
|
||||||
|
|
||||||
|
#include "jstypes.h"
|
||||||
|
|
||||||
|
#include "js/TypeDecls.h"
|
||||||
|
|
||||||
|
namespace JS {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked whenever a reader desires more data from a ReadableStream's
|
||||||
|
* embedding-provided underlying source.
|
||||||
|
*
|
||||||
|
* The given |desiredSize| is the absolute size, not a delta from the previous
|
||||||
|
* desired size.
|
||||||
|
*/
|
||||||
|
typedef void
|
||||||
|
(* RequestReadableStreamDataCallback)(JSContext* cx, HandleObject stream,
|
||||||
|
void* underlyingSource, uint8_t flags, size_t desiredSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked to cause the embedding to fill the given |buffer| with data from
|
||||||
|
* the given embedding-provided underlying source.
|
||||||
|
*
|
||||||
|
* This can only happen after the embedding has updated the amount of data
|
||||||
|
* available using JS::ReadableStreamUpdateDataAvailableFromSource. If at
|
||||||
|
* least one read request is pending when
|
||||||
|
* JS::ReadableStreamUpdateDataAvailableFromSource is called,
|
||||||
|
* the WriteIntoReadRequestBufferCallback is invoked immediately from under
|
||||||
|
* the call to JS::WriteIntoReadRequestBufferCallback. If not, it is invoked
|
||||||
|
* if and when a new read request is made.
|
||||||
|
*
|
||||||
|
* Note: This callback *must not cause GC*, because that could potentially
|
||||||
|
* invalidate the |buffer| pointer.
|
||||||
|
*/
|
||||||
|
typedef void
|
||||||
|
(* WriteIntoReadRequestBufferCallback)(JSContext* cx, HandleObject stream,
|
||||||
|
void* underlyingSource, uint8_t flags, void* buffer,
|
||||||
|
size_t length, size_t* bytesWritten);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked in reaction to the ReadableStream being canceled to allow the
|
||||||
|
* embedding to free the underlying source.
|
||||||
|
*
|
||||||
|
* This is equivalent to calling |cancel| on non-external underlying sources
|
||||||
|
* provided to the ReadableStream constructor in JavaScript.
|
||||||
|
*
|
||||||
|
* The given |reason| is the JS::Value that was passed as an argument to
|
||||||
|
* ReadableStream#cancel().
|
||||||
|
*
|
||||||
|
* The returned JS::Value will be used to resolve the Promise returned by
|
||||||
|
* ReadableStream#cancel().
|
||||||
|
*/
|
||||||
|
typedef Value
|
||||||
|
(* CancelReadableStreamCallback)(JSContext* cx, HandleObject stream,
|
||||||
|
void* underlyingSource, uint8_t flags, HandleValue reason);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked in reaction to a ReadableStream with an embedding-provided
|
||||||
|
* underlying source being closed.
|
||||||
|
*/
|
||||||
|
typedef void
|
||||||
|
(* ReadableStreamClosedCallback)(JSContext* cx, HandleObject stream, void* underlyingSource,
|
||||||
|
uint8_t flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked in reaction to a ReadableStream with an embedding-provided
|
||||||
|
* underlying source being errored with the
|
||||||
|
* given reason.
|
||||||
|
*/
|
||||||
|
typedef void
|
||||||
|
(* ReadableStreamErroredCallback)(JSContext* cx, HandleObject stream, void* underlyingSource,
|
||||||
|
uint8_t flags, HandleValue reason);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked in reaction to a ReadableStream with an embedding-provided
|
||||||
|
* underlying source being finalized. Only the underlying source is passed
|
||||||
|
* as an argument, while the ReadableStream itself is not to prevent the
|
||||||
|
* embedding from operating on a JSObject that might not be in a valid state
|
||||||
|
* anymore.
|
||||||
|
*
|
||||||
|
* Note: the ReadableStream might be finalized on a background thread. That
|
||||||
|
* means this callback might be invoked from an arbitrary thread, which the
|
||||||
|
* embedding must be able to handle.
|
||||||
|
*/
|
||||||
|
typedef void
|
||||||
|
(* ReadableStreamFinalizeCallback)(void* underlyingSource, uint8_t flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets runtime-wide callbacks to use for interacting with embedding-provided
|
||||||
|
* hooks for operating on ReadableStream instances.
|
||||||
|
*
|
||||||
|
* See the documentation for the individual callback types for details.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(void)
|
||||||
|
SetReadableStreamCallbacks(JSContext* cx,
|
||||||
|
RequestReadableStreamDataCallback dataRequestCallback,
|
||||||
|
WriteIntoReadRequestBufferCallback writeIntoReadRequestCallback,
|
||||||
|
CancelReadableStreamCallback cancelCallback,
|
||||||
|
ReadableStreamClosedCallback closedCallback,
|
||||||
|
ReadableStreamErroredCallback erroredCallback,
|
||||||
|
ReadableStreamFinalizeCallback finalizeCallback);
|
||||||
|
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
HasReadableStreamCallbacks(JSContext* cx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new instance of the ReadableStream builtin class in the current
|
||||||
|
* compartment, configured as a default stream.
|
||||||
|
* If a |proto| is passed, that gets set as the instance's [[Prototype]]
|
||||||
|
* instead of the original value of |ReadableStream.prototype|.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
NewReadableDefaultStreamObject(JSContext* cx, HandleObject underlyingSource = nullptr,
|
||||||
|
HandleFunction size = nullptr, double highWaterMark = 1,
|
||||||
|
HandleObject proto = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new instance of the ReadableStream builtin class in the current
|
||||||
|
* compartment, configured as a byte stream.
|
||||||
|
* If a |proto| is passed, that gets set as the instance's [[Prototype]]
|
||||||
|
* instead of the original value of |ReadableStream.prototype|.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
NewReadableByteStreamObject(JSContext* cx, HandleObject underlyingSource = nullptr,
|
||||||
|
double highWaterMark = 0, HandleObject proto = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new instance of the ReadableStream builtin class in the current
|
||||||
|
* compartment, with the right slot layout. If a |proto| is passed, that gets
|
||||||
|
* set as the instance's [[Prototype]] instead of the original value of
|
||||||
|
* |ReadableStream.prototype|.
|
||||||
|
*
|
||||||
|
* The instance is optimized for operating as a byte stream backed by an
|
||||||
|
* embedding-provided underlying source, using the callbacks set via
|
||||||
|
* |JS::SetReadableStreamCallbacks|.
|
||||||
|
*
|
||||||
|
* The given |flags| will be passed to all applicable callbacks and can be
|
||||||
|
* used to disambiguate between different types of stream sources the
|
||||||
|
* embedding might support.
|
||||||
|
*
|
||||||
|
* Note: the embedding is responsible for ensuring that the pointer to the
|
||||||
|
* underlying source stays valid as long as the stream can be read from.
|
||||||
|
* The underlying source can be freed if the tree is canceled or errored.
|
||||||
|
* It can also be freed if the stream is destroyed. The embedding is notified
|
||||||
|
* of that using ReadableStreamFinalizeCallback.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
NewReadableExternalSourceStreamObject(JSContext* cx, void* underlyingSource,
|
||||||
|
uint8_t flags = 0, HandleObject proto = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the flags that were passed to NewReadableExternalSourceStreamObject
|
||||||
|
* when creating the given stream.
|
||||||
|
*
|
||||||
|
* Asserts that the given stream has an embedding-provided underlying source.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(uint8_t)
|
||||||
|
ReadableStreamGetEmbeddingFlags(const JSObject* stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the embedding-provided underlying source of the given |stream|.
|
||||||
|
*
|
||||||
|
* Can be used to optimize operations if both the underlying source and the
|
||||||
|
* intended sink are embedding-provided. In that case it might be
|
||||||
|
* preferrable to pipe data directly from source to sink without interacting
|
||||||
|
* with the stream at all.
|
||||||
|
*
|
||||||
|
* Locks the stream until ReadableStreamReleaseExternalUnderlyingSource is
|
||||||
|
* called.
|
||||||
|
*
|
||||||
|
* Throws an exception if the stream is locked, i.e. if a reader has been
|
||||||
|
* acquired for the stream, or if ReadableStreamGetExternalUnderlyingSource
|
||||||
|
* has been used previously without releasing the external source again.
|
||||||
|
*
|
||||||
|
* Throws an exception if the stream isn't readable, i.e if it is errored or
|
||||||
|
* closed. This is different from ReadableStreamGetReader because we don't
|
||||||
|
* have a Promise to resolve/reject, which a reader provides.
|
||||||
|
*
|
||||||
|
* Asserts that the stream has an embedding-provided underlying source.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamGetExternalUnderlyingSource(JSContext* cx, HandleObject stream, void** source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the embedding-provided underlying source of the given |stream|,
|
||||||
|
* returning the stream into an unlocked state.
|
||||||
|
*
|
||||||
|
* Asserts that the stream was locked through
|
||||||
|
* ReadableStreamGetExternalUnderlyingSource.
|
||||||
|
*
|
||||||
|
* Asserts that the stream has an embedding-provided underlying source.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(void)
|
||||||
|
ReadableStreamReleaseExternalUnderlyingSource(JSObject* stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the amount of data available at the underlying source of the given
|
||||||
|
* |stream|.
|
||||||
|
*
|
||||||
|
* Can only be used for streams with an embedding-provided underlying source.
|
||||||
|
* The JS engine will use the given value to satisfy read requests for the
|
||||||
|
* stream by invoking the JS::WriteIntoReadRequestBuffer callback.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamUpdateDataAvailableFromSource(JSContext* cx, HandleObject stream,
|
||||||
|
uint32_t availableData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given object is an unwrapped ReadableStream object,
|
||||||
|
* false otherwise.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
IsReadableStream(const JSObject* obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given object is an unwrapped
|
||||||
|
* ReadableStreamDefaultReader or ReadableStreamBYOBReader object,
|
||||||
|
* false otherwise.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
IsReadableStreamReader(const JSObject* obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given object is an unwrapped
|
||||||
|
* ReadableStreamDefaultReader object, false otherwise.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
IsReadableStreamDefaultReader(const JSObject* obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given object is an unwrapped
|
||||||
|
* ReadableStreamBYOBReader object, false otherwise.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
IsReadableStreamBYOBReader(const JSObject* obj);
|
||||||
|
|
||||||
|
enum class ReadableStreamMode {
|
||||||
|
Default,
|
||||||
|
Byte,
|
||||||
|
ExternalSource
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the stream's ReadableStreamMode. If the mode is |Byte| or
|
||||||
|
* |ExternalSource|, it's possible to acquire a BYOB reader for more optimized
|
||||||
|
* operations.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(ReadableStreamMode)
|
||||||
|
ReadableStreamGetMode(const JSObject* stream);
|
||||||
|
|
||||||
|
enum class ReadableStreamReaderMode {
|
||||||
|
Default,
|
||||||
|
BYOB
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given ReadableStream is readable, false if not.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamIsReadable(const JSObject* stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given ReadableStream is locked, false if not.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamIsLocked(const JSObject* stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given ReadableStream is disturbed, false if not.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamIsDisturbed(const JSObject* stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the given ReadableStream with the given reason and returns a
|
||||||
|
* Promise resolved according to the result.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
ReadableStreamCancel(JSContext* cx, HandleObject stream, HandleValue reason);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a reader of the type specified by the mode option and locks the
|
||||||
|
* stream to the new reader.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
ReadableStreamGetReader(JSContext* cx, HandleObject stream, ReadableStreamReaderMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tees the given ReadableStream and stores the two resulting streams in
|
||||||
|
* outparams. Returns false if the operation fails, e.g. because the stream is
|
||||||
|
* locked.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamTee(JSContext* cx, HandleObject stream,
|
||||||
|
MutableHandleObject branch1Stream, MutableHandleObject branch2Stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the desired combined size of additional chunks to fill the given
|
||||||
|
* ReadableStream's queue. Stores the result in |value| and sets |hasValue| to
|
||||||
|
* true on success, returns false on failure.
|
||||||
|
*
|
||||||
|
* If the stream is errored, the call will succeed but no value will be stored
|
||||||
|
* in |value| and |hasValue| will be set to false.
|
||||||
|
*
|
||||||
|
* Note: This is semantically equivalent to the |desiredSize| getter on
|
||||||
|
* the stream controller's prototype in JS. We expose it with the stream
|
||||||
|
* itself as a target for simplicity.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(void)
|
||||||
|
ReadableStreamGetDesiredSize(JSObject* stream, bool* hasValue, double* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the given ReadableStream.
|
||||||
|
*
|
||||||
|
* Throws a TypeError and returns false if the closing operation fails.
|
||||||
|
*
|
||||||
|
* Note: This is semantically equivalent to the |close| method on
|
||||||
|
* the stream controller's prototype in JS. We expose it with the stream
|
||||||
|
* itself as a target for simplicity.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamClose(JSContext* cx, HandleObject stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given ReadableStream reader is locked, false otherwise.
|
||||||
|
*
|
||||||
|
* Asserts that |reader| is an unwrapped ReadableStreamDefaultReader or
|
||||||
|
* ReadableStreamBYOBReader instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamReaderIsClosed(const JSObject* reader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues the given chunk in the given ReadableStream.
|
||||||
|
*
|
||||||
|
* Throws a TypeError and returns false if the enqueing operation fails.
|
||||||
|
*
|
||||||
|
* Note: This is semantically equivalent to the |enqueue| method on
|
||||||
|
* the stream controller's prototype in JS. We expose it with the stream
|
||||||
|
* itself as a target for simplicity.
|
||||||
|
*
|
||||||
|
* If the ReadableStream has an underlying byte source, the given chunk must
|
||||||
|
* be a typed array or a DataView. Consider using
|
||||||
|
* ReadableByteStreamEnqueueBuffer.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamEnqueue(JSContext* cx, HandleObject stream, HandleValue chunk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues the given buffer as a chunk in the given ReadableStream.
|
||||||
|
*
|
||||||
|
* Throws a TypeError and returns false if the enqueing operation fails.
|
||||||
|
*
|
||||||
|
* Note: This is semantically equivalent to the |enqueue| method on
|
||||||
|
* the stream controller's prototype in JS. We expose it with the stream
|
||||||
|
* itself as a target for simplicity. Additionally, the JS version only
|
||||||
|
* takes typed arrays and ArrayBufferView instances as arguments, whereas
|
||||||
|
* this takes an ArrayBuffer, obviating the need to wrap it into a typed
|
||||||
|
* array.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance and |buffer|
|
||||||
|
* an unwrapped ArrayBuffer instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableByteStreamEnqueueBuffer(JSContext* cx, HandleObject stream, HandleObject buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Errors the given ReadableStream, causing all future interactions to fail
|
||||||
|
* with the given error value.
|
||||||
|
*
|
||||||
|
* Throws a TypeError and returns false if the erroring operation fails.
|
||||||
|
*
|
||||||
|
* Note: This is semantically equivalent to the |error| method on
|
||||||
|
* the stream controller's prototype in JS. We expose it with the stream
|
||||||
|
* itself as a target for simplicity.
|
||||||
|
*
|
||||||
|
* Asserts that |stream| is an unwrapped ReadableStream instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamError(JSContext* cx, HandleObject stream, HandleValue error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the given ReadableStream reader's associated stream.
|
||||||
|
*
|
||||||
|
* Throws a TypeError and returns false if the given reader isn't active.
|
||||||
|
*
|
||||||
|
* Asserts that |reader| is an unwrapped ReadableStreamDefaultReader or
|
||||||
|
* ReadableStreamBYOBReader instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamReaderCancel(JSContext* cx, HandleObject reader, HandleValue reason);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the given ReadableStream reader's associated stream.
|
||||||
|
*
|
||||||
|
* Throws a TypeError and returns false if the given reader has pending
|
||||||
|
* read or readInto (for default or byob readers, respectively) requests.
|
||||||
|
*
|
||||||
|
* Asserts that |reader| is an unwrapped ReadableStreamDefaultReader or
|
||||||
|
* ReadableStreamBYOBReader instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(bool)
|
||||||
|
ReadableStreamReaderReleaseLock(JSContext* cx, HandleObject reader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests a read from the reader's associated ReadableStream and returns the
|
||||||
|
* resulting PromiseObject.
|
||||||
|
*
|
||||||
|
* Returns a Promise that's resolved with the read result once available or
|
||||||
|
* rejected immediately if the stream is errored or the operation failed.
|
||||||
|
*
|
||||||
|
* Asserts that |reader| is an unwrapped ReadableStreamDefaultReader instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
ReadableStreamDefaultReaderRead(JSContext* cx, HandleObject reader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests a read from the reader's associated ReadableStream into the given
|
||||||
|
* ArrayBufferView and returns the resulting PromiseObject.
|
||||||
|
*
|
||||||
|
* Returns a Promise that's resolved with the read result once available or
|
||||||
|
* rejected immediately if the stream is errored or the operation failed.
|
||||||
|
*
|
||||||
|
* Asserts that |reader| is an unwrapped ReadableStreamDefaultReader and
|
||||||
|
* |view| an unwrapped typed array or DataView instance.
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API(JSObject*)
|
||||||
|
ReadableStreamBYOBReaderRead(JSContext* cx, HandleObject reader, HandleObject view);
|
||||||
|
|
||||||
|
} // namespace JS
|
||||||
|
|
||||||
|
#endif // js_Realm_h
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,170 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
* 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 builtin_Stream_h
|
||||||
|
#define builtin_Stream_h
|
||||||
|
|
||||||
|
#include "builtin/Promise.h"
|
||||||
|
#include "vm/NativeObject.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace js {
|
||||||
|
|
||||||
|
class AutoSetNewObjectMetadata;
|
||||||
|
|
||||||
|
class ReadableStream : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ReadableStream* createDefaultStream(JSContext* cx, HandleValue underlyingSource,
|
||||||
|
HandleValue size, HandleValue highWaterMark,
|
||||||
|
HandleObject proto = nullptr);
|
||||||
|
static ReadableStream* createByteStream(JSContext* cx, HandleValue underlyingSource,
|
||||||
|
HandleValue highWaterMark,
|
||||||
|
HandleObject proto = nullptr);
|
||||||
|
static ReadableStream* createExternalSourceStream(JSContext* cx, void* underlyingSource,
|
||||||
|
uint8_t flags, HandleObject proto = nullptr);
|
||||||
|
|
||||||
|
bool readable() const;
|
||||||
|
bool closed() const;
|
||||||
|
bool errored() const;
|
||||||
|
bool disturbed() const;
|
||||||
|
|
||||||
|
bool locked() const;
|
||||||
|
|
||||||
|
void desiredSize(bool* hasSize, double* size) const;
|
||||||
|
|
||||||
|
JS::ReadableStreamMode mode() const;
|
||||||
|
|
||||||
|
static MOZ_MUST_USE bool close(JSContext* cx, Handle<ReadableStream*> stream);
|
||||||
|
static MOZ_MUST_USE JSObject* cancel(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
|
HandleValue reason);
|
||||||
|
static MOZ_MUST_USE bool error(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
|
HandleValue error);
|
||||||
|
|
||||||
|
static MOZ_MUST_USE NativeObject* getReader(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
|
JS::ReadableStreamReaderMode mode);
|
||||||
|
|
||||||
|
static MOZ_MUST_USE bool tee(JSContext* cx,
|
||||||
|
Handle<ReadableStream*> stream, bool cloneForBranch2,
|
||||||
|
MutableHandle<ReadableStream*> branch1Stream,
|
||||||
|
MutableHandle<ReadableStream*> branch2Stream);
|
||||||
|
|
||||||
|
static MOZ_MUST_USE bool enqueue(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
|
HandleValue chunk);
|
||||||
|
static MOZ_MUST_USE bool enqueueBuffer(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
|
Handle<ArrayBufferObject*> chunk);
|
||||||
|
static MOZ_MUST_USE bool getExternalSource(JSContext* cx, Handle<ReadableStream*> stream,
|
||||||
|
void** source);
|
||||||
|
void releaseExternalSource();
|
||||||
|
uint8_t embeddingFlags() const;
|
||||||
|
static MOZ_MUST_USE bool updateDataAvailableFromSource(JSContext* cx,
|
||||||
|
Handle<ReadableStream*> stream,
|
||||||
|
uint32_t availableData);
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
Readable = 1 << 0,
|
||||||
|
Closed = 1 << 1,
|
||||||
|
Errored = 1 << 2,
|
||||||
|
Disturbed = 1 << 3
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
static MOZ_MUST_USE ReadableStream* createStream(JSContext* cx, HandleObject proto = nullptr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReadableStreamDefaultReader : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static MOZ_MUST_USE JSObject* read(JSContext* cx, Handle<ReadableStreamDefaultReader*> reader);
|
||||||
|
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReadableStreamBYOBReader : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static MOZ_MUST_USE JSObject* read(JSContext* cx, Handle<ReadableStreamBYOBReader*> reader,
|
||||||
|
Handle<ArrayBufferViewObject*> view);
|
||||||
|
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ReadableStreamReaderIsClosed(const JSObject* reader);
|
||||||
|
|
||||||
|
MOZ_MUST_USE bool ReadableStreamReaderCancel(JSContext* cx, HandleObject reader,
|
||||||
|
HandleValue reason);
|
||||||
|
|
||||||
|
MOZ_MUST_USE bool ReadableStreamReaderReleaseLock(JSContext* cx, HandleObject reader);
|
||||||
|
|
||||||
|
class ReadableStreamDefaultController : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReadableByteStreamController : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool hasExternalSource();
|
||||||
|
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReadableStreamBYOBRequest : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ByteLengthQueuingStrategy : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CountQueuingStrategy : public NativeObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool constructor(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
static const Class class_;
|
||||||
|
static const ClassSpec protoClassSpec_;
|
||||||
|
static const Class protoClass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace js
|
||||||
|
|
||||||
|
#endif /* builtin_Stream_h */
|
||||||
@@ -1435,6 +1435,14 @@ RejectPromise(JSContext* cx, unsigned argc, Value* vp)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
StreamsAreEnabled(JSContext* cx, unsigned argc, Value* vp)
|
||||||
|
{
|
||||||
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
args.rval().setBoolean(cx->options().streams());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned finalizeCount = 0;
|
static unsigned finalizeCount = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -4172,6 +4180,10 @@ JS_FN_HELP("rejectPromise", RejectPromise, 2, 0,
|
|||||||
"rejectPromise(promise, reason)",
|
"rejectPromise(promise, reason)",
|
||||||
" Reject a Promise by calling the JSAPI function JS::RejectPromise."),
|
" Reject a Promise by calling the JSAPI function JS::RejectPromise."),
|
||||||
|
|
||||||
|
JS_FN_HELP("streamsAreEnabled", StreamsAreEnabled, 0, 0,
|
||||||
|
"streamsAreEnabled()",
|
||||||
|
" Returns a boolean indicating whether WHATWG Streams are enabled for the current compartment."),
|
||||||
|
|
||||||
JS_FN_HELP("makeFinalizeObserver", MakeFinalizeObserver, 0, 0,
|
JS_FN_HELP("makeFinalizeObserver", MakeFinalizeObserver, 0, 0,
|
||||||
"makeFinalizeObserver()",
|
"makeFinalizeObserver()",
|
||||||
" Get a special object whose finalization increases the counter returned\n"
|
" Get a special object whose finalization increases the counter returned\n"
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "TypedObjectConstants.h"
|
|
||||||
|
|
||||||
function ViewedArrayBufferIfReified(tarray) {
|
function ViewedArrayBufferIfReified(tarray) {
|
||||||
assert(IsTypedArray(tarray), "non-typed array asked for its buffer");
|
assert(IsTypedArray(tarray), "non-typed array asked for its buffer");
|
||||||
|
|
||||||
@@ -1633,7 +1631,7 @@ function ArrayBufferSlice(start, end) {
|
|||||||
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
|
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
|
||||||
|
|
||||||
// Steps 19-21.
|
// Steps 19-21.
|
||||||
ArrayBufferCopyData(new_, O, first | 0, newLen | 0, isWrapped);
|
ArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);
|
||||||
|
|
||||||
// Step 22.
|
// Step 22.
|
||||||
return new_;
|
return new_;
|
||||||
@@ -1715,7 +1713,7 @@ function SharedArrayBufferSlice(start, end) {
|
|||||||
ThrowTypeError(JSMSG_SHORT_SHARED_ARRAY_BUFFER_RETURNED, newLen, actualLen);
|
ThrowTypeError(JSMSG_SHORT_SHARED_ARRAY_BUFFER_RETURNED, newLen, actualLen);
|
||||||
|
|
||||||
// Steps 16-18.
|
// Steps 16-18.
|
||||||
SharedArrayBufferCopyData(new_, O, first | 0, newLen | 0, isWrapped);
|
SharedArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);
|
||||||
|
|
||||||
// Step 19.
|
// Step 19.
|
||||||
return new_;
|
return new_;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SelfHostingDefines.h"
|
#include "SelfHostingDefines.h"
|
||||||
|
#include "TypedObjectConstants.h"
|
||||||
|
|
||||||
// Assertions and debug printing, defined here instead of in the header above
|
// Assertions and debug printing, defined here instead of in the header above
|
||||||
// to make `assert` invisible to C++.
|
// to make `assert` invisible to C++.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ SOURCES += [
|
|||||||
'ReflectParse.cpp',
|
'ReflectParse.cpp',
|
||||||
'RegExp.cpp',
|
'RegExp.cpp',
|
||||||
'SIMD.cpp',
|
'SIMD.cpp',
|
||||||
|
'Stream.cpp',
|
||||||
'SymbolObject.cpp',
|
'SymbolObject.cpp',
|
||||||
'TestingFunctions.cpp',
|
'TestingFunctions.cpp',
|
||||||
'TypedObject.cpp',
|
'TypedObject.cpp',
|
||||||
|
|||||||
+29
-1
@@ -593,7 +593,35 @@ MSG_DEF(JSMSG_RETURN_NOT_CALLABLE, 0, JSEXN_TYPEERR, "property 'return' of i
|
|||||||
MSG_DEF(JSMSG_ITERATOR_NO_THROW, 0, JSEXN_TYPEERR, "iterator does not have a 'throw' method")
|
MSG_DEF(JSMSG_ITERATOR_NO_THROW, 0, JSEXN_TYPEERR, "iterator does not have a 'throw' method")
|
||||||
|
|
||||||
// Async Iteration
|
// Async Iteration
|
||||||
MSG_DEF(JSMSG_FOR_AWAIT_NOT_OF, 0, JSEXN_TYPEERR, "'for await' loop should be used with 'of'")
|
MSG_DEF(JSMSG_FOR_AWAIT_NOT_OF, 0, JSEXN_SYNTAXERR, "'for await' loop should be used with 'of'")
|
||||||
MSG_DEF(JSMSG_NOT_AN_ASYNC_GENERATOR, 0, JSEXN_TYPEERR, "Not an async generator")
|
MSG_DEF(JSMSG_NOT_AN_ASYNC_GENERATOR, 0, JSEXN_TYPEERR, "Not an async generator")
|
||||||
MSG_DEF(JSMSG_NOT_AN_ASYNC_ITERATOR, 0, JSEXN_TYPEERR, "Not an async from sync iterator")
|
MSG_DEF(JSMSG_NOT_AN_ASYNC_ITERATOR, 0, JSEXN_TYPEERR, "Not an async from sync iterator")
|
||||||
MSG_DEF(JSMSG_GET_ASYNC_ITER_RETURNED_PRIMITIVE, 0, JSEXN_TYPEERR, "[Symbol.asyncIterator]() returned a non-object value")
|
MSG_DEF(JSMSG_GET_ASYNC_ITER_RETURNED_PRIMITIVE, 0, JSEXN_TYPEERR, "[Symbol.asyncIterator]() returned a non-object value")
|
||||||
|
|
||||||
|
// ReadableStream
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_UNDERLYINGSOURCE_TYPE_WRONG,0, JSEXN_RANGEERR,"'underlyingSource.type' must be \"bytes\" or undefined.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_INVALID_READER_MODE, 0, JSEXN_RANGEERR,"'mode' must be \"byob\" or undefined.")
|
||||||
|
MSG_DEF(JSMSG_NUMBER_MUST_BE_FINITE_NON_NEGATIVE, 1, JSEXN_RANGEERR, "'{0}' must be a finite, non-negative number.")
|
||||||
|
MSG_DEF(JSMSG_READABLEBYTESTREAMCONTROLLER_INVALID_BYTESWRITTEN, 0, JSEXN_RANGEERR, "'bytesWritten' exceeds remaining length.")
|
||||||
|
MSG_DEF(JSMSG_READABLEBYTESTREAMCONTROLLER_INVALID_VIEW_SIZE, 0, JSEXN_RANGEERR, "view size does not match requested data.")
|
||||||
|
MSG_DEF(JSMSG_READABLEBYTESTREAMCONTROLLER_INVALID_VIEW_OFFSET, 0, JSEXN_RANGEERR, "view offset does not match requested position.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_NOT_LOCKED, 1, JSEXN_TYPEERR, "'{0}' may only be called on a locked stream.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_LOCKED, 0, JSEXN_TYPEERR, "A Reader may only be created for an unlocked ReadableStream.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_NOT_BYTE_STREAM_CONTROLLER, 1, JSEXN_TYPEERR, "{0} requires a ReadableByteStreamController.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_NOT_DEFAULT_CONTROLLER, 1, JSEXN_TYPEERR, "{0} requires a ReadableStreamDefaultController.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_CONTROLLER_SET, 0, JSEXN_TYPEERR, "The ReadableStream already has a controller defined.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMREADER_NOT_OWNED, 1, JSEXN_TYPEERR, "The ReadableStream reader method '{0}' may only be called on a reader owned by a stream.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMREADER_NOT_EMPTY, 1, JSEXN_TYPEERR, "The ReadableStream reader method '{0}' may not be called on a reader with read requests.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMBYOBREADER_READ_EMPTY_VIEW, 0, JSEXN_TYPEERR, "ReadableStreamBYOBReader.read() was passed an empty TypedArrayBuffer view.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMREADER_RELEASED, 0, JSEXN_TYPEERR, "The ReadableStream reader was released.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMCONTROLLER_CLOSED, 1, JSEXN_TYPEERR, "'{0}' called on a stream already closing.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMCONTROLLER_NOT_READABLE, 1, JSEXN_TYPEERR, "'{0}' may only be called on a stream in the 'readable' state.")
|
||||||
|
MSG_DEF(JSMSG_READABLEBYTESTREAMCONTROLLER_BAD_CHUNKSIZE,0, JSEXN_RANGEERR, "ReadableByteStreamController requires a positive integer or undefined for 'autoAllocateChunkSize'.")
|
||||||
|
MSG_DEF(JSMSG_READABLEBYTESTREAMCONTROLLER_BAD_CHUNK, 1, JSEXN_TYPEERR, "{0} passed a bad chunk.")
|
||||||
|
MSG_DEF(JSMSG_READABLEBYTESTREAMCONTROLLER_CLOSE_PENDING_PULL, 0, JSEXN_TYPEERR, "The ReadableByteStreamController cannot be closed while the buffer is being filled.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMBYOBREQUEST_NO_CONTROLLER, 1, JSEXN_TYPEERR, "ReadableStreamBYOBRequest method '{0}' called on a request with no controller.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAMBYOBREQUEST_RESPOND_CLOSED, 0, JSEXN_TYPEERR, "ReadableStreamBYOBRequest method 'respond' called with non-zero number of bytes with a closed controller.")
|
||||||
|
MSG_DEF(JSMSG_READABLESTREAM_METHOD_NOT_IMPLEMENTED, 1, JSEXN_TYPEERR, "ReadableStream method {0} not yet implemented")
|
||||||
|
|
||||||
|
// Other Stream-related
|
||||||
|
MSG_DEF(JSMSG_STREAM_INVALID_HIGHWATERMARK, 0, JSEXN_RANGEERR, "'highWaterMark' must be a non-negative, non-NaN number.")
|
||||||
@@ -126,6 +126,11 @@ if CONFIG['ENABLE_ION']:
|
|||||||
'testJitRValueAlloc.cpp',
|
'testJitRValueAlloc.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if CONFIG['ENABLE_STREAMS']:
|
||||||
|
UNIFIED_SOURCES += [
|
||||||
|
'testReadableStream.cpp',
|
||||||
|
]
|
||||||
|
|
||||||
DEFINES['EXPORT_JS_API'] = True
|
DEFINES['EXPORT_JS_API'] = True
|
||||||
|
|
||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "js/RequiredDefines.h"
|
#include "js/RequiredDefines.h"
|
||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
#include "js/SliceBudget.h"
|
#include "js/SliceBudget.h"
|
||||||
|
#include "js/Stream.h"
|
||||||
#include "js/StructuredClone.h"
|
#include "js/StructuredClone.h"
|
||||||
#include "js/TracingAPI.h"
|
#include "js/TracingAPI.h"
|
||||||
#include "js/TrackedOptimizationInfo.h"
|
#include "js/TrackedOptimizationInfo.h"
|
||||||
|
|||||||
@@ -0,0 +1,676 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#include "jsapi.h"
|
||||||
|
|
||||||
|
#include "jsapi-tests/tests.h"
|
||||||
|
|
||||||
|
using namespace JS;
|
||||||
|
|
||||||
|
char test_buffer_data[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
static JSObject*
|
||||||
|
NewDefaultStream(JSContext* cx, HandleObject source = nullptr, HandleFunction size = nullptr,
|
||||||
|
double highWaterMark = 1, HandleObject proto = nullptr)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewReadableDefaultStreamObject(cx, source, size, highWaterMark,
|
||||||
|
proto));
|
||||||
|
MOZ_ASSERT_IF(stream, IsReadableStream(stream));
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSObject*
|
||||||
|
NewByteStream(JSContext* cx, double highWaterMark = 0, HandleObject proto = nullptr)
|
||||||
|
{
|
||||||
|
RootedObject source(cx, JS_NewPlainObject(cx));
|
||||||
|
MOZ_ASSERT(source);
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewReadableByteStreamObject(cx, source, highWaterMark, proto));
|
||||||
|
MOZ_ASSERT_IF(stream, IsReadableStream(stream));
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool dataRequestCBCalled = false;
|
||||||
|
static void
|
||||||
|
DataRequestCB(JSContext* cx, HandleObject stream, void* underlyingSource, uint8_t flags,
|
||||||
|
size_t desiredSize)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!dataRequestCBCalled, "Invalid test setup");
|
||||||
|
dataRequestCBCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool writeIntoRequestBufferCBCalled = false;
|
||||||
|
static void
|
||||||
|
WriteIntoRequestBufferCB(JSContext* cx, HandleObject stream, void* underlyingSource, uint8_t flags,
|
||||||
|
void* buffer, size_t length, size_t* bytesWritten)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!writeIntoRequestBufferCBCalled, "Invalid test setup");
|
||||||
|
MOZ_ASSERT(length <= sizeof(test_buffer_data));
|
||||||
|
memcpy(buffer, test_buffer_data, length);
|
||||||
|
writeIntoRequestBufferCBCalled = true;
|
||||||
|
*bytesWritten = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool cancelStreamCBCalled = false;
|
||||||
|
static Value cancelStreamReason;
|
||||||
|
static Value
|
||||||
|
CancelStreamCB(JSContext* cx, HandleObject stream, void* underlyingSource, uint8_t flags,
|
||||||
|
HandleValue reason)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!cancelStreamCBCalled, "Invalid test setup");
|
||||||
|
cancelStreamCBCalled = true;
|
||||||
|
cancelStreamReason = reason;
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool streamClosedCBCalled = false;
|
||||||
|
static Value streamClosedReason;
|
||||||
|
static void
|
||||||
|
StreamClosedCB(JSContext* cx, HandleObject stream, void* underlyingSource, uint8_t flags)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!streamClosedCBCalled, "Invalid test setup");
|
||||||
|
streamClosedCBCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool streamErroredCBCalled = false;
|
||||||
|
static Value streamErroredReason;
|
||||||
|
static void
|
||||||
|
StreamErroredCB(JSContext* cx, HandleObject stream, void* underlyingSource, uint8_t flags,
|
||||||
|
HandleValue reason)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!streamErroredCBCalled, "Invalid test setup");
|
||||||
|
streamErroredCBCalled = true;
|
||||||
|
streamErroredReason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool finalizeStreamCBCalled = false;
|
||||||
|
static void* finalizedStreamUnderlyingSource;
|
||||||
|
static void
|
||||||
|
FinalizeStreamCB(void* underlyingSource, uint8_t flags)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!finalizeStreamCBCalled, "Invalid test setup");
|
||||||
|
finalizeStreamCBCalled = true;
|
||||||
|
finalizedStreamUnderlyingSource = underlyingSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ResetCallbacks()
|
||||||
|
{
|
||||||
|
dataRequestCBCalled = false;
|
||||||
|
writeIntoRequestBufferCBCalled = false;
|
||||||
|
cancelStreamReason = UndefinedValue();
|
||||||
|
cancelStreamCBCalled = false;
|
||||||
|
streamClosedCBCalled = false;
|
||||||
|
streamErroredCBCalled = false;
|
||||||
|
finalizeStreamCBCalled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
GetIterResult(JSContext* cx, HandleObject promise, MutableHandleValue value, bool* done)
|
||||||
|
{
|
||||||
|
RootedObject iterResult(cx, &GetPromiseResult(promise).toObject());
|
||||||
|
|
||||||
|
bool found;
|
||||||
|
if (!JS_HasProperty(cx, iterResult, "value", &found))
|
||||||
|
return false;
|
||||||
|
MOZ_ASSERT(found);
|
||||||
|
if (!JS_HasProperty(cx, iterResult, "done", &found))
|
||||||
|
return false;
|
||||||
|
MOZ_ASSERT(found);
|
||||||
|
|
||||||
|
RootedValue doneVal(cx);
|
||||||
|
if (!JS_GetProperty(cx, iterResult, "value", value))
|
||||||
|
return false;
|
||||||
|
if (!JS_GetProperty(cx, iterResult, "done", &doneVal))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*done = doneVal.toBoolean();
|
||||||
|
MOZ_ASSERT_IF(*done, value.isUndefined());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSObject*
|
||||||
|
GetReadChunk(JSContext* cx, HandleObject readRequest)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(GetPromiseState(readRequest) == PromiseState::Fulfilled);
|
||||||
|
RootedValue resultVal(cx, GetPromiseResult(readRequest));
|
||||||
|
MOZ_ASSERT(resultVal.isObject());
|
||||||
|
RootedObject result(cx, &resultVal.toObject());
|
||||||
|
RootedValue chunkVal(cx);
|
||||||
|
JS_GetProperty(cx, result, "value", &chunkVal);
|
||||||
|
return &chunkVal.toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_NewReadableStream)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
CHECK(ReadableStreamGetMode(stream) == ReadableStreamMode::Default);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_NewReadableStream)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_NewReadableByteStream)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewByteStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
CHECK(ReadableStreamGetMode(stream) == ReadableStreamMode::Byte);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_NewReadableByteStream)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamGetReaderDefault)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::Default));
|
||||||
|
CHECK(reader);
|
||||||
|
CHECK(IsReadableStreamDefaultReader(reader));
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
CHECK(!ReadableStreamReaderIsClosed(reader));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamGetReaderDefault)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamGetReaderBYOB)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewByteStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::BYOB));
|
||||||
|
CHECK(reader);
|
||||||
|
CHECK(IsReadableStreamBYOBReader(reader));
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
CHECK(!ReadableStreamReaderIsClosed(reader));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamGetReaderBYOB)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamTee)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject leftStream(cx);
|
||||||
|
RootedObject rightStream(cx);
|
||||||
|
CHECK(ReadableStreamTee(cx, stream, &leftStream, &rightStream));
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
CHECK(leftStream);
|
||||||
|
CHECK(IsReadableStream(leftStream));
|
||||||
|
CHECK(rightStream);
|
||||||
|
CHECK(IsReadableStream(rightStream));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamTee)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamEnqueue)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject chunk(cx, JS_NewPlainObject(cx));
|
||||||
|
CHECK(chunk);
|
||||||
|
RootedValue chunkVal(cx, ObjectValue(*chunk));
|
||||||
|
CHECK(ReadableStreamEnqueue(cx, stream, chunkVal));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamEnqueue)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableByteStreamEnqueue)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject chunk(cx, JS_NewUint8Array(cx, 42));
|
||||||
|
CHECK(chunk);
|
||||||
|
CHECK(!ReadableByteStreamEnqueueBuffer(cx, stream, chunk));
|
||||||
|
CHECK(JS_IsExceptionPending(cx));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableByteStreamEnqueue)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamDefaultReaderRead)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::Default));
|
||||||
|
CHECK(reader);
|
||||||
|
|
||||||
|
RootedObject request(cx, ReadableStreamDefaultReaderRead(cx, reader));
|
||||||
|
CHECK(request);
|
||||||
|
CHECK(IsPromiseObject(request));
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Pending);
|
||||||
|
|
||||||
|
RootedObject chunk(cx, JS_NewPlainObject(cx));
|
||||||
|
CHECK(chunk);
|
||||||
|
RootedValue chunkVal(cx, ObjectValue(*chunk));
|
||||||
|
CHECK(ReadableStreamEnqueue(cx, stream, chunkVal));
|
||||||
|
|
||||||
|
CHECK(GetReadChunk(cx, request) == chunk);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamDefaultReaderRead)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableByteStreamDefaultReaderRead)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewByteStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::Default));
|
||||||
|
CHECK(reader);
|
||||||
|
|
||||||
|
RootedObject request(cx, ReadableStreamDefaultReaderRead(cx, reader));
|
||||||
|
CHECK(request);
|
||||||
|
CHECK(IsPromiseObject(request));
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Pending);
|
||||||
|
|
||||||
|
size_t length = sizeof(test_buffer_data);
|
||||||
|
RootedObject buffer(cx, JS_NewArrayBufferWithExternalContents(cx, length, test_buffer_data));
|
||||||
|
CHECK(buffer);
|
||||||
|
RootedObject chunk(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 0, length));
|
||||||
|
CHECK(chunk);
|
||||||
|
bool isShared;
|
||||||
|
CHECK(!JS_IsDetachedArrayBufferObject(buffer));
|
||||||
|
|
||||||
|
CHECK(ReadableByteStreamEnqueueBuffer(cx, stream, chunk));
|
||||||
|
|
||||||
|
CHECK(JS_IsDetachedArrayBufferObject(buffer));
|
||||||
|
RootedObject readChunk(cx, GetReadChunk(cx, request));
|
||||||
|
CHECK(JS_IsUint8Array(readChunk));
|
||||||
|
void* readBufferData;
|
||||||
|
{
|
||||||
|
JS::AutoCheckCannotGC autoNoGC(cx);
|
||||||
|
readBufferData = JS_GetArrayBufferViewData(readChunk, &isShared, autoNoGC);
|
||||||
|
}
|
||||||
|
CHECK(readBufferData);
|
||||||
|
CHECK(!memcmp(test_buffer_data, readBufferData, length));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableByteStreamDefaultReaderRead)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableByteStreamBYOBReaderRead)
|
||||||
|
{
|
||||||
|
RootedObject stream(cx, NewByteStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::BYOB));
|
||||||
|
CHECK(reader);
|
||||||
|
|
||||||
|
size_t length = sizeof(test_buffer_data);
|
||||||
|
RootedObject targetArray(cx, JS_NewUint8Array(cx, length));
|
||||||
|
bool isShared;
|
||||||
|
|
||||||
|
RootedObject request(cx, ReadableStreamBYOBReaderRead(cx, reader, targetArray));
|
||||||
|
CHECK(request);
|
||||||
|
CHECK(IsPromiseObject(request));
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Pending);
|
||||||
|
CHECK(JS_IsDetachedArrayBufferObject(JS_GetArrayBufferViewBuffer(cx, targetArray, &isShared)));
|
||||||
|
|
||||||
|
RootedObject buffer(cx, JS_NewArrayBufferWithExternalContents(cx, length, test_buffer_data));
|
||||||
|
CHECK(buffer);
|
||||||
|
CHECK(!JS_IsDetachedArrayBufferObject(buffer));
|
||||||
|
|
||||||
|
CHECK(ReadableByteStreamEnqueueBuffer(cx, stream, buffer));
|
||||||
|
|
||||||
|
CHECK(JS_IsDetachedArrayBufferObject(buffer));
|
||||||
|
RootedObject readChunk(cx, GetReadChunk(cx, request));
|
||||||
|
CHECK(JS_IsUint8Array(readChunk));
|
||||||
|
void* readBufferData;
|
||||||
|
{
|
||||||
|
JS::AutoCheckCannotGC autoNoGC(cx);
|
||||||
|
readBufferData = JS_GetArrayBufferViewData(readChunk, &isShared, autoNoGC);
|
||||||
|
}
|
||||||
|
CHECK(readBufferData);
|
||||||
|
CHECK(!memcmp(test_buffer_data, readBufferData, length));
|
||||||
|
// TODO: eliminate the memcpy that happens here.
|
||||||
|
// CHECK(readBufferData == test_buffer_data);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableByteStreamBYOBReaderRead)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamDefaultReaderClose)
|
||||||
|
{
|
||||||
|
SetReadableStreamCallbacks(cx, &DataRequestCB, &WriteIntoRequestBufferCB,
|
||||||
|
&CancelStreamCB, &StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB);
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::Default));
|
||||||
|
CHECK(reader);
|
||||||
|
|
||||||
|
RootedObject request(cx, ReadableStreamDefaultReaderRead(cx, reader));
|
||||||
|
CHECK(request);
|
||||||
|
CHECK(IsPromiseObject(request));
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Pending);
|
||||||
|
|
||||||
|
CHECK(ReadableStreamClose(cx, stream));
|
||||||
|
|
||||||
|
bool done;
|
||||||
|
RootedValue value(cx);
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Fulfilled);
|
||||||
|
CHECK(GetIterResult(cx, request, &value, &done));
|
||||||
|
CHECK(value.isUndefined());
|
||||||
|
CHECK(done);
|
||||||
|
|
||||||
|
// The callbacks are only invoked for external streams.
|
||||||
|
CHECK(!streamClosedCBCalled);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamDefaultReaderClose)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ReadableStreamDefaultReaderError)
|
||||||
|
{
|
||||||
|
ResetCallbacks();
|
||||||
|
SetReadableStreamCallbacks(cx, &DataRequestCB, &WriteIntoRequestBufferCB,
|
||||||
|
&CancelStreamCB, &StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB);
|
||||||
|
RootedObject stream(cx, NewDefaultStream(cx));
|
||||||
|
CHECK(stream);
|
||||||
|
RootedObject reader(cx, ReadableStreamGetReader(cx, stream, ReadableStreamReaderMode::Default));
|
||||||
|
CHECK(reader);
|
||||||
|
|
||||||
|
RootedObject request(cx, ReadableStreamDefaultReaderRead(cx, reader));
|
||||||
|
CHECK(request);
|
||||||
|
CHECK(IsPromiseObject(request));
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Pending);
|
||||||
|
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
CHECK(ReadableStreamIsReadable(stream));
|
||||||
|
RootedValue error(cx, Int32Value(42));
|
||||||
|
CHECK(ReadableStreamError(cx, stream, error));
|
||||||
|
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Rejected);
|
||||||
|
RootedValue reason(cx, GetPromiseResult(request));
|
||||||
|
CHECK(reason.isInt32());
|
||||||
|
CHECK(reason.toInt32() == 42);
|
||||||
|
|
||||||
|
// The callbacks are only invoked for external streams.
|
||||||
|
CHECK(!streamErroredCBCalled);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ReadableStreamDefaultReaderError)
|
||||||
|
|
||||||
|
static JSObject*
|
||||||
|
NewExternalSourceStream(JSContext* cx, void* underlyingSource,
|
||||||
|
RequestReadableStreamDataCallback dataRequestCallback,
|
||||||
|
WriteIntoReadRequestBufferCallback writeIntoReadRequestCallback,
|
||||||
|
CancelReadableStreamCallback cancelCallback,
|
||||||
|
ReadableStreamClosedCallback closedCallback,
|
||||||
|
ReadableStreamErroredCallback erroredCallback,
|
||||||
|
ReadableStreamFinalizeCallback finalizeCallback)
|
||||||
|
{
|
||||||
|
SetReadableStreamCallbacks(cx, dataRequestCallback, writeIntoReadRequestCallback,
|
||||||
|
cancelCallback, closedCallback, erroredCallback,
|
||||||
|
finalizeCallback);
|
||||||
|
RootedObject stream(cx, NewReadableExternalSourceStreamObject(cx, underlyingSource));
|
||||||
|
MOZ_ASSERT_IF(stream, IsReadableStream(stream));
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_CreateReadableByteStreamWithExternalSource)
|
||||||
|
{
|
||||||
|
ResetCallbacks();
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewExternalSourceStream(cx, &test_buffer_data, &DataRequestCB,
|
||||||
|
&WriteIntoRequestBufferCB, &CancelStreamCB,
|
||||||
|
&StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB));
|
||||||
|
CHECK(stream);
|
||||||
|
CHECK(ReadableStreamGetMode(stream) == JS::ReadableStreamMode::ExternalSource);
|
||||||
|
void* underlyingSource;
|
||||||
|
CHECK(ReadableStreamGetExternalUnderlyingSource(cx, stream, &underlyingSource));
|
||||||
|
CHECK(underlyingSource == &test_buffer_data);
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
ReadableStreamReleaseExternalUnderlyingSource(stream);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_CreateReadableByteStreamWithExternalSource)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ExternalSourceCancel)
|
||||||
|
{
|
||||||
|
ResetCallbacks();
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewExternalSourceStream(cx, &test_buffer_data, &DataRequestCB,
|
||||||
|
&WriteIntoRequestBufferCB, &CancelStreamCB,
|
||||||
|
&StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB));
|
||||||
|
CHECK(stream);
|
||||||
|
RootedValue reason(cx, Int32Value(42));
|
||||||
|
CHECK(ReadableStreamCancel(cx, stream, reason));
|
||||||
|
CHECK(cancelStreamCBCalled);
|
||||||
|
CHECK(cancelStreamReason == reason);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ExternalSourceCancel)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ExternalSourceGetReader)
|
||||||
|
{
|
||||||
|
ResetCallbacks();
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewExternalSourceStream(cx, &test_buffer_data, &DataRequestCB,
|
||||||
|
&WriteIntoRequestBufferCB, &CancelStreamCB,
|
||||||
|
&StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
RootedValue streamVal(cx, ObjectValue(*stream));
|
||||||
|
CHECK(JS_SetProperty(cx, global, "stream", streamVal));
|
||||||
|
RootedValue rval(cx);
|
||||||
|
EVAL("stream.getReader()", &rval);
|
||||||
|
CHECK(rval.isObject());
|
||||||
|
RootedObject reader(cx, &rval.toObject());
|
||||||
|
CHECK(IsReadableStreamDefaultReader(reader));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ExternalSourceGetReader)
|
||||||
|
|
||||||
|
BEGIN_TEST(testReadableStream_ExternalSourceUpdateAvailableData)
|
||||||
|
{
|
||||||
|
ResetCallbacks();
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewExternalSourceStream(cx, &test_buffer_data, &DataRequestCB,
|
||||||
|
&WriteIntoRequestBufferCB, &CancelStreamCB,
|
||||||
|
&StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB));
|
||||||
|
CHECK(stream);
|
||||||
|
|
||||||
|
ReadableStreamUpdateDataAvailableFromSource(cx, stream, 1024);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testReadableStream_ExternalSourceUpdateAvailableData)
|
||||||
|
|
||||||
|
struct ReadFromExternalSourceFixture : public JSAPITest
|
||||||
|
{
|
||||||
|
virtual ~ReadFromExternalSourceFixture() {}
|
||||||
|
|
||||||
|
bool readWithoutDataAvailable(const char* evalSrc, const char* evalSrc2,
|
||||||
|
uint32_t writtenLength)
|
||||||
|
{
|
||||||
|
ResetCallbacks();
|
||||||
|
definePrint();
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewExternalSourceStream(cx, &test_buffer_data, &DataRequestCB,
|
||||||
|
&WriteIntoRequestBufferCB,
|
||||||
|
&CancelStreamCB,
|
||||||
|
&StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB));
|
||||||
|
CHECK(stream);
|
||||||
|
js::RunJobs(cx);
|
||||||
|
void* underlyingSource;
|
||||||
|
CHECK(ReadableStreamGetExternalUnderlyingSource(cx, stream, &underlyingSource));
|
||||||
|
CHECK(underlyingSource == &test_buffer_data);
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
ReadableStreamReleaseExternalUnderlyingSource(stream);
|
||||||
|
|
||||||
|
RootedValue streamVal(cx, ObjectValue(*stream));
|
||||||
|
CHECK(JS_SetProperty(cx, global, "stream", streamVal));
|
||||||
|
|
||||||
|
RootedValue rval(cx);
|
||||||
|
EVAL(evalSrc, &rval);
|
||||||
|
CHECK(dataRequestCBCalled);
|
||||||
|
CHECK(!writeIntoRequestBufferCBCalled);
|
||||||
|
CHECK(rval.isObject());
|
||||||
|
RootedObject promise(cx, &rval.toObject());
|
||||||
|
CHECK(IsPromiseObject(promise));
|
||||||
|
CHECK(GetPromiseState(promise) == PromiseState::Pending);
|
||||||
|
|
||||||
|
size_t length = sizeof(test_buffer_data);
|
||||||
|
ReadableStreamUpdateDataAvailableFromSource(cx, stream, length);
|
||||||
|
|
||||||
|
CHECK(writeIntoRequestBufferCBCalled);
|
||||||
|
CHECK(GetPromiseState(promise) == PromiseState::Fulfilled);
|
||||||
|
RootedValue iterVal(cx);
|
||||||
|
bool done;
|
||||||
|
if (!GetIterResult(cx, promise, &iterVal, &done))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CHECK(!done);
|
||||||
|
RootedObject chunk(cx, &iterVal.toObject());
|
||||||
|
CHECK(JS_IsUint8Array(chunk));
|
||||||
|
|
||||||
|
{
|
||||||
|
JS::AutoCheckCannotGC noGC(cx);
|
||||||
|
bool dummy;
|
||||||
|
void* buffer = JS_GetArrayBufferViewData(chunk, &dummy, noGC);
|
||||||
|
CHECK(!memcmp(buffer, test_buffer_data, writtenLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
dataRequestCBCalled = false;
|
||||||
|
writeIntoRequestBufferCBCalled = false;
|
||||||
|
EVAL(evalSrc2, &rval);
|
||||||
|
CHECK(dataRequestCBCalled);
|
||||||
|
CHECK(!writeIntoRequestBufferCBCalled);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readWithDataAvailable(const char* evalSrc, uint32_t writtenLength) {
|
||||||
|
ResetCallbacks();
|
||||||
|
definePrint();
|
||||||
|
|
||||||
|
RootedObject stream(cx, NewExternalSourceStream(cx, &test_buffer_data, &DataRequestCB,
|
||||||
|
&WriteIntoRequestBufferCB, &CancelStreamCB,
|
||||||
|
&StreamClosedCB, &StreamErroredCB,
|
||||||
|
&FinalizeStreamCB));
|
||||||
|
CHECK(stream);
|
||||||
|
void* underlyingSource;
|
||||||
|
CHECK(ReadableStreamGetExternalUnderlyingSource(cx, stream, &underlyingSource));
|
||||||
|
CHECK(underlyingSource == &test_buffer_data);
|
||||||
|
CHECK(ReadableStreamIsLocked(stream));
|
||||||
|
ReadableStreamReleaseExternalUnderlyingSource(stream);
|
||||||
|
|
||||||
|
size_t length = sizeof(test_buffer_data);
|
||||||
|
ReadableStreamUpdateDataAvailableFromSource(cx, stream, length);
|
||||||
|
|
||||||
|
RootedValue streamVal(cx, ObjectValue(*stream));
|
||||||
|
CHECK(JS_SetProperty(cx, global, "stream", streamVal));
|
||||||
|
|
||||||
|
RootedValue rval(cx);
|
||||||
|
EVAL(evalSrc, &rval);
|
||||||
|
CHECK(writeIntoRequestBufferCBCalled);
|
||||||
|
CHECK(rval.isObject());
|
||||||
|
RootedObject promise(cx, &rval.toObject());
|
||||||
|
CHECK(IsPromiseObject(promise));
|
||||||
|
CHECK(GetPromiseState(promise) == PromiseState::Fulfilled);
|
||||||
|
RootedValue iterVal(cx);
|
||||||
|
bool done;
|
||||||
|
if (!GetIterResult(cx, promise, &iterVal, &done))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CHECK(!done);
|
||||||
|
RootedObject chunk(cx, &iterVal.toObject());
|
||||||
|
CHECK(JS_IsUint8Array(chunk));
|
||||||
|
|
||||||
|
{
|
||||||
|
JS::AutoCheckCannotGC noGC(cx);
|
||||||
|
bool dummy;
|
||||||
|
void* buffer = JS_GetArrayBufferViewData(chunk, &dummy, noGC);
|
||||||
|
CHECK(!memcmp(buffer, test_buffer_data, writtenLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BEGIN_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadDefaultWithoutDataAvailable)
|
||||||
|
{
|
||||||
|
return readWithoutDataAvailable("r = stream.getReader(); r.read()", "r.read()", sizeof(test_buffer_data));
|
||||||
|
}
|
||||||
|
END_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadDefaultWithoutDataAvailable)
|
||||||
|
|
||||||
|
BEGIN_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceCloseWithPendingRead)
|
||||||
|
{
|
||||||
|
CHECK(readWithoutDataAvailable("r = stream.getReader(); request0 = r.read(); "
|
||||||
|
"request1 = r.read(); request0", "r.read()",
|
||||||
|
sizeof(test_buffer_data)));
|
||||||
|
|
||||||
|
RootedValue val(cx);
|
||||||
|
CHECK(JS_GetProperty(cx, global, "request1", &val));
|
||||||
|
CHECK(val.isObject());
|
||||||
|
RootedObject request(cx, &val.toObject());
|
||||||
|
CHECK(IsPromiseObject(request));
|
||||||
|
CHECK(GetPromiseState(request) == PromiseState::Pending);
|
||||||
|
|
||||||
|
CHECK(JS_GetProperty(cx, global, "stream", &val));
|
||||||
|
RootedObject stream(cx, &val.toObject());
|
||||||
|
ReadableStreamClose(cx, stream);
|
||||||
|
|
||||||
|
val = GetPromiseResult(request);
|
||||||
|
MOZ_ASSERT(val.isObject());
|
||||||
|
RootedObject result(cx, &val.toObject());
|
||||||
|
|
||||||
|
JS_GetProperty(cx, result, "done", &val);
|
||||||
|
CHECK(val.isBoolean());
|
||||||
|
CHECK(val.toBoolean() == true);
|
||||||
|
|
||||||
|
JS_GetProperty(cx, result, "value", &val);
|
||||||
|
CHECK(val.isUndefined());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceCloseWithPendingRead)
|
||||||
|
|
||||||
|
BEGIN_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadDefaultWithDataAvailable)
|
||||||
|
{
|
||||||
|
return readWithDataAvailable("r = stream.getReader(); r.read()", sizeof(test_buffer_data));
|
||||||
|
}
|
||||||
|
END_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadDefaultWithDataAvailable)
|
||||||
|
|
||||||
|
BEGIN_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadBYOBWithoutDataAvailable)
|
||||||
|
{
|
||||||
|
return readWithoutDataAvailable("r = stream.getReader({mode: 'byob'}); r.read(new Uint8Array(63))", "r.read(new Uint8Array(10))", 10);
|
||||||
|
}
|
||||||
|
END_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadBYOBWithoutDataAvailable)
|
||||||
|
|
||||||
|
BEGIN_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadBYOBWithDataAvailable)
|
||||||
|
{
|
||||||
|
return readWithDataAvailable("r = stream.getReader({mode: 'byob'}); r.read(new Uint8Array(10))", 10);
|
||||||
|
}
|
||||||
|
END_FIXTURE_TEST(ReadFromExternalSourceFixture,
|
||||||
|
testReadableStream_ExternalSourceReadBYOBWithDataAvailable)
|
||||||
@@ -81,6 +81,10 @@ JSObject* JSAPITest::createGlobal(JSPrincipals* principals)
|
|||||||
/* Create the global object. */
|
/* Create the global object. */
|
||||||
JS::RootedObject newGlobal(cx);
|
JS::RootedObject newGlobal(cx);
|
||||||
JS::CompartmentOptions options;
|
JS::CompartmentOptions options;
|
||||||
|
#ifdef ENABLE_STREAMS
|
||||||
|
options.creationOptions().setStreamsEnabled(true);
|
||||||
|
#endif
|
||||||
|
printf("enabled\n");
|
||||||
options.behaviors().setVersion(JSVERSION_LATEST);
|
options.behaviors().setVersion(JSVERSION_LATEST);
|
||||||
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
|
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
|
||||||
options);
|
options);
|
||||||
|
|||||||
+364
-2
@@ -47,6 +47,7 @@
|
|||||||
#include "builtin/MapObject.h"
|
#include "builtin/MapObject.h"
|
||||||
#include "builtin/Promise.h"
|
#include "builtin/Promise.h"
|
||||||
#include "builtin/RegExp.h"
|
#include "builtin/RegExp.h"
|
||||||
|
#include "builtin/Stream.h"
|
||||||
#include "builtin/SymbolObject.h"
|
#include "builtin/SymbolObject.h"
|
||||||
#ifdef ENABLE_SIMD
|
#ifdef ENABLE_SIMD
|
||||||
# include "builtin/SIMD.h"
|
# include "builtin/SIMD.h"
|
||||||
@@ -5016,7 +5017,6 @@ CallOriginalPromiseThenImpl(JSContext* cx, JS::HandleObject promiseObj,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(JSObject*)
|
JS_PUBLIC_API(JSObject*)
|
||||||
@@ -5043,7 +5043,7 @@ JS::AddPromiseReactions(JSContext* cx, JS::HandleObject promiseObj,
|
|||||||
* Unforgeable version of Promise.all for internal use.
|
* Unforgeable version of Promise.all for internal use.
|
||||||
*
|
*
|
||||||
* Takes a dense array of Promise objects and returns a promise that's
|
* Takes a dense array of Promise objects and returns a promise that's
|
||||||
* resolved with an array of resolution values when all those promises ahve
|
* resolved with an array of resolution values when all those promises have
|
||||||
* been resolved, or rejected with the rejection value of the first rejected
|
* been resolved, or rejected with the rejection value of the first rejected
|
||||||
* promise.
|
* promise.
|
||||||
*
|
*
|
||||||
@@ -5058,6 +5058,368 @@ JS::GetWaitForAllPromise(JSContext* cx, const JS::AutoObjectVector& promises)
|
|||||||
return js::GetWaitForAllPromise(cx, promises);
|
return js::GetWaitForAllPromise(cx, promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::NewReadableDefaultStreamObject(JSContext* cx,
|
||||||
|
JS::HandleObject underlyingSource /* = nullptr */,
|
||||||
|
JS::HandleFunction size /* = nullptr */,
|
||||||
|
double highWaterMark /* = 1 */,
|
||||||
|
JS::HandleObject proto /* = nullptr */)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
|
||||||
|
RootedObject source(cx, underlyingSource);
|
||||||
|
if (!source) {
|
||||||
|
source = NewBuiltinClassInstance<PlainObject>(cx);
|
||||||
|
if (!source)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
RootedValue sourceVal(cx, ObjectValue(*source));
|
||||||
|
RootedValue sizeVal(cx, size ? ObjectValue(*size) : UndefinedValue());
|
||||||
|
RootedValue highWaterMarkVal(cx, NumberValue(highWaterMark));
|
||||||
|
return ReadableStream::createDefaultStream(cx, sourceVal, sizeVal, highWaterMarkVal, proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::NewReadableByteStreamObject(JSContext* cx,
|
||||||
|
JS::HandleObject underlyingSource /* = nullptr */,
|
||||||
|
double highWaterMark /* = 1 */,
|
||||||
|
JS::HandleObject proto /* = nullptr */)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
|
||||||
|
RootedObject source(cx, underlyingSource);
|
||||||
|
if (!source) {
|
||||||
|
source = NewBuiltinClassInstance<PlainObject>(cx);
|
||||||
|
if (!source)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
RootedValue sourceVal(cx, ObjectValue(*source));
|
||||||
|
RootedValue highWaterMarkVal(cx, NumberValue(highWaterMark));
|
||||||
|
return ReadableStream::createByteStream(cx, sourceVal, highWaterMarkVal, proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern JS_PUBLIC_API(void)
|
||||||
|
JS::SetReadableStreamCallbacks(JSContext* cx,
|
||||||
|
JS::RequestReadableStreamDataCallback dataRequestCallback,
|
||||||
|
JS::WriteIntoReadRequestBufferCallback writeIntoReadRequestCallback,
|
||||||
|
JS::CancelReadableStreamCallback cancelCallback,
|
||||||
|
JS::ReadableStreamClosedCallback closedCallback,
|
||||||
|
JS::ReadableStreamErroredCallback erroredCallback,
|
||||||
|
JS::ReadableStreamFinalizeCallback finalizeCallback)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(dataRequestCallback);
|
||||||
|
MOZ_ASSERT(writeIntoReadRequestCallback);
|
||||||
|
MOZ_ASSERT(cancelCallback);
|
||||||
|
MOZ_ASSERT(closedCallback);
|
||||||
|
MOZ_ASSERT(erroredCallback);
|
||||||
|
MOZ_ASSERT(finalizeCallback);
|
||||||
|
|
||||||
|
JSRuntime* rt = cx->runtime();
|
||||||
|
|
||||||
|
MOZ_ASSERT(!rt->readableStreamDataRequestCallback);
|
||||||
|
MOZ_ASSERT(!rt->readableStreamWriteIntoReadRequestCallback);
|
||||||
|
MOZ_ASSERT(!rt->readableStreamCancelCallback);
|
||||||
|
MOZ_ASSERT(!rt->readableStreamClosedCallback);
|
||||||
|
MOZ_ASSERT(!rt->readableStreamErroredCallback);
|
||||||
|
MOZ_ASSERT(!rt->readableStreamFinalizeCallback);
|
||||||
|
|
||||||
|
rt->readableStreamDataRequestCallback = dataRequestCallback;
|
||||||
|
rt->readableStreamWriteIntoReadRequestCallback = writeIntoReadRequestCallback;
|
||||||
|
rt->readableStreamCancelCallback = cancelCallback;
|
||||||
|
rt->readableStreamClosedCallback = closedCallback;
|
||||||
|
rt->readableStreamErroredCallback = erroredCallback;
|
||||||
|
rt->readableStreamFinalizeCallback = finalizeCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::HasReadableStreamCallbacks(JSContext* cx)
|
||||||
|
{
|
||||||
|
return cx->runtime()->readableStreamDataRequestCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::NewReadableExternalSourceStreamObject(JSContext* cx, void* underlyingSource,
|
||||||
|
uint8_t flags /* = 0 */,
|
||||||
|
HandleObject proto /* = nullptr */)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
JSRuntime* rt = cx->runtime();
|
||||||
|
MOZ_ASSERT(rt->readableStreamDataRequestCallback);
|
||||||
|
MOZ_ASSERT(rt->readableStreamWriteIntoReadRequestCallback);
|
||||||
|
MOZ_ASSERT(rt->readableStreamCancelCallback);
|
||||||
|
MOZ_ASSERT(rt->readableStreamClosedCallback);
|
||||||
|
MOZ_ASSERT(rt->readableStreamErroredCallback);
|
||||||
|
MOZ_ASSERT(rt->readableStreamFinalizeCallback);
|
||||||
|
#endif // DEBUG
|
||||||
|
|
||||||
|
return ReadableStream::createExternalSourceStream(cx, underlyingSource, flags, proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(uint8_t)
|
||||||
|
JS::ReadableStreamGetEmbeddingFlags(const JSObject* stream)
|
||||||
|
{
|
||||||
|
return stream->as<ReadableStream>().embeddingFlags();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::IsReadableStream(const JSObject* obj)
|
||||||
|
{
|
||||||
|
return obj->is<ReadableStream>();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::IsReadableStreamReader(const JSObject* obj)
|
||||||
|
{
|
||||||
|
return obj->is<ReadableStreamDefaultReader>() || obj->is<ReadableStreamBYOBReader>();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::IsReadableStreamDefaultReader(const JSObject* obj)
|
||||||
|
{
|
||||||
|
return obj->is<ReadableStreamDefaultReader>();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::IsReadableStreamBYOBReader(const JSObject* obj)
|
||||||
|
{
|
||||||
|
return obj->is<ReadableStreamBYOBReader>();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamIsReadable(const JSObject* stream)
|
||||||
|
{
|
||||||
|
return stream->as<ReadableStream>().readable();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamIsLocked(const JSObject* stream)
|
||||||
|
{
|
||||||
|
return stream->as<ReadableStream>().locked();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamIsDisturbed(const JSObject* stream)
|
||||||
|
{
|
||||||
|
return stream->as<ReadableStream>().disturbed();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::ReadableStreamCancel(JSContext* cx, HandleObject streamObj, HandleValue reason)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
assertSameCompartment(cx, reason);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
return ReadableStream::cancel(cx, stream, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JS::ReadableStreamMode)
|
||||||
|
JS::ReadableStreamGetMode(const JSObject* stream)
|
||||||
|
{
|
||||||
|
return stream->as<ReadableStream>().mode();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::ReadableStreamGetReader(JSContext* cx, HandleObject streamObj, ReadableStreamReaderMode mode)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
return ReadableStream::getReader(cx, stream, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamGetExternalUnderlyingSource(JSContext* cx, HandleObject streamObj, void** source)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
return ReadableStream::getExternalSource(cx, stream, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(void)
|
||||||
|
JS::ReadableStreamReleaseExternalUnderlyingSource(JSObject* stream)
|
||||||
|
{
|
||||||
|
stream->as<ReadableStream>().releaseExternalSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamUpdateDataAvailableFromSource(JSContext* cx, JS::HandleObject streamObj,
|
||||||
|
uint32_t availableData)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
return ReadableStream::updateDataAvailableFromSource(cx, stream, availableData);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamTee(JSContext* cx, HandleObject streamObj,
|
||||||
|
MutableHandleObject branch1Obj, MutableHandleObject branch2Obj)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
Rooted<ReadableStream*> branch1Stream(cx);
|
||||||
|
Rooted<ReadableStream*> branch2Stream(cx);
|
||||||
|
|
||||||
|
if (!ReadableStream::tee(cx, stream, false, &branch1Stream, &branch2Stream))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
branch1Obj.set(branch1Stream);
|
||||||
|
branch2Obj.set(branch2Stream);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(void)
|
||||||
|
JS::ReadableStreamGetDesiredSize(JSObject* streamObj, bool* hasValue, double* value)
|
||||||
|
{
|
||||||
|
streamObj->as<ReadableStream>().desiredSize(hasValue, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamClose(JSContext* cx, HandleObject streamObj)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
return ReadableStream::close(cx, stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamEnqueue(JSContext* cx, HandleObject streamObj, HandleValue chunk)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
assertSameCompartment(cx, chunk);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
if (stream->mode() != JS::ReadableStreamMode::Default) {
|
||||||
|
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
|
||||||
|
JSMSG_READABLESTREAM_NOT_DEFAULT_CONTROLLER,
|
||||||
|
"JS::ReadableStreamEnqueue");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return ReadableStream::enqueue(cx, stream, chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableByteStreamEnqueueBuffer(JSContext* cx, HandleObject streamObj, HandleObject chunkObj)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
assertSameCompartment(cx, chunkObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
if (stream->mode() != JS::ReadableStreamMode::Byte) {
|
||||||
|
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
|
||||||
|
JSMSG_READABLESTREAM_NOT_BYTE_STREAM_CONTROLLER,
|
||||||
|
"JS::ReadableByteStreamEnqueueBuffer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rooted<ArrayBufferObject*> buffer(cx);
|
||||||
|
if (chunkObj->is<ArrayBufferViewObject>()) {
|
||||||
|
bool dummy;
|
||||||
|
buffer = &JS_GetArrayBufferViewBuffer(cx, chunkObj, &dummy)->as<ArrayBufferObject>();
|
||||||
|
} else if (chunkObj->is<ArrayBufferObject>()) {
|
||||||
|
buffer = &chunkObj->as<ArrayBufferObject>();
|
||||||
|
} else {
|
||||||
|
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
|
||||||
|
JSMSG_READABLEBYTESTREAMCONTROLLER_BAD_CHUNK,
|
||||||
|
"JS::ReadableByteStreamEnqueueBuffer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReadableStream::enqueueBuffer(cx, stream, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamError(JSContext* cx, HandleObject streamObj, HandleValue error)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, streamObj);
|
||||||
|
assertSameCompartment(cx, error);
|
||||||
|
|
||||||
|
Rooted<ReadableStream*> stream(cx, &streamObj->as<ReadableStream>());
|
||||||
|
return js::ReadableStream::error(cx, stream, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamReaderIsClosed(const JSObject* reader)
|
||||||
|
{
|
||||||
|
return js::ReadableStreamReaderIsClosed(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamReaderCancel(JSContext* cx, HandleObject reader, HandleValue reason)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, reader);
|
||||||
|
assertSameCompartment(cx, reason);
|
||||||
|
|
||||||
|
return js::ReadableStreamReaderCancel(cx, reader, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(bool)
|
||||||
|
JS::ReadableStreamReaderReleaseLock(JSContext* cx, HandleObject reader)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, reader);
|
||||||
|
|
||||||
|
return js::ReadableStreamReaderReleaseLock(cx, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::ReadableStreamDefaultReaderRead(JSContext* cx, HandleObject readerObj)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, readerObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStreamDefaultReader*> reader(cx, &readerObj->as<ReadableStreamDefaultReader>());
|
||||||
|
return js::ReadableStreamDefaultReader::read(cx, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API(JSObject*)
|
||||||
|
JS::ReadableStreamBYOBReaderRead(JSContext* cx, HandleObject readerObj, HandleObject viewObj)
|
||||||
|
{
|
||||||
|
AssertHeapIsIdle(cx);
|
||||||
|
CHECK_REQUEST(cx);
|
||||||
|
assertSameCompartment(cx, readerObj);
|
||||||
|
assertSameCompartment(cx, viewObj);
|
||||||
|
|
||||||
|
Rooted<ReadableStreamBYOBReader*> reader(cx, &readerObj->as<ReadableStreamBYOBReader>());
|
||||||
|
Rooted<ArrayBufferViewObject*> view(cx, &viewObj->as<ArrayBufferViewObject>());
|
||||||
|
return js::ReadableStreamBYOBReader::read(cx, reader, view);
|
||||||
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(void)
|
JS_PUBLIC_API(void)
|
||||||
JS::SetAsyncTaskCallbacks(JSContext* cx, JS::StartAsyncTaskCallback start,
|
JS::SetAsyncTaskCallbacks(JSContext* cx, JS::StartAsyncTaskCallback start,
|
||||||
JS::FinishAsyncTaskCallback finish)
|
JS::FinishAsyncTaskCallback finish)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "js/Principals.h"
|
#include "js/Principals.h"
|
||||||
#include "js/Realm.h"
|
#include "js/Realm.h"
|
||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
|
#include "js/Stream.h"
|
||||||
#include "js/TracingAPI.h"
|
#include "js/TracingAPI.h"
|
||||||
#include "js/UniquePtr.h"
|
#include "js/UniquePtr.h"
|
||||||
#include "js/Utility.h"
|
#include "js/Utility.h"
|
||||||
@@ -1169,6 +1170,16 @@ class JS_PUBLIC_API(ContextOptions) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool streams() const { return streams_; }
|
||||||
|
ContextOptions& setStreams(bool flag) {
|
||||||
|
streams_ = flag;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
ContextOptions& toggleStreams() {
|
||||||
|
streams_ = !streams_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
bool nativeRegExp() const { return nativeRegExp_; }
|
bool nativeRegExp() const { return nativeRegExp_; }
|
||||||
ContextOptions& setNativeRegExp(bool flag) {
|
ContextOptions& setNativeRegExp(bool flag) {
|
||||||
nativeRegExp_ = flag;
|
nativeRegExp_ = flag;
|
||||||
@@ -1251,6 +1262,7 @@ class JS_PUBLIC_API(ContextOptions) {
|
|||||||
bool strictMode_ : 1;
|
bool strictMode_ : 1;
|
||||||
bool extraWarnings_ : 1;
|
bool extraWarnings_ : 1;
|
||||||
bool arrayProtoValues_ : 1;
|
bool arrayProtoValues_ : 1;
|
||||||
|
bool streams_ : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
JS_PUBLIC_API(ContextOptions&)
|
JS_PUBLIC_API(ContextOptions&)
|
||||||
|
|||||||
@@ -1778,6 +1778,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 {
|
||||||
|
|
||||||
@@ -1994,6 +1997,12 @@ JS_IsArrayBufferViewObject(JSObject* obj);
|
|||||||
extern JS_FRIEND_API(uint32_t)
|
extern JS_FRIEND_API(uint32_t)
|
||||||
JS_GetArrayBufferViewByteLength(JSObject* obj);
|
JS_GetArrayBufferViewByteLength(JSObject* obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* More generic name for JS_GetTypedArrayByteOffset to cover DataViews as well
|
||||||
|
*/
|
||||||
|
extern JS_FRIEND_API(uint32_t)
|
||||||
|
JS_GetArrayBufferViewByteOffset(JSObject* obj);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a pointer to the start of the data referenced by a typed array. The
|
* Return a pointer to the start of the data referenced by a typed array. The
|
||||||
* data is still owned by the typed array, and should not be modified on
|
* data is still owned by the typed array, and should not be modified on
|
||||||
|
|||||||
+8
-3
@@ -947,6 +947,13 @@ static const JSFunctionSpec number_methods[] = {
|
|||||||
JS_FS_END
|
JS_FS_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
js::IsInteger(const Value& val)
|
||||||
|
{
|
||||||
|
return val.isInt32() ||
|
||||||
|
(mozilla::IsFinite(val.toDouble()) && JS::ToInteger(val.toDouble()) == val.toDouble());
|
||||||
|
}
|
||||||
|
|
||||||
// ES6 draft ES6 15.7.3.12
|
// ES6 draft ES6 15.7.3.12
|
||||||
static bool
|
static bool
|
||||||
Number_isInteger(JSContext* cx, unsigned argc, Value* vp)
|
Number_isInteger(JSContext* cx, unsigned argc, Value* vp)
|
||||||
@@ -957,9 +964,7 @@ Number_isInteger(JSContext* cx, unsigned argc, Value* vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Value val = args[0];
|
Value val = args[0];
|
||||||
args.rval().setBoolean(val.isInt32() ||
|
args.rval().setBoolean(js::IsInteger(val));
|
||||||
(mozilla::IsFinite(val.toDouble()) &&
|
|
||||||
JS::ToInteger(val.toDouble()) == val.toDouble()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ Int32ToString(ExclusiveContext* cx, int32_t i);
|
|||||||
extern JSAtom*
|
extern JSAtom*
|
||||||
Int32ToAtom(ExclusiveContext* cx, int32_t si);
|
Int32ToAtom(ExclusiveContext* cx, int32_t si);
|
||||||
|
|
||||||
|
// ES6 15.7.3.12
|
||||||
|
extern bool
|
||||||
|
IsInteger(const Value& val);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert an integer or double (contained in the given value) to a string and
|
* Convert an integer or double (contained in the given value) to a string and
|
||||||
* append to the given buffer.
|
* append to the given buffer.
|
||||||
|
|||||||
+17
-6
@@ -106,12 +106,23 @@ IF_SIMD(real,imaginary)(SIMD, 44, InitSimdClass, OCLASP(Si
|
|||||||
real(TypedArray, 46, InitViaClassSpec, &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \
|
real(TypedArray, 46, InitViaClassSpec, &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \
|
||||||
IF_SAB(real,imaginary)(Atomics, 47, InitAtomicsClass, OCLASP(Atomics)) \
|
IF_SAB(real,imaginary)(Atomics, 47, InitAtomicsClass, OCLASP(Atomics)) \
|
||||||
real(SavedFrame, 48, InitViaClassSpec, &js::SavedFrame::class_) \
|
real(SavedFrame, 48, InitViaClassSpec, &js::SavedFrame::class_) \
|
||||||
real(WebAssembly, 49, InitWebAssemblyClass, CLASP(WebAssembly)) \
|
real(Promise, 49, InitViaClassSpec, OCLASP(Promise)) \
|
||||||
imaginary(WasmModule, 50, dummy, dummy) \
|
real(ReadableStream, 50, InitViaClassSpec, &js::ReadableStream::class_) \
|
||||||
imaginary(WasmInstance, 51, dummy, dummy) \
|
real(ReadableStreamDefaultReader, 51, InitViaClassSpec, &js::ReadableStreamDefaultReader::class_) \
|
||||||
imaginary(WasmMemory, 52, dummy, dummy) \
|
real(ReadableStreamBYOBReader, 52, InitViaClassSpec, &js::ReadableStreamBYOBReader::class_) \
|
||||||
imaginary(WasmTable, 53, dummy, dummy) \
|
real(ReadableStreamDefaultController, 53, InitViaClassSpec, &js::ReadableStreamDefaultController::class_) \
|
||||||
real(Promise, 54, InitViaClassSpec, OCLASP(Promise)) \
|
real(ReadableByteStreamController, 54, InitViaClassSpec, &js::ReadableByteStreamController::class_) \
|
||||||
|
real(ReadableStreamBYOBRequest, 55, InitViaClassSpec, &js::ReadableStreamBYOBRequest::class_) \
|
||||||
|
imaginary(WritableStream, 56, dummy, dummy) \
|
||||||
|
imaginary(WritableStreamDefaultWriter, 57, dummy, dummy) \
|
||||||
|
imaginary(WritableStreamDefaultController, 58, dummy, dummy) \
|
||||||
|
real(ByteLengthQueuingStrategy, 59, InitViaClassSpec, &js::ByteLengthQueuingStrategy::class_) \
|
||||||
|
real(CountQueuingStrategy, 60, InitViaClassSpec, &js::CountQueuingStrategy::class_) \
|
||||||
|
real(WebAssembly, 61, InitWebAssemblyClass, CLASP(WebAssembly)) \
|
||||||
|
imaginary(WasmModule, 62, dummy, dummy) \
|
||||||
|
imaginary(WasmInstance, 63, dummy, dummy) \
|
||||||
|
imaginary(WasmMemory, 64, dummy, dummy) \
|
||||||
|
imaginary(WasmTable, 65, dummy, dummy)
|
||||||
|
|
||||||
#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro)
|
#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro)
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ EXPORTS.js += [
|
|||||||
'../public/RequiredDefines.h',
|
'../public/RequiredDefines.h',
|
||||||
'../public/RootingAPI.h',
|
'../public/RootingAPI.h',
|
||||||
'../public/SliceBudget.h',
|
'../public/SliceBudget.h',
|
||||||
|
'../public/Stream.h',
|
||||||
'../public/StructuredClone.h',
|
'../public/StructuredClone.h',
|
||||||
'../public/SweepingAPI.h',
|
'../public/SweepingAPI.h',
|
||||||
'../public/TraceKind.h',
|
'../public/TraceKind.h',
|
||||||
|
|||||||
+7
-2
@@ -321,6 +321,7 @@ static bool enableUnboxedArrays = false;
|
|||||||
static bool enableSharedMemory = SHARED_MEMORY_DEFAULT;
|
static bool enableSharedMemory = SHARED_MEMORY_DEFAULT;
|
||||||
static bool enableWasmAlwaysBaseline = false;
|
static bool enableWasmAlwaysBaseline = false;
|
||||||
static bool enableArrayProtoValues = true;
|
static bool enableArrayProtoValues = true;
|
||||||
|
static bool enableStreams = false;
|
||||||
static bool printTiming = false;
|
static bool printTiming = false;
|
||||||
static const char* jsCacheDir = nullptr;
|
static const char* jsCacheDir = nullptr;
|
||||||
static const char* jsCacheAsmJSPath = nullptr;
|
static const char* jsCacheAsmJSPath = nullptr;
|
||||||
@@ -7288,6 +7289,7 @@ SetContextOptions(JSContext* cx, const OptionParser& op)
|
|||||||
enableUnboxedArrays = op.getBoolOption("unboxed-arrays");
|
enableUnboxedArrays = op.getBoolOption("unboxed-arrays");
|
||||||
enableWasmAlwaysBaseline = op.getBoolOption("wasm-always-baseline");
|
enableWasmAlwaysBaseline = op.getBoolOption("wasm-always-baseline");
|
||||||
enableArrayProtoValues = !op.getBoolOption("no-array-proto-values");
|
enableArrayProtoValues = !op.getBoolOption("no-array-proto-values");
|
||||||
|
enableStreams = op.getBoolOption("enable-streams");
|
||||||
|
|
||||||
JS::ContextOptionsRef(cx).setBaseline(enableBaseline)
|
JS::ContextOptionsRef(cx).setBaseline(enableBaseline)
|
||||||
.setIon(enableIon)
|
.setIon(enableIon)
|
||||||
@@ -7296,7 +7298,8 @@ SetContextOptions(JSContext* cx, const OptionParser& op)
|
|||||||
.setWasmAlwaysBaseline(enableWasmAlwaysBaseline)
|
.setWasmAlwaysBaseline(enableWasmAlwaysBaseline)
|
||||||
.setNativeRegExp(enableNativeRegExp)
|
.setNativeRegExp(enableNativeRegExp)
|
||||||
.setUnboxedArrays(enableUnboxedArrays)
|
.setUnboxedArrays(enableUnboxedArrays)
|
||||||
.setArrayProtoValues(enableArrayProtoValues);
|
.setArrayProtoValues(enableArrayProtoValues)
|
||||||
|
.setStreams(enableStreams);
|
||||||
|
|
||||||
if (op.getBoolOption("wasm-check-bce"))
|
if (op.getBoolOption("wasm-check-bce"))
|
||||||
jit::JitOptions.wasmAlwaysCheckBounds = true;
|
jit::JitOptions.wasmAlwaysCheckBounds = true;
|
||||||
@@ -7568,7 +7571,8 @@ SetWorkerContextOptions(JSContext* cx)
|
|||||||
.setWasmAlwaysBaseline(enableWasmAlwaysBaseline)
|
.setWasmAlwaysBaseline(enableWasmAlwaysBaseline)
|
||||||
.setNativeRegExp(enableNativeRegExp)
|
.setNativeRegExp(enableNativeRegExp)
|
||||||
.setUnboxedArrays(enableUnboxedArrays)
|
.setUnboxedArrays(enableUnboxedArrays)
|
||||||
.setArrayProtoValues(enableArrayProtoValues);
|
.setArrayProtoValues(enableArrayProtoValues)
|
||||||
|
.setStreams(enableStreams);
|
||||||
cx->setOffthreadIonCompilationEnabled(offthreadCompilation);
|
cx->setOffthreadIonCompilationEnabled(offthreadCompilation);
|
||||||
cx->profilingScripts = enableCodeCoverage || enableDisassemblyDumps;
|
cx->profilingScripts = enableCodeCoverage || enableDisassemblyDumps;
|
||||||
|
|
||||||
@@ -7742,6 +7746,7 @@ main(int argc, char** argv, char** envp)
|
|||||||
|| !op.addBoolOption('\0', "wasm-always-baseline", "Enable wasm baseline compiler when possible")
|
|| !op.addBoolOption('\0', "wasm-always-baseline", "Enable wasm baseline compiler when possible")
|
||||||
|| !op.addBoolOption('\0', "wasm-check-bce", "Always generate wasm bounds check, even redundant ones.")
|
|| !op.addBoolOption('\0', "wasm-check-bce", "Always generate wasm bounds check, even redundant ones.")
|
||||||
|| !op.addBoolOption('\0', "no-array-proto-values", "Remove Array.prototype.values")
|
|| !op.addBoolOption('\0', "no-array-proto-values", "Remove Array.prototype.values")
|
||||||
|
|| !op.addBoolOption('\0', "enable-streams", "Enable WHATWG Streams")
|
||||||
#ifdef ENABLE_SHARED_ARRAY_BUFFER
|
#ifdef ENABLE_SHARED_ARRAY_BUFFER
|
||||||
|| !op.addStringOption('\0', "shared-memory", "on/off",
|
|| !op.addStringOption('\0', "shared-memory", "on/off",
|
||||||
"SharedArrayBuffer and Atomics "
|
"SharedArrayBuffer and Atomics "
|
||||||
|
|||||||
@@ -1258,15 +1258,16 @@ ArrayBufferObject::finalize(FreeOp* fop, JSObject* obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
ArrayBufferObject::copyData(Handle<ArrayBufferObject*> toBuffer,
|
ArrayBufferObject::copyData(Handle<ArrayBufferObject*> toBuffer, uint32_t toIndex,
|
||||||
Handle<ArrayBufferObject*> fromBuffer,
|
Handle<ArrayBufferObject*> fromBuffer, uint32_t fromIndex,
|
||||||
uint32_t fromIndex, uint32_t count)
|
uint32_t count)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(toBuffer->byteLength() >= count);
|
MOZ_ASSERT(toBuffer->byteLength() >= count);
|
||||||
|
MOZ_ASSERT(toBuffer->byteLength() >= toIndex + count);
|
||||||
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex);
|
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex);
|
||||||
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count);
|
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count);
|
||||||
|
|
||||||
memcpy(toBuffer->dataPointer(), fromBuffer->dataPointer() + fromIndex, count);
|
memcpy(toBuffer->dataPointer() + toIndex, fromBuffer->dataPointer() + fromIndex, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
@@ -1893,6 +1894,17 @@ JS_GetArrayBufferViewByteLength(JSObject* obj)
|
|||||||
: obj->as<TypedArrayObject>().byteLength();
|
: obj->as<TypedArrayObject>().byteLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS_FRIEND_API(uint32_t)
|
||||||
|
JS_GetArrayBufferViewByteOffset(JSObject* obj)
|
||||||
|
{
|
||||||
|
obj = CheckedUnwrap(obj);
|
||||||
|
if (!obj)
|
||||||
|
return 0;
|
||||||
|
return obj->is<DataViewObject>()
|
||||||
|
? obj->as<DataViewObject>().byteOffset()
|
||||||
|
: obj->as<TypedArrayObject>().byteOffset();
|
||||||
|
}
|
||||||
|
|
||||||
JS_FRIEND_API(JSObject*)
|
JS_FRIEND_API(JSObject*)
|
||||||
JS_GetObjectAsArrayBufferView(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data)
|
JS_GetObjectAsArrayBufferView(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -261,9 +261,9 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
static bool createTypedArrayFromBuffer(JSContext* cx, unsigned argc, Value* vp);
|
static bool createTypedArrayFromBuffer(JSContext* cx, unsigned argc, Value* vp);
|
||||||
|
|
||||||
static void copyData(Handle<ArrayBufferObject*> toBuffer,
|
static void copyData(Handle<ArrayBufferObject*> toBuffer, uint32_t toIndex,
|
||||||
Handle<ArrayBufferObject*> fromBuffer,
|
Handle<ArrayBufferObject*> fromBuffer, uint32_t fromIndex,
|
||||||
uint32_t fromIndex, uint32_t count);
|
uint32_t count);
|
||||||
|
|
||||||
static void trace(JSTracer* trc, JSObject* obj);
|
static void trace(JSTracer* trc, JSObject* obj);
|
||||||
static void objectMoved(JSObject* obj, const JSObject* old);
|
static void objectMoved(JSObject* obj, const JSObject* old);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
macro(anonymous, anonymous, "anonymous") \
|
macro(anonymous, anonymous, "anonymous") \
|
||||||
macro(Any, Any, "Any") \
|
macro(Any, Any, "Any") \
|
||||||
macro(apply, apply, "apply") \
|
macro(apply, apply, "apply") \
|
||||||
|
macro(AcquireReadableStreamBYOBReader, AcquireReadableStreamBYOBReader, "AcquireReadableStreamBYOBReader") \
|
||||||
|
macro(AcquireReadableStreamDefaultReader, AcquireReadableStreamDefaultReader, "AcquireReadableStreamDefaultReader") \
|
||||||
macro(arguments, arguments, "arguments") \
|
macro(arguments, arguments, "arguments") \
|
||||||
macro(ArrayBufferSpecies, ArrayBufferSpecies, "ArrayBufferSpecies") \
|
macro(ArrayBufferSpecies, ArrayBufferSpecies, "ArrayBufferSpecies") \
|
||||||
macro(ArrayIterator, ArrayIterator, "Array Iterator") \
|
macro(ArrayIterator, ArrayIterator, "Array Iterator") \
|
||||||
@@ -34,6 +36,7 @@
|
|||||||
macro(AsyncGeneratorFunction, AsyncGeneratorFunction, "AsyncGeneratorFunction") \
|
macro(AsyncGeneratorFunction, AsyncGeneratorFunction, "AsyncGeneratorFunction") \
|
||||||
macro(AsyncWrapped, AsyncWrapped, "AsyncWrapped") \
|
macro(AsyncWrapped, AsyncWrapped, "AsyncWrapped") \
|
||||||
macro(async, async, "async") \
|
macro(async, async, "async") \
|
||||||
|
macro(autoAllocateChunkSize, autoAllocateChunkSize, "autoAllocateChunkSize") \
|
||||||
macro(await, await, "await") \
|
macro(await, await, "await") \
|
||||||
macro(Bool8x16, Bool8x16, "Bool8x16") \
|
macro(Bool8x16, Bool8x16, "Bool8x16") \
|
||||||
macro(Bool16x8, Bool16x8, "Bool16x8") \
|
macro(Bool16x8, Bool16x8, "Bool16x8") \
|
||||||
@@ -45,6 +48,7 @@
|
|||||||
macro(buffer, buffer, "buffer") \
|
macro(buffer, buffer, "buffer") \
|
||||||
macro(builder, builder, "builder") \
|
macro(builder, builder, "builder") \
|
||||||
macro(by, by, "by") \
|
macro(by, by, "by") \
|
||||||
|
macro(byob, byob, "byob") \
|
||||||
macro(byteAlignment, byteAlignment, "byteAlignment") \
|
macro(byteAlignment, byteAlignment, "byteAlignment") \
|
||||||
macro(byteLength, byteLength, "byteLength") \
|
macro(byteLength, byteLength, "byteLength") \
|
||||||
macro(byteOffset, byteOffset, "byteOffset") \
|
macro(byteOffset, byteOffset, "byteOffset") \
|
||||||
@@ -55,6 +59,7 @@
|
|||||||
macro(callee, callee, "callee") \
|
macro(callee, callee, "callee") \
|
||||||
macro(caller, caller, "caller") \
|
macro(caller, caller, "caller") \
|
||||||
macro(callFunction, callFunction, "callFunction") \
|
macro(callFunction, callFunction, "callFunction") \
|
||||||
|
macro(cancel, cancel, "cancel") \
|
||||||
macro(case, case_, "case") \
|
macro(case, case_, "case") \
|
||||||
macro(caseFirst, caseFirst, "caseFirst") \
|
macro(caseFirst, caseFirst, "caseFirst") \
|
||||||
macro(catch, catch_, "catch") \
|
macro(catch, catch_, "catch") \
|
||||||
@@ -164,6 +169,7 @@
|
|||||||
macro(has, has, "has") \
|
macro(has, has, "has") \
|
||||||
macro(hasOwn, hasOwn, "hasOwn") \
|
macro(hasOwn, hasOwn, "hasOwn") \
|
||||||
macro(hasOwnProperty, hasOwnProperty, "hasOwnProperty") \
|
macro(hasOwnProperty, hasOwnProperty, "hasOwnProperty") \
|
||||||
|
macro(highWaterMark, highWaterMark, "highWaterMark") \
|
||||||
macro(hour, hour, "hour") \
|
macro(hour, hour, "hour") \
|
||||||
macro(if, if_, "if") \
|
macro(if, if_, "if") \
|
||||||
macro(ignoreCase, ignoreCase, "ignoreCase") \
|
macro(ignoreCase, ignoreCase, "ignoreCase") \
|
||||||
@@ -224,6 +230,7 @@
|
|||||||
macro(minimumSignificantDigits, minimumSignificantDigits, "minimumSignificantDigits") \
|
macro(minimumSignificantDigits, minimumSignificantDigits, "minimumSignificantDigits") \
|
||||||
macro(minute, minute, "minute") \
|
macro(minute, minute, "minute") \
|
||||||
macro(missingArguments, missingArguments, "missingArguments") \
|
macro(missingArguments, missingArguments, "missingArguments") \
|
||||||
|
macro(mode, mode, "mode") \
|
||||||
macro(module, module, "module") \
|
macro(module, module, "module") \
|
||||||
macro(Module, Module, "Module") \
|
macro(Module, Module, "Module") \
|
||||||
macro(ModuleInstantiate, ModuleInstantiate, "ModuleInstantiate") \
|
macro(ModuleInstantiate, ModuleInstantiate, "ModuleInstantiate") \
|
||||||
@@ -271,6 +278,7 @@
|
|||||||
macro(pattern, pattern, "pattern") \
|
macro(pattern, pattern, "pattern") \
|
||||||
macro(pending, pending, "pending") \
|
macro(pending, pending, "pending") \
|
||||||
macro(public, public_, "public") \
|
macro(public, public_, "public") \
|
||||||
|
macro(pull, pull, "pull") \
|
||||||
macro(preventExtensions, preventExtensions, "preventExtensions") \
|
macro(preventExtensions, preventExtensions, "preventExtensions") \
|
||||||
macro(private, private_, "private") \
|
macro(private, private_, "private") \
|
||||||
macro(promise, promise, "promise") \
|
macro(promise, promise, "promise") \
|
||||||
@@ -280,6 +288,50 @@
|
|||||||
macro(prototype, prototype, "prototype") \
|
macro(prototype, prototype, "prototype") \
|
||||||
macro(proxy, proxy, "proxy") \
|
macro(proxy, proxy, "proxy") \
|
||||||
macro(raw, raw, "raw") \
|
macro(raw, raw, "raw") \
|
||||||
|
macro(ReadableByteStreamControllerGetDesiredSize, \
|
||||||
|
ReadableByteStreamControllerGetDesiredSize, \
|
||||||
|
"ReadableByteStreamControllerGetDesiredSize") \
|
||||||
|
macro(ReadableByteStreamController_close, \
|
||||||
|
ReadableByteStreamController_close, \
|
||||||
|
"ReadableByteStreamController_close") \
|
||||||
|
macro(ReadableByteStreamController_enqueue, \
|
||||||
|
ReadableByteStreamController_enqueue, \
|
||||||
|
"ReadableByteStreamController_enqueue") \
|
||||||
|
macro(ReadableByteStreamController_error, \
|
||||||
|
ReadableByteStreamController_error, \
|
||||||
|
"ReadableByteStreamController_error") \
|
||||||
|
macro(ReadableStreamBYOBReader_cancel, \
|
||||||
|
ReadableStreamBYOBReader_cancel, \
|
||||||
|
"ReadableStreamBYOBReader_cancel") \
|
||||||
|
macro(ReadableStreamBYOBReader_read, \
|
||||||
|
ReadableStreamBYOBReader_read, \
|
||||||
|
"ReadableStreamBYOBReader_read") \
|
||||||
|
macro(ReadableStreamBYOBReader_releaseLock, \
|
||||||
|
ReadableStreamBYOBReader_releaseLock, \
|
||||||
|
"ReadableStreamBYOBReader_releaseLock") \
|
||||||
|
macro(ReadableStream_cancel, ReadableStream_cancel, "ReadableStream_cancel") \
|
||||||
|
macro(ReadableStreamDefaultControllerGetDesiredSize, \
|
||||||
|
ReadableStreamDefaultControllerGetDesiredSize, \
|
||||||
|
"ReadableStreamDefaultControllerGetDesiredSize") \
|
||||||
|
macro(ReadableStreamDefaultController_close, \
|
||||||
|
ReadableStreamDefaultController_close, \
|
||||||
|
"ReadableStreamDefaultController_close") \
|
||||||
|
macro(ReadableStreamDefaultController_enqueue, \
|
||||||
|
ReadableStreamDefaultController_enqueue, \
|
||||||
|
"ReadableStreamDefaultController_enqueue") \
|
||||||
|
macro(ReadableStreamDefaultController_error, \
|
||||||
|
ReadableStreamDefaultController_error, \
|
||||||
|
"ReadableStreamDefaultController_error") \
|
||||||
|
macro(ReadableStreamDefaultReader_cancel, \
|
||||||
|
ReadableStreamDefaultReader_cancel, \
|
||||||
|
"ReadableStreamDefaultReader_cancel") \
|
||||||
|
macro(ReadableStreamDefaultReader_read, \
|
||||||
|
ReadableStreamDefaultReader_read, \
|
||||||
|
"ReadableStreamDefaultReader_read") \
|
||||||
|
macro(ReadableStreamDefaultReader_releaseLock, \
|
||||||
|
ReadableStreamDefaultReader_releaseLock, \
|
||||||
|
"ReadableStreamDefaultReader_releaseLock") \
|
||||||
|
macro(ReadableStreamTee, ReadableStreamTee, "ReadableStreamTee") \
|
||||||
macro(reason, reason, "reason") \
|
macro(reason, reason, "reason") \
|
||||||
macro(RegExpFlagsGetter, RegExpFlagsGetter, "RegExpFlagsGetter") \
|
macro(RegExpFlagsGetter, RegExpFlagsGetter, "RegExpFlagsGetter") \
|
||||||
macro(RegExpStringIterator, RegExpStringIterator, "RegExp String Iterator") \
|
macro(RegExpStringIterator, RegExpStringIterator, "RegExp String Iterator") \
|
||||||
@@ -311,6 +363,7 @@
|
|||||||
macro(StarGeneratorNext, StarGeneratorNext, "StarGeneratorNext") \
|
macro(StarGeneratorNext, StarGeneratorNext, "StarGeneratorNext") \
|
||||||
macro(StarGeneratorReturn, StarGeneratorReturn, "StarGeneratorReturn") \
|
macro(StarGeneratorReturn, StarGeneratorReturn, "StarGeneratorReturn") \
|
||||||
macro(StarGeneratorThrow, StarGeneratorThrow, "StarGeneratorThrow") \
|
macro(StarGeneratorThrow, StarGeneratorThrow, "StarGeneratorThrow") \
|
||||||
|
macro(start, start, "start") \
|
||||||
macro(startTimestamp, startTimestamp, "startTimestamp") \
|
macro(startTimestamp, startTimestamp, "startTimestamp") \
|
||||||
macro(state, state, "state") \
|
macro(state, state, "state") \
|
||||||
macro(static, static_, "static") \
|
macro(static, static_, "static") \
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "builtin/Promise.h"
|
#include "builtin/Promise.h"
|
||||||
#include "builtin/RegExp.h"
|
#include "builtin/RegExp.h"
|
||||||
#include "builtin/SelfHostingDefines.h"
|
#include "builtin/SelfHostingDefines.h"
|
||||||
|
#include "builtin/Stream.h"
|
||||||
#include "builtin/SymbolObject.h"
|
#include "builtin/SymbolObject.h"
|
||||||
#include "builtin/TypedObject.h"
|
#include "builtin/TypedObject.h"
|
||||||
#include "builtin/WeakMapObject.h"
|
#include "builtin/WeakMapObject.h"
|
||||||
@@ -93,21 +94,27 @@ js::GlobalObject::getTypedObjectModule() const {
|
|||||||
/* static */ bool
|
/* static */ bool
|
||||||
GlobalObject::skipDeselectedConstructor(JSContext* cx, JSProtoKey key)
|
GlobalObject::skipDeselectedConstructor(JSContext* cx, JSProtoKey key)
|
||||||
{
|
{
|
||||||
if (key == JSProto_WebAssembly)
|
switch (key) {
|
||||||
|
case JSProto_WebAssembly:
|
||||||
return !wasm::HasSupport(cx);
|
return !wasm::HasSupport(cx);
|
||||||
|
|
||||||
#ifdef ENABLE_SHARED_ARRAY_BUFFER
|
case JSProto_ReadableStream:
|
||||||
// Return true if the given constructor has been disabled at run-time.
|
case JSProto_ReadableStreamDefaultReader:
|
||||||
switch (key) {
|
case JSProto_ReadableStreamBYOBReader:
|
||||||
|
case JSProto_ReadableStreamDefaultController:
|
||||||
|
case JSProto_ReadableByteStreamController:
|
||||||
|
case JSProto_ReadableStreamBYOBRequest:
|
||||||
|
case JSProto_ByteLengthQueuingStrategy:
|
||||||
|
case JSProto_CountQueuingStrategy:
|
||||||
|
return !cx->options().streams();
|
||||||
|
|
||||||
|
// Return true if the given constructor has been disabled at run-time.
|
||||||
case JSProto_Atomics:
|
case JSProto_Atomics:
|
||||||
case JSProto_SharedArrayBuffer:
|
case JSProto_SharedArrayBuffer:
|
||||||
return !cx->compartment()->creationOptions().getSharedMemoryAndAtomicsEnabled();
|
return !cx->compartment()->creationOptions().getSharedMemoryAndAtomicsEnabled();
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool
|
/* static */ bool
|
||||||
|
|||||||
@@ -156,6 +156,12 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime)
|
|||||||
startAsyncTaskCallback(nullptr),
|
startAsyncTaskCallback(nullptr),
|
||||||
finishAsyncTaskCallback(nullptr),
|
finishAsyncTaskCallback(nullptr),
|
||||||
promiseTasksToDestroy(mutexid::PromiseTaskPtrVector),
|
promiseTasksToDestroy(mutexid::PromiseTaskPtrVector),
|
||||||
|
readableStreamDataRequestCallback(nullptr),
|
||||||
|
readableStreamWriteIntoReadRequestCallback(nullptr),
|
||||||
|
readableStreamCancelCallback(nullptr),
|
||||||
|
readableStreamClosedCallback(nullptr),
|
||||||
|
readableStreamErroredCallback(nullptr),
|
||||||
|
readableStreamFinalizeCallback(nullptr),
|
||||||
exclusiveAccessLock(mutexid::RuntimeExclusiveAccess),
|
exclusiveAccessLock(mutexid::RuntimeExclusiveAccess),
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mainThreadHasExclusiveAccess(false),
|
mainThreadHasExclusiveAccess(false),
|
||||||
|
|||||||
@@ -651,6 +651,13 @@ struct JSRuntime : public JS::shadow::Runtime,
|
|||||||
JS::FinishAsyncTaskCallback finishAsyncTaskCallback;
|
JS::FinishAsyncTaskCallback finishAsyncTaskCallback;
|
||||||
js::ExclusiveData<js::PromiseTaskPtrVector> promiseTasksToDestroy;
|
js::ExclusiveData<js::PromiseTaskPtrVector> promiseTasksToDestroy;
|
||||||
|
|
||||||
|
JS::RequestReadableStreamDataCallback readableStreamDataRequestCallback;
|
||||||
|
JS::WriteIntoReadRequestBufferCallback readableStreamWriteIntoReadRequestCallback;
|
||||||
|
JS::CancelReadableStreamCallback readableStreamCancelCallback;
|
||||||
|
JS::ReadableStreamClosedCallback readableStreamClosedCallback;
|
||||||
|
JS::ReadableStreamErroredCallback readableStreamErroredCallback;
|
||||||
|
JS::ReadableStreamFinalizeCallback readableStreamFinalizeCallback;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*
|
/*
|
||||||
* Lock taken when using per-runtime or per-zone data that could otherwise
|
* Lock taken when using per-runtime or per-zone data that could otherwise
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "builtin/Reflect.h"
|
#include "builtin/Reflect.h"
|
||||||
#include "builtin/SelfHostingDefines.h"
|
#include "builtin/SelfHostingDefines.h"
|
||||||
#include "builtin/SIMD.h"
|
#include "builtin/SIMD.h"
|
||||||
|
#include "builtin/Stream.h"
|
||||||
#include "builtin/TypedObject.h"
|
#include "builtin/TypedObject.h"
|
||||||
#include "builtin/WeakSetObject.h"
|
#include "builtin/WeakSetObject.h"
|
||||||
#include "gc/Marking.h"
|
#include "gc/Marking.h"
|
||||||
@@ -64,7 +65,6 @@ using JS::AutoCheckCannotGC;
|
|||||||
using mozilla::IsInRange;
|
using mozilla::IsInRange;
|
||||||
using mozilla::Maybe;
|
using mozilla::Maybe;
|
||||||
using mozilla::PodMove;
|
using mozilla::PodMove;
|
||||||
using mozilla::Maybe;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
selfHosting_WarningReporter(JSContext* cx, JSErrorReport* report)
|
selfHosting_WarningReporter(JSContext* cx, JSErrorReport* report)
|
||||||
@@ -1088,9 +1088,9 @@ static bool
|
|||||||
intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
|
intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
|
||||||
{
|
{
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
MOZ_ASSERT(args.length() == 5);
|
MOZ_ASSERT(args.length() == 6);
|
||||||
|
|
||||||
bool isWrapped = args[4].toBoolean();
|
bool isWrapped = args[5].toBoolean();
|
||||||
Rooted<T*> toBuffer(cx);
|
Rooted<T*> toBuffer(cx);
|
||||||
if (!isWrapped) {
|
if (!isWrapped) {
|
||||||
toBuffer = &args[0].toObject().as<T>();
|
toBuffer = &args[0].toObject().as<T>();
|
||||||
@@ -1104,11 +1104,12 @@ intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
|
|||||||
}
|
}
|
||||||
toBuffer = toBufferObj.as<T>();
|
toBuffer = toBufferObj.as<T>();
|
||||||
}
|
}
|
||||||
Rooted<T*> fromBuffer(cx, &args[1].toObject().as<T>());
|
uint32_t toIndex = uint32_t(args[1].toInt32());
|
||||||
uint32_t fromIndex = uint32_t(args[2].toInt32());
|
Rooted<T*> fromBuffer(cx, &args[2].toObject().as<T>());
|
||||||
uint32_t count = uint32_t(args[3].toInt32());
|
uint32_t fromIndex = uint32_t(args[3].toInt32());
|
||||||
|
uint32_t count = uint32_t(args[4].toInt32());
|
||||||
|
|
||||||
T::copyData(toBuffer, fromBuffer, fromIndex, count);
|
T::copyData(toBuffer, toIndex, fromBuffer, fromIndex, count);
|
||||||
|
|
||||||
args.rval().setUndefined();
|
args.rval().setUndefined();
|
||||||
return true;
|
return true;
|
||||||
@@ -2481,14 +2482,14 @@ static const JSFunctionSpec intrinsic_functions[] = {
|
|||||||
intrinsic_PossiblyWrappedArrayBufferByteLength<ArrayBufferObject>, 1,0,
|
intrinsic_PossiblyWrappedArrayBufferByteLength<ArrayBufferObject>, 1,0,
|
||||||
IntrinsicPossiblyWrappedArrayBufferByteLength),
|
IntrinsicPossiblyWrappedArrayBufferByteLength),
|
||||||
JS_FN("ArrayBufferCopyData",
|
JS_FN("ArrayBufferCopyData",
|
||||||
intrinsic_ArrayBufferCopyData<ArrayBufferObject>, 5,0),
|
intrinsic_ArrayBufferCopyData<ArrayBufferObject>, 6,0),
|
||||||
|
|
||||||
JS_FN("SharedArrayBufferByteLength",
|
JS_FN("SharedArrayBufferByteLength",
|
||||||
intrinsic_ArrayBufferByteLength<SharedArrayBufferObject>, 1,0),
|
intrinsic_ArrayBufferByteLength<SharedArrayBufferObject>, 1,0),
|
||||||
JS_FN("PossiblyWrappedSharedArrayBufferByteLength",
|
JS_FN("PossiblyWrappedSharedArrayBufferByteLength",
|
||||||
intrinsic_PossiblyWrappedArrayBufferByteLength<SharedArrayBufferObject>, 1,0),
|
intrinsic_PossiblyWrappedArrayBufferByteLength<SharedArrayBufferObject>, 1,0),
|
||||||
JS_FN("SharedArrayBufferCopyData",
|
JS_FN("SharedArrayBufferCopyData",
|
||||||
intrinsic_ArrayBufferCopyData<SharedArrayBufferObject>, 5,0),
|
intrinsic_ArrayBufferCopyData<SharedArrayBufferObject>, 6,0),
|
||||||
|
|
||||||
JS_FN("IsUint8TypedArray", intrinsic_IsUint8TypedArray, 1,0),
|
JS_FN("IsUint8TypedArray", intrinsic_IsUint8TypedArray, 1,0),
|
||||||
JS_FN("IsInt8TypedArray", intrinsic_IsInt8TypedArray, 1,0),
|
JS_FN("IsInt8TypedArray", intrinsic_IsInt8TypedArray, 1,0),
|
||||||
@@ -2546,6 +2547,9 @@ static const JSFunctionSpec intrinsic_functions[] = {
|
|||||||
JS_FN("Promise_static_reject", Promise_reject, 1, 0),
|
JS_FN("Promise_static_reject", Promise_reject, 1, 0),
|
||||||
JS_FN("Promise_then", Promise_then, 2, 0),
|
JS_FN("Promise_then", Promise_then, 2, 0),
|
||||||
|
|
||||||
|
JS_FN("IsReadableStreamBYOBRequest",
|
||||||
|
intrinsic_IsInstanceOfBuiltin<ReadableStreamBYOBRequest>, 1, 0),
|
||||||
|
|
||||||
// See builtin/TypedObject.h for descriptors of the typedobj functions.
|
// See builtin/TypedObject.h for descriptors of the typedobj functions.
|
||||||
JS_FN("NewOpaqueTypedObject", js::NewOpaqueTypedObject, 1, 0),
|
JS_FN("NewOpaqueTypedObject", js::NewOpaqueTypedObject, 1, 0),
|
||||||
JS_FN("NewDerivedTypedObject", js::NewDerivedTypedObject, 3, 0),
|
JS_FN("NewDerivedTypedObject", js::NewDerivedTypedObject, 3, 0),
|
||||||
|
|||||||
@@ -331,15 +331,16 @@ SharedArrayBufferObject::addSizeOfExcludingThis(JSObject* obj, mozilla::MallocSi
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
SharedArrayBufferObject::copyData(Handle<SharedArrayBufferObject*> toBuffer,
|
SharedArrayBufferObject::copyData(Handle<SharedArrayBufferObject*> toBuffer, uint32_t toIndex,
|
||||||
Handle<SharedArrayBufferObject*> fromBuffer,
|
Handle<SharedArrayBufferObject*> fromBuffer, uint32_t fromIndex,
|
||||||
uint32_t fromIndex, uint32_t count)
|
uint32_t count)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(toBuffer->byteLength() >= count);
|
MOZ_ASSERT(toBuffer->byteLength() >= count);
|
||||||
|
MOZ_ASSERT(toBuffer->byteLength() >= toIndex + count);
|
||||||
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex);
|
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex);
|
||||||
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count);
|
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count);
|
||||||
|
|
||||||
jit::AtomicOperations::memcpySafeWhenRacy(toBuffer->dataPointerShared(),
|
jit::AtomicOperations::memcpySafeWhenRacy(toBuffer->dataPointerShared() + toIndex,
|
||||||
fromBuffer->dataPointerShared() + fromIndex,
|
fromBuffer->dataPointerShared() + fromIndex,
|
||||||
count);
|
count);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,9 +146,9 @@ class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared
|
|||||||
static void addSizeOfExcludingThis(JSObject* obj, mozilla::MallocSizeOf mallocSizeOf,
|
static void addSizeOfExcludingThis(JSObject* obj, mozilla::MallocSizeOf mallocSizeOf,
|
||||||
JS::ClassInfo* info);
|
JS::ClassInfo* info);
|
||||||
|
|
||||||
static void copyData(Handle<SharedArrayBufferObject*> toBuffer,
|
static void copyData(Handle<SharedArrayBufferObject*> toBuffer, uint32_t toIndex,
|
||||||
Handle<SharedArrayBufferObject*> fromBuffer,
|
Handle<SharedArrayBufferObject*> fromBuffer, uint32_t fromIndex,
|
||||||
uint32_t fromIndex, uint32_t count);
|
uint32_t count);
|
||||||
|
|
||||||
SharedArrayRawBuffer* rawBufferObject() const;
|
SharedArrayRawBuffer* rawBufferObject() const;
|
||||||
|
|
||||||
|
|||||||
@@ -1426,6 +1426,8 @@ ReloadPrefsCallback(const char* pref, void* data)
|
|||||||
|
|
||||||
bool extraWarnings = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict");
|
bool extraWarnings = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict");
|
||||||
|
|
||||||
|
bool streams = Preferences::GetBool(JS_OPTIONS_DOT_STR "streams");
|
||||||
|
|
||||||
bool unboxedObjects = Preferences::GetBool(JS_OPTIONS_DOT_STR "unboxed_objects");
|
bool unboxedObjects = Preferences::GetBool(JS_OPTIONS_DOT_STR "unboxed_objects");
|
||||||
|
|
||||||
sSharedMemoryEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "shared_memory");
|
sSharedMemoryEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "shared_memory");
|
||||||
@@ -1448,7 +1450,8 @@ ReloadPrefsCallback(const char* pref, void* data)
|
|||||||
.setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun)
|
.setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun)
|
||||||
.setWerror(werror)
|
.setWerror(werror)
|
||||||
.setExtraWarnings(extraWarnings)
|
.setExtraWarnings(extraWarnings)
|
||||||
.setArrayProtoValues(arrayProtoValues);
|
.setArrayProtoValues(arrayProtoValues)
|
||||||
|
.setStreams(streams);
|
||||||
|
|
||||||
JS_SetParallelParsingEnabled(cx, parallelParsing);
|
JS_SetParallelParsingEnabled(cx, parallelParsing);
|
||||||
JS_SetOffthreadIonCompilationEnabled(cx, offthreadIonCompilation);
|
JS_SetOffthreadIonCompilationEnabled(cx, offthreadIonCompilation);
|
||||||
|
|||||||
@@ -1333,6 +1333,9 @@ pref("javascript.options.shared_memory", true);
|
|||||||
pref("javascript.options.throw_on_debuggee_would_run", false);
|
pref("javascript.options.throw_on_debuggee_would_run", false);
|
||||||
pref("javascript.options.dump_stack_on_debuggee_would_run", false);
|
pref("javascript.options.dump_stack_on_debuggee_would_run", false);
|
||||||
|
|
||||||
|
// Streams API
|
||||||
|
pref("javascript.options.streams", false);
|
||||||
|
|
||||||
// advanced prefs
|
// advanced prefs
|
||||||
pref("advanced.mailftp", false);
|
pref("advanced.mailftp", false);
|
||||||
pref("image.animation_mode", "normal");
|
pref("image.animation_mode", "normal");
|
||||||
@@ -4745,6 +4748,9 @@ pref("dom.vibrator.max_vibrate_list_len", 128);
|
|||||||
// Abort API
|
// Abort API
|
||||||
pref("dom.abortController.enabled", true);
|
pref("dom.abortController.enabled", true);
|
||||||
|
|
||||||
|
// Streams API
|
||||||
|
pref("dom.streams.enabled", false);
|
||||||
|
|
||||||
// Push
|
// Push
|
||||||
pref("dom.push.enabled", false);
|
pref("dom.push.enabled", false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
[setrequestheader-content-type.htm]
|
[setrequestheader-content-type.htm]
|
||||||
type: testharness
|
type: testharness
|
||||||
[ReadableStream request respects setRequestHeader("")]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[ReadableStream request with under type sends no Content-Type without setRequestHeader() call]
|
[ReadableStream request with under type sends no Content-Type without setRequestHeader() call]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user