Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ResolveSystemBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
#include "AbortControllerBinding.h"
2
#include "AbortSignalBinding.h"
3
#include "AddonManagerBinding.h"
4
#include "BrowsingContextBinding.h"
5
#include "ChannelWrapperBinding.h"
6
#include "ChromeUtilsBinding.h"
7
#include "ConsoleBinding.h"
8
#include "DOMErrorBinding.h"
9
#include "DOMExceptionBinding.h"
10
#include "DOMRequestBinding.h"
11
#include "DOMStringListBinding.h"
12
#include "DominatorTreeBinding.h"
13
#include "ErrorEventBinding.h"
14
#include "EventBinding.h"
15
#include "EventTargetBinding.h"
16
#include "FileReaderBinding.h"
17
#include "HeapSnapshotBinding.h"
18
#include "IDBCursorBinding.h"
19
#include "IDBDatabaseBinding.h"
20
#include "IDBFactoryBinding.h"
21
#include "IDBFileHandleBinding.h"
22
#include "IDBFileRequestBinding.h"
23
#include "IDBIndexBinding.h"
24
#include "IDBKeyRangeBinding.h"
25
#include "IDBMutableFileBinding.h"
26
#include "IDBObjectStoreBinding.h"
27
#include "IDBOpenDBRequestBinding.h"
28
#include "IDBRequestBinding.h"
29
#include "IDBTransactionBinding.h"
30
#include "IDBVersionChangeEventBinding.h"
31
#include "IdleDeadlineBinding.h"
32
#include "MatchGlobBinding.h"
33
#include "MatchPatternBinding.h"
34
#include "MessageChannelBinding.h"
35
#include "MessageEventBinding.h"
36
#include "MessagePortBinding.h"
37
#include "MozDocumentObserverBinding.h"
38
#include "PlacesEventBinding.h"
39
#include "PlacesObserversBinding.h"
40
#include "PrecompiledScriptBinding.h"
41
#include "PrioEncoderBinding.h"
42
#include "PromiseDebuggingBinding.h"
43
#include "StreamFilterBinding.h"
44
#include "StreamFilterDataEventBinding.h"
45
#include "StructuredCloneHolderBinding.h"
46
#include "TCPServerSocketBinding.h"
47
#include "TCPServerSocketEventBinding.h"
48
#include "TCPSocketBinding.h"
49
#include "TCPSocketErrorEventBinding.h"
50
#include "TCPSocketEventBinding.h"
51
#include "TextDecoderBinding.h"
52
#include "TextEncoderBinding.h"
53
#include "URLSearchParamsBinding.h"
54
#include "WebExtensionContentScriptBinding.h"
55
#include "WebExtensionPolicyBinding.h"
56
#include "WorkerBinding.h"
57
#include "js/Id.h"
58
#include "mozilla/dom/WebIDLGlobalNameHash.h"
59
#include "nsThreadUtils.h"
60
61
namespace mozilla {
62
namespace dom {
63
static const char *IdString(unsigned int aIndex)
64
195
{
65
195
  static const char table[] = "AbortController" "\0" "AbortSignal" "\0" "AddonManagerPermissions" "\0" "BrowsingContext" "\0" "ChannelWrapper" "\0" "ChromeUtils" "\0" "ChromeWorker" "\0" "ConsoleInstance" "\0" "DOMError" "\0" "DOMException" "\0" "DOMRequest" "\0" "DOMStringList" "\0" "DominatorTree" "\0" "ErrorEvent" "\0" "Event" "\0" "EventTarget" "\0" "FileReader" "\0" "HeapSnapshot" "\0" "IDBCursor" "\0" "IDBCursorWithValue" "\0" "IDBDatabase" "\0" "IDBFactory" "\0" "IDBFileHandle" "\0" "IDBFileRequest" "\0" "IDBIndex" "\0" "IDBKeyRange" "\0" "IDBLocaleAwareKeyRange" "\0" "IDBMutableFile" "\0" "IDBObjectStore" "\0" "IDBOpenDBRequest" "\0" "IDBRequest" "\0" "IDBTransaction" "\0" "IDBVersionChangeEvent" "\0" "IdleDeadline" "\0" "MatchGlob" "\0" "MatchPattern" "\0" "MatchPatternSet" "\0" "MessageChannel" "\0" "MessageEvent" "\0" "MessagePort" "\0" "MozDocumentMatcher" "\0" "MozDocumentObserver" "\0" "MozQueryInterface" "\0" "PlacesEvent" "\0" "PlacesObservers" "\0" "PlacesVisit" "\0" "PlacesWeakCallbackWrapper" "\0" "PrecompiledScript" "\0" "PrioEncoder" "\0" "PromiseDebugging" "\0" "StreamFilter" "\0" "StreamFilterDataEvent" "\0" "StructuredCloneHolder" "\0" "TCPServerSocket" "\0" "TCPServerSocketEvent" "\0" "TCPSocket" "\0" "TCPSocketErrorEvent" "\0" "TCPSocketEvent" "\0" "TextDecoder" "\0" "TextEncoder" "\0" "URLSearchParams" "\0" "WebExtensionContentScript" "\0" "WebExtensionPolicy" "\0" "Worker" "\0" "console";
66
195
  static const uint16_t indices[] = { 0, 16, 28, 52, 68, 83, 95, 108, 124, 133, 146, 157, 171, 185, 196, 202, 214, 225, 238, 248, 267, 279, 290, 304, 319, 328, 340, 363, 378, 393, 410, 421, 436, 458, 471, 481, 494, 510, 525, 538, 550, 569, 589, 607, 619, 635, 647, 673, 691, 703, 720, 733, 755, 777, 793, 814, 824, 844, 859, 871, 883, 899, 925, 944, 951 };
67
195
  static_assert(959 <= UINT16_MAX, "string table overflow!");
68
195
  return &table[indices[aIndex]];
69
195
}
70
71
struct SystemProperty
72
{
73
  WebIDLGlobalNameHash::ConstructorEnabled enabled;
74
  ProtoGetter define;
75
  PinnedStringId id;
76
};
77
78
static SystemProperty properties[] = {
79
  { nullptr, AbortController_Binding::GetConstructorObject },
80
  { nullptr, AbortSignal_Binding::GetConstructorObject },
81
  { AddonManagerPermissions_Binding::ConstructorEnabled, AddonManagerPermissions_Binding::GetConstructorObject },
82
  { BrowsingContext_Binding::ConstructorEnabled, BrowsingContext_Binding::GetConstructorObject },
83
  { ChannelWrapper_Binding::ConstructorEnabled, ChannelWrapper_Binding::GetConstructorObject },
84
  { ChromeUtils_Binding::ConstructorEnabled, ChromeUtils_Binding::GetConstructorObject },
85
  { ChromeWorker_Binding::ConstructorEnabled, ChromeWorker_Binding::GetConstructorObject },
86
  { ConsoleInstance_Binding::ConstructorEnabled, ConsoleInstance_Binding::GetConstructorObject },
87
  { nullptr, DOMError_Binding::GetConstructorObject },
88
  { nullptr, DOMException_Binding::GetConstructorObject },
89
  { nullptr, DOMRequest_Binding::GetConstructorObject },
90
  { nullptr, DOMStringList_Binding::GetConstructorObject },
91
  { DominatorTree_Binding::ConstructorEnabled, DominatorTree_Binding::GetConstructorObject },
92
  { nullptr, ErrorEvent_Binding::GetConstructorObject },
93
  { nullptr, Event_Binding::GetConstructorObject },
94
  { nullptr, EventTarget_Binding::GetConstructorObject },
95
  { nullptr, FileReader_Binding::GetConstructorObject },
96
  { HeapSnapshot_Binding::ConstructorEnabled, HeapSnapshot_Binding::GetConstructorObject },
97
  { nullptr, IDBCursor_Binding::GetConstructorObject },
98
  { nullptr, IDBCursorWithValue_Binding::GetConstructorObject },
99
  { nullptr, IDBDatabase_Binding::GetConstructorObject },
100
  { nullptr, IDBFactory_Binding::GetConstructorObject },
101
  { nullptr, IDBFileHandle_Binding::GetConstructorObject },
102
  { nullptr, IDBFileRequest_Binding::GetConstructorObject },
103
  { nullptr, IDBIndex_Binding::GetConstructorObject },
104
  { nullptr, IDBKeyRange_Binding::GetConstructorObject },
105
  { IDBLocaleAwareKeyRange_Binding::ConstructorEnabled, IDBLocaleAwareKeyRange_Binding::GetConstructorObject },
106
  { nullptr, IDBMutableFile_Binding::GetConstructorObject },
107
  { nullptr, IDBObjectStore_Binding::GetConstructorObject },
108
  { nullptr, IDBOpenDBRequest_Binding::GetConstructorObject },
109
  { nullptr, IDBRequest_Binding::GetConstructorObject },
110
  { nullptr, IDBTransaction_Binding::GetConstructorObject },
111
  { nullptr, IDBVersionChangeEvent_Binding::GetConstructorObject },
112
  { IdleDeadline_Binding::ConstructorEnabled, IdleDeadline_Binding::GetConstructorObject },
113
  { MatchGlob_Binding::ConstructorEnabled, MatchGlob_Binding::GetConstructorObject },
114
  { MatchPattern_Binding::ConstructorEnabled, MatchPattern_Binding::GetConstructorObject },
115
  { MatchPatternSet_Binding::ConstructorEnabled, MatchPatternSet_Binding::GetConstructorObject },
116
  { nullptr, MessageChannel_Binding::GetConstructorObject },
117
  { nullptr, MessageEvent_Binding::GetConstructorObject },
118
  { nullptr, MessagePort_Binding::GetConstructorObject },
119
  { MozDocumentMatcher_Binding::ConstructorEnabled, MozDocumentMatcher_Binding::GetConstructorObject },
120
  { MozDocumentObserver_Binding::ConstructorEnabled, MozDocumentObserver_Binding::GetConstructorObject },
121
  { MozQueryInterface_Binding::ConstructorEnabled, MozQueryInterface_Binding::GetConstructorObject },
122
  { PlacesEvent_Binding::ConstructorEnabled, PlacesEvent_Binding::GetConstructorObject },
123
  { PlacesObservers_Binding::ConstructorEnabled, PlacesObservers_Binding::GetConstructorObject },
124
  { PlacesVisit_Binding::ConstructorEnabled, PlacesVisit_Binding::GetConstructorObject },
125
  { PlacesWeakCallbackWrapper_Binding::ConstructorEnabled, PlacesWeakCallbackWrapper_Binding::GetConstructorObject },
126
  { PrecompiledScript_Binding::ConstructorEnabled, PrecompiledScript_Binding::GetConstructorObject },
127
  { PrioEncoder_Binding::ConstructorEnabled, PrioEncoder_Binding::GetConstructorObject },
128
  { PromiseDebugging_Binding::ConstructorEnabled, PromiseDebugging_Binding::GetConstructorObject },
129
  { StreamFilter_Binding::ConstructorEnabled, StreamFilter_Binding::GetConstructorObject },
130
  { StreamFilterDataEvent_Binding::ConstructorEnabled, StreamFilterDataEvent_Binding::GetConstructorObject },
131
  { StructuredCloneHolder_Binding::ConstructorEnabled, StructuredCloneHolder_Binding::GetConstructorObject },
132
  { TCPServerSocket_Binding::ConstructorEnabled, TCPServerSocket_Binding::GetConstructorObject },
133
  { TCPServerSocketEvent_Binding::ConstructorEnabled, TCPServerSocketEvent_Binding::GetConstructorObject },
134
  { TCPSocket_Binding::ConstructorEnabled, TCPSocket_Binding::GetConstructorObject },
135
  { TCPSocketErrorEvent_Binding::ConstructorEnabled, TCPSocketErrorEvent_Binding::GetConstructorObject },
136
  { TCPSocketEvent_Binding::ConstructorEnabled, TCPSocketEvent_Binding::GetConstructorObject },
137
  { nullptr, TextDecoder_Binding::GetConstructorObject },
138
  { nullptr, TextEncoder_Binding::GetConstructorObject },
139
  { nullptr, URLSearchParams_Binding::GetConstructorObject },
140
  { WebExtensionContentScript_Binding::ConstructorEnabled, WebExtensionContentScript_Binding::GetConstructorObject },
141
  { WebExtensionPolicy_Binding::ConstructorEnabled, WebExtensionPolicy_Binding::GetConstructorObject },
142
  { Worker_Binding::ConstructorEnabled, Worker_Binding::GetConstructorObject },
143
  { nullptr, console_Binding::GetConstructorObject },
144
};
145
146
static bool idsInited = false;
147
148
bool
149
SystemBindingInitIds(JSContext* aCx)
150
3
{
151
3
  MOZ_ASSERT(NS_IsMainThread());
152
3
153
3
  if (!idsInited) {
154
3
    // We can't use range-based for because we need the index to call IdString.
155
198
    for (uint32_t i = 0; i < ArrayLength(properties); ++i) {
156
195
      if (!properties[i].id.init(aCx, IdString(i))) {
157
0
        return false;
158
0
      }
159
195
    }
160
3
    idsInited = true;
161
3
  }
162
3
163
3
  return true;
164
3
}
165
166
bool
167
ResolveSystemBinding(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId, bool* aResolvedp)
168
49
{
169
49
  MOZ_ASSERT(NS_IsMainThread());
170
49
  MOZ_ASSERT(idsInited);
171
49
172
49
  if (JSID_IS_VOID(aId)) {
173
0
    for (const auto& property : properties) {
174
0
      if (!property.enabled || property.enabled(aCx, aObj)) {
175
0
        if (!property.define(aCx)) {
176
0
          return false;
177
0
        }
178
0
        *aResolvedp = true;
179
0
      }
180
0
    }
181
0
    return true;
182
49
  }
183
49
184
3.12k
  for (const auto& property : properties) {
185
3.12k
    if (property.id == aId) {
186
1
      if (!property.enabled || property.enabled(aCx, aObj)) {
187
1
        if (!property.define(aCx)) {
188
0
          return false;
189
0
        }
190
1
        *aResolvedp = true;
191
1
        break;
192
1
      }
193
1
    }
194
3.12k
  }
195
49
  return true;
196
49
}
197
198
bool
199
MayResolveAsSystemBindingName(jsid aId)
200
0
{
201
0
  MOZ_ASSERT(NS_IsMainThread());
202
0
  MOZ_ASSERT(idsInited);
203
0
204
0
  for (const auto& property : properties) {
205
0
    if (aId == property.id) {
206
0
      return true;
207
0
    }
208
0
  }
209
0
  return false;
210
0
}
211
212
void
213
GetSystemBindingNames(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::AutoIdVector& aNames, bool aEnumerableOnly, mozilla::ErrorResult& aRv)
214
0
{
215
0
  MOZ_ASSERT(NS_IsMainThread());
216
0
217
0
  if (aEnumerableOnly) {
218
0
    return;
219
0
  }
220
0
221
0
  if (!SystemBindingInitIds(aCx)) {
222
0
    aRv.NoteJSContextException(aCx);
223
0
    return;
224
0
  }
225
0
226
0
  for (const auto& property : properties) {
227
0
    if (!property.enabled || property.enabled(aCx, aObj)) {
228
0
      if (!aNames.append(property.id)) {
229
0
        aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
230
0
        return;
231
0
      }
232
0
    }
233
0
  }
234
0
}
235
236
} // namespace dom
237
} // namespace mozilla
238