1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/* -*- 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/. */
/* Miscellaneous operations. */
#ifndef builtin_streams_MiscellaneousOperations_h
#define builtin_streams_MiscellaneousOperations_h
#include "mozilla/Attributes.h" // MOZ_MUST_USE
#include "jstypes.h" // JS_PUBLIC_API
#include "js/CallArgs.h" // JS::CallArgs
#include "js/RootingAPI.h" // JS::{,Mutable}Handle
#include "js/Value.h" // JS::Value
#include "vm/JSObject.h" // JSObject
#include "vm/PromiseObject.h" // js::PromiseObject
struct JS_PUBLIC_API JSContext;
namespace js {
class PropertyName;
extern MOZ_MUST_USE PromiseObject* PromiseRejectedWithPendingError(
JSContext* cx);
inline MOZ_MUST_USE bool ReturnPromiseRejectedWithPendingError(
JSContext* cx, const JS::CallArgs& args) {
PromiseObject* promise = PromiseRejectedWithPendingError(cx);
if (!promise) {
return false;
}
args.rval().setObject(*promise);
return true;
}
/**
* Streams spec, 6.3.1.
* CreateAlgorithmFromUnderlyingMethod ( underlyingObject, methodName,
* algoArgCount, extraArgs )
*
* This function only partly implements the standard algorithm. We do not
* actually create a new JSFunction completely encapsulating the new algorithm.
* Instead, this just gets the specified method and checks for errors. It's the
* caller's responsibility to make sure that later, when the algorithm is
* "performed", the appropriate steps are carried out.
*/
extern MOZ_MUST_USE bool CreateAlgorithmFromUnderlyingMethod(
JSContext* cx, JS::Handle<JS::Value> underlyingObject,
const char* methodNameForErrorMessage, JS::Handle<PropertyName*> methodName,
JS::MutableHandle<JS::Value> method);
/**
* Streams spec, 6.3.2. InvokeOrNoop ( O, P, args )
* As it happens, all callers pass exactly one argument.
*/
extern MOZ_MUST_USE bool InvokeOrNoop(JSContext* cx, JS::Handle<JS::Value> O,
JS::Handle<PropertyName*> P,
JS::Handle<JS::Value> arg,
JS::MutableHandle<JS::Value> rval);
/**
* Streams spec, 6.3.7. ValidateAndNormalizeHighWaterMark ( highWaterMark )
*/
extern MOZ_MUST_USE bool ValidateAndNormalizeHighWaterMark(
JSContext* cx, JS::Handle<JS::Value> highWaterMarkVal,
double* highWaterMark);
/**
* Streams spec, 6.3.8. MakeSizeAlgorithmFromSizeFunction ( size )
*/
extern MOZ_MUST_USE bool MakeSizeAlgorithmFromSizeFunction(
JSContext* cx, JS::Handle<JS::Value> size);
template <class T>
inline bool IsMaybeWrapped(const JS::Handle<JS::Value> v) {
return v.isObject() && v.toObject().canUnwrapAs<T>();
}
} // namespace js
#endif // builtin_streams_MiscellaneousOperations_h
|