Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/WebExtensionPolicyBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM WebExtensionPolicy.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "WebExtensionPolicyBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/NonRefcountedDOMObject.h"
10
#include "mozilla/dom/Nullable.h"
11
#include "mozilla/dom/PrimitiveConversions.h"
12
#include "mozilla/dom/ScriptSettings.h"
13
#include "mozilla/dom/UnionConversions.h"
14
#include "mozilla/extensions/MatchPattern.h"
15
#include "mozilla/extensions/WebExtensionContentScript.h"
16
#include "mozilla/extensions/WebExtensionPolicy.h"
17
#include "nsContentUtils.h"
18
#include "nsIURI.h"
19
#include "nsJSUtils.h"
20
#include "nsThreadUtils.h"
21
22
namespace mozilla {
23
namespace dom {
24
25
namespace binding_detail {}; // Just to make sure it's known as a namespace
26
using namespace mozilla::dom::binding_detail;
27
28
29
30
WebExtensionInit::WebExtensionInit()
31
0
{
32
0
  // Safe to pass a null context if we pass a null value
33
0
  Init(nullptr, JS::NullHandleValue);
34
0
}
35
36
37
bool
38
WebExtensionInit::InitIds(JSContext* cx, WebExtensionInitAtoms* atomsCache)
39
0
{
40
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
41
0
42
0
  // Initialize these in reverse order so that any failure leaves the first one
43
0
  // uninitialized.
44
0
  if (!atomsCache->webAccessibleResources_id.init(cx, "webAccessibleResources") ||
45
0
      !atomsCache->permissions_id.init(cx, "permissions") ||
46
0
      !atomsCache->name_id.init(cx, "name") ||
47
0
      !atomsCache->mozExtensionHostname_id.init(cx, "mozExtensionHostname") ||
48
0
      !atomsCache->localizeCallback_id.init(cx, "localizeCallback") ||
49
0
      !atomsCache->id_id.init(cx, "id") ||
50
0
      !atomsCache->contentSecurityPolicy_id.init(cx, "contentSecurityPolicy") ||
51
0
      !atomsCache->contentScripts_id.init(cx, "contentScripts") ||
52
0
      !atomsCache->baseURL_id.init(cx, "baseURL") ||
53
0
      !atomsCache->backgroundScripts_id.init(cx, "backgroundScripts") ||
54
0
      !atomsCache->allowedOrigins_id.init(cx, "allowedOrigins")) {
55
0
    return false;
56
0
  }
57
0
  return true;
58
0
}
59
60
bool
61
WebExtensionInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
62
0
{
63
0
  // Passing a null JSContext is OK only if we're initing from null,
64
0
  // Since in that case we will not have to do any property gets
65
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
66
0
  // checkers by static analysis tools
67
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
68
0
  WebExtensionInitAtoms* atomsCache = nullptr;
69
0
  if (cx) {
70
0
    atomsCache = GetAtomCache<WebExtensionInitAtoms>(cx);
71
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
72
0
      return false;
73
0
    }
74
0
  }
75
0
76
0
  if (!IsConvertibleToDictionary(val)) {
77
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
78
0
  }
79
0
80
0
  bool isNull = val.isNullOrUndefined();
81
0
  // We only need these if !isNull, in which case we have |cx|.
82
0
  Maybe<JS::Rooted<JSObject *> > object;
83
0
  Maybe<JS::Rooted<JS::Value> > temp;
84
0
  if (!isNull) {
85
0
    MOZ_ASSERT(cx);
86
0
    object.emplace(cx, &val.toObject());
87
0
    temp.emplace(cx);
88
0
  }
89
0
  if (!isNull) {
90
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->allowedOrigins_id, temp.ptr())) {
91
0
      return false;
92
0
    }
93
0
  }
94
0
  if (!isNull && !temp->isUndefined()) {
95
0
    {
96
0
      bool done = false, failed = false, tryNext;
97
0
      if (temp.ref().isObject()) {
98
0
        done = (failed = !mAllowedOrigins.TrySetToMatchPatternSet(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
99
0
100
0
        if (!done) {
101
0
          done = (failed = !mAllowedOrigins.TrySetToStringSequence(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
102
0
        }
103
0
      }
104
0
      if (failed) {
105
0
        return false;
106
0
      }
107
0
      if (!done) {
108
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'allowedOrigins' member of WebExtensionInit", "MatchPatternSet, StringSequence");
109
0
        return false;
110
0
      }
111
0
    }
112
0
    mIsAnyMemberPresent = true;
113
0
  } else if (cx) {
114
0
    // Don't error out if we have no cx.  In that
115
0
    // situation the caller is default-constructing us and we'll
116
0
    // just assume they know what they're doing.
117
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
118
0
                             "'allowedOrigins' member of WebExtensionInit");
119
0
  }
120
0
121
0
  if (!isNull) {
122
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->backgroundScripts_id, temp.ptr())) {
123
0
      return false;
124
0
    }
125
0
  }
126
0
  if (!isNull && !temp->isUndefined()) {
127
0
    if (temp.ref().isObject()) {
128
0
      JS::ForOfIterator iter(cx);
129
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
130
0
        return false;
131
0
      }
132
0
      if (!iter.valueIsIterable()) {
133
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'backgroundScripts' member of WebExtensionInit");
134
0
        return false;
135
0
      }
136
0
      Sequence<nsString> &arr = mBackgroundScripts.SetValue();
137
0
      JS::Rooted<JS::Value> temp(cx);
138
0
      while (true) {
139
0
        bool done;
140
0
        if (!iter.next(&temp, &done)) {
141
0
          return false;
142
0
        }
143
0
        if (done) {
144
0
          break;
145
0
        }
146
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
147
0
        if (!slotPtr) {
148
0
          JS_ReportOutOfMemory(cx);
149
0
          return false;
150
0
        }
151
0
        nsString& slot = *slotPtr;
152
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
153
0
          return false;
154
0
        }
155
0
      }
156
0
    } else if (temp.ref().isNullOrUndefined()) {
157
0
      mBackgroundScripts.SetNull();
158
0
    } else {
159
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'backgroundScripts' member of WebExtensionInit");
160
0
      return false;
161
0
    }
162
0
  } else {
163
0
    mBackgroundScripts.SetNull();
164
0
  }
165
0
  mIsAnyMemberPresent = true;
166
0
167
0
  if (!isNull) {
168
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->baseURL_id, temp.ptr())) {
169
0
      return false;
170
0
    }
171
0
  }
172
0
  if (!isNull && !temp->isUndefined()) {
173
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mBaseURL)) {
174
0
      return false;
175
0
    }
176
0
    mIsAnyMemberPresent = true;
177
0
  } else if (cx) {
178
0
    // Don't error out if we have no cx.  In that
179
0
    // situation the caller is default-constructing us and we'll
180
0
    // just assume they know what they're doing.
181
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
182
0
                             "'baseURL' member of WebExtensionInit");
183
0
  }
184
0
185
0
  if (!isNull) {
186
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->contentScripts_id, temp.ptr())) {
187
0
      return false;
188
0
    }
189
0
  }
190
0
  if (!isNull && !temp->isUndefined()) {
191
0
    if (temp.ref().isObject()) {
192
0
      JS::ForOfIterator iter(cx);
193
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
194
0
        return false;
195
0
      }
196
0
      if (!iter.valueIsIterable()) {
197
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'contentScripts' member of WebExtensionInit");
198
0
        return false;
199
0
      }
200
0
      Sequence<WebExtensionContentScriptInit> &arr = mContentScripts;
201
0
      JS::Rooted<JS::Value> temp(cx);
202
0
      while (true) {
203
0
        bool done;
204
0
        if (!iter.next(&temp, &done)) {
205
0
          return false;
206
0
        }
207
0
        if (done) {
208
0
          break;
209
0
        }
210
0
        WebExtensionContentScriptInit* slotPtr = arr.AppendElement(mozilla::fallible);
211
0
        if (!slotPtr) {
212
0
          JS_ReportOutOfMemory(cx);
213
0
          return false;
214
0
        }
215
0
        WebExtensionContentScriptInit& slot = *slotPtr;
216
0
        if (!slot.Init(cx, temp,  "Element of 'contentScripts' member of WebExtensionInit", passedToJSImpl)) {
217
0
          return false;
218
0
        }
219
0
      }
220
0
    } else {
221
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'contentScripts' member of WebExtensionInit");
222
0
      return false;
223
0
    }
224
0
  } else {
225
0
    /* Array is already empty; nothing to do */
226
0
  }
227
0
  mIsAnyMemberPresent = true;
228
0
229
0
  if (!isNull) {
230
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->contentSecurityPolicy_id, temp.ptr())) {
231
0
      return false;
232
0
    }
233
0
  }
234
0
  if (!isNull && !temp->isUndefined()) {
235
0
    if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mContentSecurityPolicy)) {
236
0
      return false;
237
0
    }
238
0
  } else {
239
0
    mContentSecurityPolicy.SetIsVoid(true);
240
0
  }
241
0
  mIsAnyMemberPresent = true;
242
0
243
0
  if (!isNull) {
244
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->id_id, temp.ptr())) {
245
0
      return false;
246
0
    }
247
0
  }
248
0
  if (!isNull && !temp->isUndefined()) {
249
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mId)) {
250
0
      return false;
251
0
    }
252
0
    mIsAnyMemberPresent = true;
253
0
  } else if (cx) {
254
0
    // Don't error out if we have no cx.  In that
255
0
    // situation the caller is default-constructing us and we'll
256
0
    // just assume they know what they're doing.
257
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
258
0
                             "'id' member of WebExtensionInit");
259
0
  }
260
0
261
0
  if (!isNull) {
262
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->localizeCallback_id, temp.ptr())) {
263
0
      return false;
264
0
    }
265
0
  }
266
0
  if (!isNull && !temp->isUndefined()) {
267
0
    if (temp.ref().isObject()) {
268
0
      if (JS::IsCallable(&temp.ref().toObject())) {
269
0
      { // scope for tempRoot and tempGlobalRoot if needed
270
0
        JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
271
0
        JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
272
0
        mLocalizeCallback = new WebExtensionLocalizeCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
273
0
      }
274
0
      } else {
275
0
        ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'localizeCallback' member of WebExtensionInit");
276
0
        return false;
277
0
      }
278
0
    } else {
279
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'localizeCallback' member of WebExtensionInit");
280
0
      return false;
281
0
    }
282
0
    mIsAnyMemberPresent = true;
283
0
  } else if (cx) {
284
0
    // Don't error out if we have no cx.  In that
285
0
    // situation the caller is default-constructing us and we'll
286
0
    // just assume they know what they're doing.
287
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
288
0
                             "'localizeCallback' member of WebExtensionInit");
289
0
  }
290
0
291
0
  if (!isNull) {
292
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->mozExtensionHostname_id, temp.ptr())) {
293
0
      return false;
294
0
    }
295
0
  }
296
0
  if (!isNull && !temp->isUndefined()) {
297
0
    if (!ConvertJSValueToByteString(cx, temp.ref(), false, mMozExtensionHostname)) {
298
0
      return false;
299
0
    }
300
0
    mIsAnyMemberPresent = true;
301
0
  } else if (cx) {
302
0
    // Don't error out if we have no cx.  In that
303
0
    // situation the caller is default-constructing us and we'll
304
0
    // just assume they know what they're doing.
305
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
306
0
                             "'mozExtensionHostname' member of WebExtensionInit");
307
0
  }
308
0
309
0
  if (!isNull) {
310
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
311
0
      return false;
312
0
    }
313
0
  }
314
0
  if (!isNull && !temp->isUndefined()) {
315
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
316
0
      return false;
317
0
    }
318
0
  } else {
319
0
    static const char16_t data[] = { 0 };
320
0
    mName.Rebind(data, ArrayLength(data) - 1);
321
0
  }
322
0
  mIsAnyMemberPresent = true;
323
0
324
0
  if (!isNull) {
325
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->permissions_id, temp.ptr())) {
326
0
      return false;
327
0
    }
328
0
  }
329
0
  if (!isNull && !temp->isUndefined()) {
330
0
    if (temp.ref().isObject()) {
331
0
      JS::ForOfIterator iter(cx);
332
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
333
0
        return false;
334
0
      }
335
0
      if (!iter.valueIsIterable()) {
336
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'permissions' member of WebExtensionInit");
337
0
        return false;
338
0
      }
339
0
      Sequence<nsString> &arr = mPermissions;
340
0
      JS::Rooted<JS::Value> temp(cx);
341
0
      while (true) {
342
0
        bool done;
343
0
        if (!iter.next(&temp, &done)) {
344
0
          return false;
345
0
        }
346
0
        if (done) {
347
0
          break;
348
0
        }
349
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
350
0
        if (!slotPtr) {
351
0
          JS_ReportOutOfMemory(cx);
352
0
          return false;
353
0
        }
354
0
        nsString& slot = *slotPtr;
355
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
356
0
          return false;
357
0
        }
358
0
      }
359
0
    } else {
360
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'permissions' member of WebExtensionInit");
361
0
      return false;
362
0
    }
363
0
  } else {
364
0
    /* Array is already empty; nothing to do */
365
0
  }
366
0
  mIsAnyMemberPresent = true;
367
0
368
0
  if (!isNull) {
369
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->webAccessibleResources_id, temp.ptr())) {
370
0
      return false;
371
0
    }
372
0
  }
373
0
  if (!isNull && !temp->isUndefined()) {
374
0
    if (temp.ref().isObject()) {
375
0
      JS::ForOfIterator iter(cx);
376
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
377
0
        return false;
378
0
      }
379
0
      if (!iter.valueIsIterable()) {
380
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'webAccessibleResources' member of WebExtensionInit");
381
0
        return false;
382
0
      }
383
0
      Sequence<OwningMatchGlobOrString> &arr = mWebAccessibleResources;
384
0
      JS::Rooted<JS::Value> temp(cx);
385
0
      while (true) {
386
0
        bool done;
387
0
        if (!iter.next(&temp, &done)) {
388
0
          return false;
389
0
        }
390
0
        if (done) {
391
0
          break;
392
0
        }
393
0
        OwningMatchGlobOrString* slotPtr = arr.AppendElement(mozilla::fallible);
394
0
        if (!slotPtr) {
395
0
          JS_ReportOutOfMemory(cx);
396
0
          return false;
397
0
        }
398
0
        OwningMatchGlobOrString& slot = *slotPtr;
399
0
        {
400
0
          bool done = false, failed = false, tryNext;
401
0
          if (temp.isObject()) {
402
0
            done = (failed = !slot.TrySetToMatchGlob(cx, temp, tryNext, passedToJSImpl)) || !tryNext;
403
0
404
0
          }
405
0
          if (!done) {
406
0
            do {
407
0
              done = (failed = !slot.TrySetToString(cx, temp, tryNext)) || !tryNext;
408
0
              break;
409
0
            } while (false);
410
0
          }
411
0
          if (failed) {
412
0
            return false;
413
0
          }
414
0
          if (!done) {
415
0
            ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Element of 'webAccessibleResources' member of WebExtensionInit", "MatchGlob");
416
0
            return false;
417
0
          }
418
0
        }
419
0
      }
420
0
    } else {
421
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'webAccessibleResources' member of WebExtensionInit");
422
0
      return false;
423
0
    }
424
0
  } else {
425
0
    /* Array is already empty; nothing to do */
426
0
  }
427
0
  mIsAnyMemberPresent = true;
428
0
  return true;
429
0
}
430
431
bool
432
WebExtensionInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
433
0
{
434
0
  WebExtensionInitAtoms* atomsCache = GetAtomCache<WebExtensionInitAtoms>(cx);
435
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
436
0
    return false;
437
0
  }
438
0
439
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
440
0
  if (!obj) {
441
0
    return false;
442
0
  }
443
0
  rval.set(JS::ObjectValue(*obj));
444
0
445
0
  do {
446
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
447
0
    JS::Rooted<JS::Value> temp(cx);
448
0
    OwningMatchPatternSetOrStringSequence const & currentValue = mAllowedOrigins;
449
0
    if (!currentValue.ToJSVal(cx, obj, &temp)) {
450
0
      return false;
451
0
    }
452
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->allowedOrigins_id, temp, JSPROP_ENUMERATE)) {
453
0
      return false;
454
0
    }
455
0
    break;
456
0
  } while(false);
457
0
458
0
  do {
459
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
460
0
    JS::Rooted<JS::Value> temp(cx);
461
0
    Nullable<Sequence<nsString>> const & currentValue = mBackgroundScripts;
462
0
463
0
    if (currentValue.IsNull()) {
464
0
      temp.setNull();
465
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->backgroundScripts_id, temp, JSPROP_ENUMERATE)) {
466
0
        return false;
467
0
      }
468
0
      break;
469
0
    }
470
0
471
0
    uint32_t length = currentValue.Value().Length();
472
0
    JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
473
0
    if (!returnArray) {
474
0
      return false;
475
0
    }
476
0
    // Scope for 'tmp'
477
0
    {
478
0
      JS::Rooted<JS::Value> tmp(cx);
479
0
      for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
480
0
        // Control block to let us common up the JS_DefineElement calls when there
481
0
        // are different ways to succeed at wrapping the object.
482
0
        do {
483
0
          if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], &tmp)) {
484
0
            return false;
485
0
          }
486
0
          break;
487
0
        } while (false);
488
0
        if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
489
0
                              JSPROP_ENUMERATE)) {
490
0
          return false;
491
0
        }
492
0
      }
493
0
    }
494
0
    temp.setObject(*returnArray);
495
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->backgroundScripts_id, temp, JSPROP_ENUMERATE)) {
496
0
      return false;
497
0
    }
498
0
    break;
499
0
  } while(false);
500
0
501
0
  do {
502
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
503
0
    JS::Rooted<JS::Value> temp(cx);
504
0
    nsString const & currentValue = mBaseURL;
505
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
506
0
      return false;
507
0
    }
508
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->baseURL_id, temp, JSPROP_ENUMERATE)) {
509
0
      return false;
510
0
    }
511
0
    break;
512
0
  } while(false);
513
0
514
0
  do {
515
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
516
0
    JS::Rooted<JS::Value> temp(cx);
517
0
    Sequence<WebExtensionContentScriptInit> const & currentValue = mContentScripts;
518
0
519
0
    uint32_t length = currentValue.Length();
520
0
    JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
521
0
    if (!returnArray) {
522
0
      return false;
523
0
    }
524
0
    // Scope for 'tmp'
525
0
    {
526
0
      JS::Rooted<JS::Value> tmp(cx);
527
0
      for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
528
0
        // Control block to let us common up the JS_DefineElement calls when there
529
0
        // are different ways to succeed at wrapping the object.
530
0
        do {
531
0
          if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
532
0
            return false;
533
0
          }
534
0
          break;
535
0
        } while (false);
536
0
        if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
537
0
                              JSPROP_ENUMERATE)) {
538
0
          return false;
539
0
        }
540
0
      }
541
0
    }
542
0
    temp.setObject(*returnArray);
543
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->contentScripts_id, temp, JSPROP_ENUMERATE)) {
544
0
      return false;
545
0
    }
546
0
    break;
547
0
  } while(false);
548
0
549
0
  do {
550
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
551
0
    JS::Rooted<JS::Value> temp(cx);
552
0
    nsString const & currentValue = mContentSecurityPolicy;
553
0
    if (!xpc::StringToJsval(cx, currentValue, &temp)) {
554
0
      return false;
555
0
    }
556
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->contentSecurityPolicy_id, temp, JSPROP_ENUMERATE)) {
557
0
      return false;
558
0
    }
559
0
    break;
560
0
  } while(false);
561
0
562
0
  do {
563
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
564
0
    JS::Rooted<JS::Value> temp(cx);
565
0
    nsString const & currentValue = mId;
566
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
567
0
      return false;
568
0
    }
569
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->id_id, temp, JSPROP_ENUMERATE)) {
570
0
      return false;
571
0
    }
572
0
    break;
573
0
  } while(false);
574
0
575
0
  do {
576
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
577
0
    JS::Rooted<JS::Value> temp(cx);
578
0
    OwningNonNull<WebExtensionLocalizeCallback> const & currentValue = mLocalizeCallback;
579
0
    temp.setObjectOrNull(GetCallbackFromCallbackObject(cx, currentValue));
580
0
    if (!MaybeWrapObjectValue(cx, &temp)) {
581
0
      return false;
582
0
    }
583
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->localizeCallback_id, temp, JSPROP_ENUMERATE)) {
584
0
      return false;
585
0
    }
586
0
    break;
587
0
  } while(false);
588
0
589
0
  do {
590
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
591
0
    JS::Rooted<JS::Value> temp(cx);
592
0
    nsCString const & currentValue = mMozExtensionHostname;
593
0
    if (!NonVoidByteStringToJsval(cx, currentValue, &temp)) {
594
0
      return false;
595
0
    }
596
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->mozExtensionHostname_id, temp, JSPROP_ENUMERATE)) {
597
0
      return false;
598
0
    }
599
0
    break;
600
0
  } while(false);
601
0
602
0
  do {
603
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
604
0
    JS::Rooted<JS::Value> temp(cx);
605
0
    nsString const & currentValue = mName;
606
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
607
0
      return false;
608
0
    }
609
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
610
0
      return false;
611
0
    }
612
0
    break;
613
0
  } while(false);
614
0
615
0
  do {
616
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
617
0
    JS::Rooted<JS::Value> temp(cx);
618
0
    Sequence<nsString> const & currentValue = mPermissions;
619
0
620
0
    uint32_t length = currentValue.Length();
621
0
    JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
622
0
    if (!returnArray) {
623
0
      return false;
624
0
    }
625
0
    // Scope for 'tmp'
626
0
    {
627
0
      JS::Rooted<JS::Value> tmp(cx);
628
0
      for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
629
0
        // Control block to let us common up the JS_DefineElement calls when there
630
0
        // are different ways to succeed at wrapping the object.
631
0
        do {
632
0
          if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
633
0
            return false;
634
0
          }
635
0
          break;
636
0
        } while (false);
637
0
        if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
638
0
                              JSPROP_ENUMERATE)) {
639
0
          return false;
640
0
        }
641
0
      }
642
0
    }
643
0
    temp.setObject(*returnArray);
644
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->permissions_id, temp, JSPROP_ENUMERATE)) {
645
0
      return false;
646
0
    }
647
0
    break;
648
0
  } while(false);
649
0
650
0
  do {
651
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
652
0
    JS::Rooted<JS::Value> temp(cx);
653
0
    Sequence<OwningMatchGlobOrString> const & currentValue = mWebAccessibleResources;
654
0
655
0
    uint32_t length = currentValue.Length();
656
0
    JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
657
0
    if (!returnArray) {
658
0
      return false;
659
0
    }
660
0
    // Scope for 'tmp'
661
0
    {
662
0
      JS::Rooted<JS::Value> tmp(cx);
663
0
      for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
664
0
        // Control block to let us common up the JS_DefineElement calls when there
665
0
        // are different ways to succeed at wrapping the object.
666
0
        do {
667
0
          if (!currentValue[sequenceIdx0].ToJSVal(cx, returnArray, &tmp)) {
668
0
            return false;
669
0
          }
670
0
          break;
671
0
        } while (false);
672
0
        if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
673
0
                              JSPROP_ENUMERATE)) {
674
0
          return false;
675
0
        }
676
0
      }
677
0
    }
678
0
    temp.setObject(*returnArray);
679
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->webAccessibleResources_id, temp, JSPROP_ENUMERATE)) {
680
0
      return false;
681
0
    }
682
0
    break;
683
0
  } while(false);
684
0
685
0
  return true;
686
0
}
687
688
void
689
WebExtensionInit::TraceDictionary(JSTracer* trc)
690
0
{
691
0
}
692
693
694
695
namespace binding_detail {
696
} // namespace binding_detail
697
698
699
void
700
WebExtensionLocalizeCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& unlocalizedText, nsString& aRetVal, ErrorResult& aRv)
701
0
{
702
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
703
0
  JS::AutoValueVector argv(cx);
704
0
  if (!argv.resize(1)) {
705
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
706
0
    return;
707
0
  }
708
0
  unsigned argc = 1;
709
0
710
0
  do {
711
0
    nsString mutableStr(unlocalizedText);
712
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
713
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
714
0
      return;
715
0
    }
716
0
    break;
717
0
  } while (false);
718
0
719
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
720
0
  if (!JS::Call(cx, aThisVal, callable,
721
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
722
0
    aRv.NoteJSContextException(cx);
723
0
    return;
724
0
  }
725
0
  binding_detail::FakeString rvalDecl;
726
0
  if (!ConvertJSValueToString(cx, rval, eStringify, eStringify, rvalDecl)) {
727
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
728
0
    return;
729
0
  }
730
0
  aRetVal = rvalDecl;
731
0
}
732
733
734
735
namespace binding_detail {
736
} // namespace binding_detail
737
738
739
namespace WebExtensionPolicy_Binding {
740
741
static bool
742
get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
743
0
{
744
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.id", DOM, cx);
745
0
746
0
  // Have to either root across the getter call or reget after.
747
0
  JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
748
0
  MOZ_ASSERT(IsDOMObject(slotStorage));
749
0
  const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 0);
750
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
751
0
  {
752
0
    // Scope for cachedVal
753
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
754
0
    if (!cachedVal.isUndefined()) {
755
0
      args.rval().set(cachedVal);
756
0
      // The cached value is in the compartment of slotStorage,
757
0
      // so wrap into the caller compartment as needed.
758
0
      if (MaybeWrapValue(cx, args.rval())) {
759
0
        return true;
760
0
      }
761
0
      return false;
762
0
    }
763
0
  }
764
0
765
0
  DOMString result;
766
0
  self->GetId(result);
767
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
768
0
  {
769
0
    JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
770
0
    JSAutoRealm ar(cx, conversionScope);
771
0
    do { // block we break out of when done wrapping
772
0
      if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
773
0
        return false;
774
0
      }
775
0
      break;
776
0
    } while (false);
777
0
  }
778
0
  { // And now store things in the realm of our slotStorage.
779
0
    JSAutoRealm ar(cx, slotStorage);
780
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
781
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
782
0
    if (!MaybeWrapValue(cx, &storedVal)) {
783
0
      return false;
784
0
    }
785
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
786
0
  }
787
0
  // And now make sure args.rval() is in the caller realm.
788
0
  if (MaybeWrapValue(cx, args.rval())) {
789
0
    return true;
790
0
  }
791
0
  return false;
792
0
}
793
794
static const JSJitInfo id_getterinfo = {
795
  { (JSJitGetterOp)get_id },
796
  { prototypes::id::WebExtensionPolicy },
797
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
798
  JSJitInfo::Getter,
799
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
800
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
801
  false,  /* isInfallible. False in setters. */
802
  true,  /* isMovable.  Not relevant for setters. */
803
  true, /* isEliminatable.  Not relevant for setters. */
804
  true, /* isAlwaysInSlot.  Only relevant for getters. */
805
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
806
  false,  /* isTypedMethod.  Only relevant for methods. */
807
  (DOM_INSTANCE_RESERVED_SLOTS + 0)   /* Reserved slot index, if we're stored in a slot, else 0. */
808
};
809
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
810
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 5, "There is no slot for us");
811
812
static bool
813
get_mozExtensionHostname(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
814
0
{
815
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.mozExtensionHostname", DOM, cx);
816
0
817
0
  // Have to either root across the getter call or reget after.
818
0
  JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
819
0
  MOZ_ASSERT(IsDOMObject(slotStorage));
820
0
  const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 1);
821
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
822
0
  {
823
0
    // Scope for cachedVal
824
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
825
0
    if (!cachedVal.isUndefined()) {
826
0
      args.rval().set(cachedVal);
827
0
      // The cached value is in the compartment of slotStorage,
828
0
      // so wrap into the caller compartment as needed.
829
0
      if (MaybeWrapValue(cx, args.rval())) {
830
0
        return true;
831
0
      }
832
0
      return false;
833
0
    }
834
0
  }
835
0
836
0
  nsCString result;
837
0
  self->GetMozExtensionHostname(result);
838
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
839
0
  {
840
0
    JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
841
0
    JSAutoRealm ar(cx, conversionScope);
842
0
    do { // block we break out of when done wrapping
843
0
      if (!NonVoidByteStringToJsval(cx, result, args.rval())) {
844
0
        return false;
845
0
      }
846
0
      break;
847
0
    } while (false);
848
0
  }
849
0
  { // And now store things in the realm of our slotStorage.
850
0
    JSAutoRealm ar(cx, slotStorage);
851
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
852
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
853
0
    if (!MaybeWrapValue(cx, &storedVal)) {
854
0
      return false;
855
0
    }
856
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
857
0
  }
858
0
  // And now make sure args.rval() is in the caller realm.
859
0
  if (MaybeWrapValue(cx, args.rval())) {
860
0
    return true;
861
0
  }
862
0
  return false;
863
0
}
864
865
static const JSJitInfo mozExtensionHostname_getterinfo = {
866
  { (JSJitGetterOp)get_mozExtensionHostname },
867
  { prototypes::id::WebExtensionPolicy },
868
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
869
  JSJitInfo::Getter,
870
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
871
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
872
  false,  /* isInfallible. False in setters. */
873
  true,  /* isMovable.  Not relevant for setters. */
874
  true, /* isEliminatable.  Not relevant for setters. */
875
  true, /* isAlwaysInSlot.  Only relevant for getters. */
876
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
877
  false,  /* isTypedMethod.  Only relevant for methods. */
878
  (DOM_INSTANCE_RESERVED_SLOTS + 1)   /* Reserved slot index, if we're stored in a slot, else 0. */
879
};
880
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) <= JSJitInfo::maxSlotIndex, "We won't fit");
881
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) < 5, "There is no slot for us");
882
883
MOZ_CAN_RUN_SCRIPT static bool
884
get_baseURL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
885
0
{
886
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.baseURL", DOM, cx);
887
0
888
0
  nsCString result;
889
0
  self->GetBaseURL(result);
890
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
891
0
  if (!NonVoidByteStringToJsval(cx, result, args.rval())) {
892
0
    return false;
893
0
  }
894
0
  return true;
895
0
}
896
897
static const JSJitInfo baseURL_getterinfo = {
898
  { (JSJitGetterOp)get_baseURL },
899
  { prototypes::id::WebExtensionPolicy },
900
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
901
  JSJitInfo::Getter,
902
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
903
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
904
  false,  /* isInfallible. False in setters. */
905
  true,  /* isMovable.  Not relevant for setters. */
906
  true, /* isEliminatable.  Not relevant for setters. */
907
  false, /* isAlwaysInSlot.  Only relevant for getters. */
908
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
909
  false,  /* isTypedMethod.  Only relevant for methods. */
910
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
911
};
912
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
913
static_assert(0 < 5, "There is no slot for us");
914
915
MOZ_CAN_RUN_SCRIPT static bool
916
get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
917
0
{
918
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.name", DOM, cx);
919
0
920
0
  DOMString result;
921
0
  self->GetName(result);
922
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
923
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
924
0
    return false;
925
0
  }
926
0
  return true;
927
0
}
928
929
static const JSJitInfo name_getterinfo = {
930
  { (JSJitGetterOp)get_name },
931
  { prototypes::id::WebExtensionPolicy },
932
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
933
  JSJitInfo::Getter,
934
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
935
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
936
  false,  /* isInfallible. False in setters. */
937
  true,  /* isMovable.  Not relevant for setters. */
938
  true, /* isEliminatable.  Not relevant for setters. */
939
  false, /* isAlwaysInSlot.  Only relevant for getters. */
940
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
941
  false,  /* isTypedMethod.  Only relevant for methods. */
942
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
943
};
944
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
945
static_assert(0 < 5, "There is no slot for us");
946
947
MOZ_CAN_RUN_SCRIPT static bool
948
get_contentSecurityPolicy(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
949
0
{
950
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.contentSecurityPolicy", DOM, cx);
951
0
952
0
  DOMString result;
953
0
  self->GetContentSecurityPolicy(result);
954
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
955
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
956
0
    return false;
957
0
  }
958
0
  return true;
959
0
}
960
961
static const JSJitInfo contentSecurityPolicy_getterinfo = {
962
  { (JSJitGetterOp)get_contentSecurityPolicy },
963
  { prototypes::id::WebExtensionPolicy },
964
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
965
  JSJitInfo::Getter,
966
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
967
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
968
  false,  /* isInfallible. False in setters. */
969
  true,  /* isMovable.  Not relevant for setters. */
970
  true, /* isEliminatable.  Not relevant for setters. */
971
  false, /* isAlwaysInSlot.  Only relevant for getters. */
972
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
973
  false,  /* isTypedMethod.  Only relevant for methods. */
974
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
975
};
976
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
977
static_assert(0 < 5, "There is no slot for us");
978
979
MOZ_CAN_RUN_SCRIPT static bool
980
get_permissions(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
981
0
{
982
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.permissions", DOM, cx);
983
0
984
0
  // Have to either root across the getter call or reget after.
985
0
  JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
986
0
  MOZ_ASSERT(IsDOMObject(slotStorage));
987
0
  const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 2);
988
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
989
0
  {
990
0
    // Scope for cachedVal
991
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
992
0
    if (!cachedVal.isUndefined()) {
993
0
      args.rval().set(cachedVal);
994
0
      // The cached value is in the compartment of slotStorage,
995
0
      // so wrap into the caller compartment as needed.
996
0
      if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
997
0
        return true;
998
0
      }
999
0
      return false;
1000
0
    }
1001
0
  }
1002
0
1003
0
  nsTArray<nsString> result;
1004
0
  self->GetPermissions(result);
1005
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1006
0
  {
1007
0
    JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
1008
0
    JSAutoRealm ar(cx, conversionScope);
1009
0
    do { // block we break out of when done wrapping
1010
0
1011
0
      uint32_t length = result.Length();
1012
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1013
0
      if (!returnArray) {
1014
0
        return false;
1015
0
      }
1016
0
      // Scope for 'tmp'
1017
0
      {
1018
0
        JS::Rooted<JS::Value> tmp(cx);
1019
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1020
0
          // Control block to let us common up the JS_DefineElement calls when there
1021
0
          // are different ways to succeed at wrapping the object.
1022
0
          do {
1023
0
            if (!xpc::NonVoidStringToJsval(cx, result[sequenceIdx0], &tmp)) {
1024
0
              return false;
1025
0
            }
1026
0
            break;
1027
0
          } while (false);
1028
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1029
0
                                JSPROP_ENUMERATE)) {
1030
0
            return false;
1031
0
          }
1032
0
        }
1033
0
      }
1034
0
      args.rval().setObject(*returnArray);
1035
0
      break;
1036
0
    } while (false);
1037
0
    JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject());
1038
0
    if (!JS_FreezeObject(cx, rvalObj)) {
1039
0
      return false;
1040
0
    }
1041
0
  }
1042
0
  { // And now store things in the realm of our slotStorage.
1043
0
    JSAutoRealm ar(cx, slotStorage);
1044
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
1045
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
1046
0
    if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
1047
0
      return false;
1048
0
    }
1049
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
1050
0
    PreserveWrapper(self);
1051
0
  }
1052
0
  // And now make sure args.rval() is in the caller realm.
1053
0
  if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
1054
0
    return true;
1055
0
  }
1056
0
  return false;
1057
0
}
1058
1059
MOZ_CAN_RUN_SCRIPT static bool
1060
set_permissions(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitSetterCallArgs args)
1061
0
{
1062
0
  AUTO_PROFILER_LABEL_FAST("set WebExtensionPolicy.permissions", DOM, cx);
1063
0
1064
0
  binding_detail::AutoSequence<nsString> arg0;
1065
0
  if (args[0].isObject()) {
1066
0
    JS::ForOfIterator iter(cx);
1067
0
    if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
1068
0
      return false;
1069
0
    }
1070
0
    if (!iter.valueIsIterable()) {
1071
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Value being assigned to WebExtensionPolicy.permissions");
1072
0
      return false;
1073
0
    }
1074
0
    binding_detail::AutoSequence<nsString> &arr = arg0;
1075
0
    JS::Rooted<JS::Value> temp(cx);
1076
0
    while (true) {
1077
0
      bool done;
1078
0
      if (!iter.next(&temp, &done)) {
1079
0
        return false;
1080
0
      }
1081
0
      if (done) {
1082
0
        break;
1083
0
      }
1084
0
      nsString* slotPtr = arr.AppendElement(mozilla::fallible);
1085
0
      if (!slotPtr) {
1086
0
        JS_ReportOutOfMemory(cx);
1087
0
        return false;
1088
0
      }
1089
0
      nsString& slot = *slotPtr;
1090
0
      if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
1091
0
        return false;
1092
0
      }
1093
0
    }
1094
0
  } else {
1095
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Value being assigned to WebExtensionPolicy.permissions");
1096
0
    return false;
1097
0
  }
1098
0
  self->SetPermissions(Constify(arg0));
1099
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1100
0
1101
0
  ClearCachedPermissionsValue(self);
1102
0
  return true;
1103
0
}
1104
1105
static const JSJitInfo permissions_getterinfo = {
1106
  { (JSJitGetterOp)get_permissions },
1107
  { prototypes::id::WebExtensionPolicy },
1108
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1109
  JSJitInfo::Getter,
1110
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1111
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1112
  false,  /* isInfallible. False in setters. */
1113
  true,  /* isMovable.  Not relevant for setters. */
1114
  true, /* isEliminatable.  Not relevant for setters. */
1115
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1116
  true, /* isLazilyCachedInSlot.  Only relevant for getters. */
1117
  false,  /* isTypedMethod.  Only relevant for methods. */
1118
  (DOM_INSTANCE_RESERVED_SLOTS + 2)   /* Reserved slot index, if we're stored in a slot, else 0. */
1119
};
1120
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 2) <= JSJitInfo::maxSlotIndex, "We won't fit");
1121
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 2) < 5, "There is no slot for us");
1122
static const JSJitInfo permissions_setterinfo = {
1123
  { (JSJitGetterOp)set_permissions },
1124
  { prototypes::id::WebExtensionPolicy },
1125
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1126
  JSJitInfo::Setter,
1127
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1128
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1129
  false,  /* isInfallible. False in setters. */
1130
  false,  /* isMovable.  Not relevant for setters. */
1131
  false, /* isEliminatable.  Not relevant for setters. */
1132
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1133
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1134
  false,  /* isTypedMethod.  Only relevant for methods. */
1135
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1136
};
1137
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1138
static_assert(0 < 5, "There is no slot for us");
1139
1140
MOZ_CAN_RUN_SCRIPT static bool
1141
get_allowedOrigins(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
1142
0
{
1143
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.allowedOrigins", DOM, cx);
1144
0
1145
0
  auto result(StrongOrRawPtr<mozilla::extensions::MatchPatternSet>(self->AllowedOrigins()));
1146
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1147
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1148
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1149
0
    return false;
1150
0
  }
1151
0
  return true;
1152
0
}
1153
1154
MOZ_CAN_RUN_SCRIPT static bool
1155
set_allowedOrigins(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitSetterCallArgs args)
1156
0
{
1157
0
  AUTO_PROFILER_LABEL_FAST("set WebExtensionPolicy.allowedOrigins", DOM, cx);
1158
0
1159
0
  NonNull<mozilla::extensions::MatchPatternSet> arg0;
1160
0
  if (args[0].isObject()) {
1161
0
    {
1162
0
      nsresult rv = UnwrapObject<prototypes::id::MatchPatternSet, mozilla::extensions::MatchPatternSet>(args[0], arg0);
1163
0
      if (NS_FAILED(rv)) {
1164
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Value being assigned to WebExtensionPolicy.allowedOrigins", "MatchPatternSet");
1165
0
        return false;
1166
0
      }
1167
0
    }
1168
0
  } else {
1169
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Value being assigned to WebExtensionPolicy.allowedOrigins");
1170
0
    return false;
1171
0
  }
1172
0
  self->SetAllowedOrigins(MOZ_KnownLive(NonNullHelper(arg0)));
1173
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1174
0
1175
0
  return true;
1176
0
}
1177
1178
static const JSJitInfo allowedOrigins_getterinfo = {
1179
  { (JSJitGetterOp)get_allowedOrigins },
1180
  { prototypes::id::WebExtensionPolicy },
1181
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1182
  JSJitInfo::Getter,
1183
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1184
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1185
  false,  /* isInfallible. False in setters. */
1186
  true,  /* isMovable.  Not relevant for setters. */
1187
  true, /* isEliminatable.  Not relevant for setters. */
1188
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1189
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1190
  false,  /* isTypedMethod.  Only relevant for methods. */
1191
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1192
};
1193
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1194
static_assert(0 < 5, "There is no slot for us");
1195
static const JSJitInfo allowedOrigins_setterinfo = {
1196
  { (JSJitGetterOp)set_allowedOrigins },
1197
  { prototypes::id::WebExtensionPolicy },
1198
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1199
  JSJitInfo::Setter,
1200
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1201
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1202
  false,  /* isInfallible. False in setters. */
1203
  false,  /* isMovable.  Not relevant for setters. */
1204
  false, /* isEliminatable.  Not relevant for setters. */
1205
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1206
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1207
  false,  /* isTypedMethod.  Only relevant for methods. */
1208
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1209
};
1210
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1211
static_assert(0 < 5, "There is no slot for us");
1212
1213
MOZ_CAN_RUN_SCRIPT static bool
1214
get_contentScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
1215
0
{
1216
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.contentScripts", DOM, cx);
1217
0
1218
0
  // Have to either root across the getter call or reget after.
1219
0
  JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
1220
0
  MOZ_ASSERT(IsDOMObject(slotStorage));
1221
0
  const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 3);
1222
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
1223
0
  {
1224
0
    // Scope for cachedVal
1225
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
1226
0
    if (!cachedVal.isUndefined()) {
1227
0
      args.rval().set(cachedVal);
1228
0
      // The cached value is in the compartment of slotStorage,
1229
0
      // so wrap into the caller compartment as needed.
1230
0
      if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
1231
0
        return true;
1232
0
      }
1233
0
      return false;
1234
0
    }
1235
0
  }
1236
0
1237
0
  nsTArray<StrongPtrForMember<mozilla::extensions::WebExtensionContentScript>::Type> result;
1238
0
  self->GetContentScripts(result);
1239
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1240
0
  {
1241
0
    JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
1242
0
    JSAutoRealm ar(cx, conversionScope);
1243
0
    do { // block we break out of when done wrapping
1244
0
1245
0
      uint32_t length = result.Length();
1246
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1247
0
      if (!returnArray) {
1248
0
        return false;
1249
0
      }
1250
0
      // Scope for 'tmp'
1251
0
      {
1252
0
        JS::Rooted<JS::Value> tmp(cx);
1253
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1254
0
          // Control block to let us common up the JS_DefineElement calls when there
1255
0
          // are different ways to succeed at wrapping the object.
1256
0
          do {
1257
0
            if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
1258
0
              MOZ_ASSERT(JS_IsExceptionPending(cx));
1259
0
              return false;
1260
0
            }
1261
0
            break;
1262
0
          } while (false);
1263
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1264
0
                                JSPROP_ENUMERATE)) {
1265
0
            return false;
1266
0
          }
1267
0
        }
1268
0
      }
1269
0
      args.rval().setObject(*returnArray);
1270
0
      break;
1271
0
    } while (false);
1272
0
    JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject());
1273
0
    if (!JS_FreezeObject(cx, rvalObj)) {
1274
0
      return false;
1275
0
    }
1276
0
  }
1277
0
  { // And now store things in the realm of our slotStorage.
1278
0
    JSAutoRealm ar(cx, slotStorage);
1279
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
1280
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
1281
0
    if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
1282
0
      return false;
1283
0
    }
1284
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
1285
0
    PreserveWrapper(self);
1286
0
  }
1287
0
  // And now make sure args.rval() is in the caller realm.
1288
0
  if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
1289
0
    return true;
1290
0
  }
1291
0
  return false;
1292
0
}
1293
1294
static const JSJitInfo contentScripts_getterinfo = {
1295
  { (JSJitGetterOp)get_contentScripts },
1296
  { prototypes::id::WebExtensionPolicy },
1297
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1298
  JSJitInfo::Getter,
1299
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1300
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1301
  false,  /* isInfallible. False in setters. */
1302
  true,  /* isMovable.  Not relevant for setters. */
1303
  true, /* isEliminatable.  Not relevant for setters. */
1304
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1305
  true, /* isLazilyCachedInSlot.  Only relevant for getters. */
1306
  false,  /* isTypedMethod.  Only relevant for methods. */
1307
  (DOM_INSTANCE_RESERVED_SLOTS + 3)   /* Reserved slot index, if we're stored in a slot, else 0. */
1308
};
1309
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 3) <= JSJitInfo::maxSlotIndex, "We won't fit");
1310
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 3) < 5, "There is no slot for us");
1311
1312
MOZ_CAN_RUN_SCRIPT static bool
1313
get_active(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitGetterCallArgs args)
1314
0
{
1315
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.active", DOM, cx);
1316
0
1317
0
  bool result(self->Active());
1318
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1319
0
  args.rval().setBoolean(result);
1320
0
  return true;
1321
0
}
1322
1323
MOZ_CAN_RUN_SCRIPT static bool
1324
set_active(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, JSJitSetterCallArgs args)
1325
0
{
1326
0
  AUTO_PROFILER_LABEL_FAST("set WebExtensionPolicy.active", DOM, cx);
1327
0
1328
0
  bool arg0;
1329
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
1330
0
    return false;
1331
0
  }
1332
0
  FastErrorResult rv;
1333
0
  self->SetActive(arg0, rv);
1334
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1335
0
    return false;
1336
0
  }
1337
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1338
0
1339
0
  return true;
1340
0
}
1341
1342
static const JSJitInfo active_getterinfo = {
1343
  { (JSJitGetterOp)get_active },
1344
  { prototypes::id::WebExtensionPolicy },
1345
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1346
  JSJitInfo::Getter,
1347
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1348
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1349
  true,  /* isInfallible. False in setters. */
1350
  false,  /* isMovable.  Not relevant for setters. */
1351
  false, /* isEliminatable.  Not relevant for setters. */
1352
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1353
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1354
  false,  /* isTypedMethod.  Only relevant for methods. */
1355
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1356
};
1357
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1358
static_assert(0 < 5, "There is no slot for us");
1359
static const JSJitInfo active_setterinfo = {
1360
  { (JSJitGetterOp)set_active },
1361
  { prototypes::id::WebExtensionPolicy },
1362
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1363
  JSJitInfo::Setter,
1364
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1365
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1366
  false,  /* isInfallible. False in setters. */
1367
  false,  /* isMovable.  Not relevant for setters. */
1368
  false, /* isEliminatable.  Not relevant for setters. */
1369
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1370
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1371
  false,  /* isTypedMethod.  Only relevant for methods. */
1372
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1373
};
1374
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1375
static_assert(0 < 5, "There is no slot for us");
1376
1377
static bool
1378
get_useRemoteWebExtensions(JSContext* cx, unsigned argc, JS::Value* vp)
1379
0
{
1380
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.useRemoteWebExtensions", DOM, cx);
1381
0
1382
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1383
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1384
0
1385
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1386
0
  if (global.Failed()) {
1387
0
    return false;
1388
0
  }
1389
0
1390
0
  bool result(mozilla::extensions::WebExtensionPolicy::UseRemoteWebExtensions(global));
1391
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1392
0
  args.rval().setBoolean(result);
1393
0
  return true;
1394
0
}
1395
1396
static bool
1397
get_isExtensionProcess(JSContext* cx, unsigned argc, JS::Value* vp)
1398
0
{
1399
0
  AUTO_PROFILER_LABEL_FAST("get WebExtensionPolicy.isExtensionProcess", DOM, cx);
1400
0
1401
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1402
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1403
0
1404
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1405
0
  if (global.Failed()) {
1406
0
    return false;
1407
0
  }
1408
0
1409
0
  bool result(mozilla::extensions::WebExtensionPolicy::IsExtensionProcess(global));
1410
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1411
0
  args.rval().setBoolean(result);
1412
0
  return true;
1413
0
}
1414
1415
MOZ_CAN_RUN_SCRIPT static bool
1416
canAccessURI(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1417
0
{
1418
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.canAccessURI", DOM, cx);
1419
0
1420
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1421
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.canAccessURI");
1422
0
  }
1423
0
  nsIURI* arg0;
1424
0
  RefPtr<nsIURI> arg0_holder;
1425
0
  if (args[0].isObject()) {
1426
0
    JS::Rooted<JSObject*> source(cx, &args[0].toObject());
1427
0
    if (NS_FAILED(UnwrapArg<nsIURI>(cx, source, getter_AddRefs(arg0_holder)))) {
1428
0
      ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebExtensionPolicy.canAccessURI", "URI");
1429
0
      return false;
1430
0
    }
1431
0
    MOZ_ASSERT(arg0_holder);
1432
0
    arg0 = arg0_holder;
1433
0
  } else {
1434
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebExtensionPolicy.canAccessURI");
1435
0
    return false;
1436
0
  }
1437
0
  bool arg1;
1438
0
  if (args.hasDefined(1)) {
1439
0
    if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
1440
0
      return false;
1441
0
    }
1442
0
  } else {
1443
0
    arg1 = false;
1444
0
  }
1445
0
  bool result(self->CanAccessURI(MOZ_KnownLive(NonNullHelper(arg0)), arg1));
1446
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1447
0
  args.rval().setBoolean(result);
1448
0
  return true;
1449
0
}
1450
1451
static const JSJitInfo canAccessURI_methodinfo = {
1452
  { (JSJitGetterOp)canAccessURI },
1453
  { prototypes::id::WebExtensionPolicy },
1454
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1455
  JSJitInfo::Method,
1456
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1457
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1458
  false,  /* isInfallible. False in setters. */
1459
  false,  /* isMovable.  Not relevant for setters. */
1460
  false, /* isEliminatable.  Not relevant for setters. */
1461
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1462
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1463
  false,  /* isTypedMethod.  Only relevant for methods. */
1464
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1465
};
1466
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1467
static_assert(0 < 5, "There is no slot for us");
1468
1469
MOZ_CAN_RUN_SCRIPT static bool
1470
hasPermission(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1471
0
{
1472
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.hasPermission", DOM, cx);
1473
0
1474
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1475
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.hasPermission");
1476
0
  }
1477
0
  binding_detail::FakeString arg0;
1478
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1479
0
    return false;
1480
0
  }
1481
0
  bool result(self->HasPermission(NonNullHelper(Constify(arg0))));
1482
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1483
0
  args.rval().setBoolean(result);
1484
0
  return true;
1485
0
}
1486
1487
static const JSJitInfo hasPermission_methodinfo = {
1488
  { (JSJitGetterOp)hasPermission },
1489
  { prototypes::id::WebExtensionPolicy },
1490
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1491
  JSJitInfo::Method,
1492
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1493
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1494
  false,  /* isInfallible. False in setters. */
1495
  false,  /* isMovable.  Not relevant for setters. */
1496
  false, /* isEliminatable.  Not relevant for setters. */
1497
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1498
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1499
  false,  /* isTypedMethod.  Only relevant for methods. */
1500
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1501
};
1502
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1503
static_assert(0 < 5, "There is no slot for us");
1504
1505
MOZ_CAN_RUN_SCRIPT static bool
1506
isPathWebAccessible(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1507
0
{
1508
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.isPathWebAccessible", DOM, cx);
1509
0
1510
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1511
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.isPathWebAccessible");
1512
0
  }
1513
0
  binding_detail::FakeString arg0;
1514
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1515
0
    return false;
1516
0
  }
1517
0
  bool result(self->IsPathWebAccessible(NonNullHelper(Constify(arg0))));
1518
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1519
0
  args.rval().setBoolean(result);
1520
0
  return true;
1521
0
}
1522
1523
static const JSJitInfo isPathWebAccessible_methodinfo = {
1524
  { (JSJitGetterOp)isPathWebAccessible },
1525
  { prototypes::id::WebExtensionPolicy },
1526
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1527
  JSJitInfo::Method,
1528
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1529
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1530
  false,  /* isInfallible. False in setters. */
1531
  false,  /* isMovable.  Not relevant for setters. */
1532
  false, /* isEliminatable.  Not relevant for setters. */
1533
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1534
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1535
  false,  /* isTypedMethod.  Only relevant for methods. */
1536
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1537
};
1538
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1539
static_assert(0 < 5, "There is no slot for us");
1540
1541
MOZ_CAN_RUN_SCRIPT static bool
1542
localize(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1543
0
{
1544
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.localize", DOM, cx);
1545
0
1546
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1547
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.localize");
1548
0
  }
1549
0
  binding_detail::FakeString arg0;
1550
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1551
0
    return false;
1552
0
  }
1553
0
  DOMString result;
1554
0
  self->Localize(NonNullHelper(Constify(arg0)), result);
1555
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1556
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
1557
0
    return false;
1558
0
  }
1559
0
  return true;
1560
0
}
1561
1562
static const JSJitInfo localize_methodinfo = {
1563
  { (JSJitGetterOp)localize },
1564
  { prototypes::id::WebExtensionPolicy },
1565
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1566
  JSJitInfo::Method,
1567
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1568
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1569
  false,  /* isInfallible. False in setters. */
1570
  false,  /* isMovable.  Not relevant for setters. */
1571
  false, /* isEliminatable.  Not relevant for setters. */
1572
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1573
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1574
  false,  /* isTypedMethod.  Only relevant for methods. */
1575
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1576
};
1577
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1578
static_assert(0 < 5, "There is no slot for us");
1579
1580
MOZ_CAN_RUN_SCRIPT static bool
1581
getURL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1582
0
{
1583
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.getURL", DOM, cx);
1584
0
1585
0
  binding_detail::FakeString arg0;
1586
0
  if (args.hasDefined(0)) {
1587
0
    if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1588
0
      return false;
1589
0
    }
1590
0
  } else {
1591
0
    static const char16_t data[] = { 0 };
1592
0
    arg0.Rebind(data, ArrayLength(data) - 1);
1593
0
  }
1594
0
  FastErrorResult rv;
1595
0
  DOMString result;
1596
0
  self->GetURL(NonNullHelper(Constify(arg0)), result, rv);
1597
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1598
0
    return false;
1599
0
  }
1600
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1601
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
1602
0
    return false;
1603
0
  }
1604
0
  return true;
1605
0
}
1606
1607
static const JSJitInfo getURL_methodinfo = {
1608
  { (JSJitGetterOp)getURL },
1609
  { prototypes::id::WebExtensionPolicy },
1610
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1611
  JSJitInfo::Method,
1612
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1613
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1614
  false,  /* isInfallible. False in setters. */
1615
  false,  /* isMovable.  Not relevant for setters. */
1616
  false, /* isEliminatable.  Not relevant for setters. */
1617
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1618
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1619
  false,  /* isTypedMethod.  Only relevant for methods. */
1620
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1621
};
1622
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1623
static_assert(0 < 5, "There is no slot for us");
1624
1625
MOZ_CAN_RUN_SCRIPT static bool
1626
registerContentScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1627
0
{
1628
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.registerContentScript", DOM, cx);
1629
0
1630
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1631
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.registerContentScript");
1632
0
  }
1633
0
  NonNull<mozilla::extensions::WebExtensionContentScript> arg0;
1634
0
  if (args[0].isObject()) {
1635
0
    {
1636
0
      nsresult rv = UnwrapObject<prototypes::id::WebExtensionContentScript, mozilla::extensions::WebExtensionContentScript>(args[0], arg0);
1637
0
      if (NS_FAILED(rv)) {
1638
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebExtensionPolicy.registerContentScript", "WebExtensionContentScript");
1639
0
        return false;
1640
0
      }
1641
0
    }
1642
0
  } else {
1643
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebExtensionPolicy.registerContentScript");
1644
0
    return false;
1645
0
  }
1646
0
  FastErrorResult rv;
1647
0
  self->RegisterContentScript(MOZ_KnownLive(NonNullHelper(arg0)), rv);
1648
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1649
0
    return false;
1650
0
  }
1651
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1652
0
  args.rval().setUndefined();
1653
0
  return true;
1654
0
}
1655
1656
static const JSJitInfo registerContentScript_methodinfo = {
1657
  { (JSJitGetterOp)registerContentScript },
1658
  { prototypes::id::WebExtensionPolicy },
1659
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1660
  JSJitInfo::Method,
1661
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1662
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1663
  false,  /* isInfallible. False in setters. */
1664
  false,  /* isMovable.  Not relevant for setters. */
1665
  false, /* isEliminatable.  Not relevant for setters. */
1666
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1667
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1668
  false,  /* isTypedMethod.  Only relevant for methods. */
1669
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1670
};
1671
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1672
static_assert(0 < 5, "There is no slot for us");
1673
1674
MOZ_CAN_RUN_SCRIPT static bool
1675
unregisterContentScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1676
0
{
1677
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.unregisterContentScript", DOM, cx);
1678
0
1679
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1680
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.unregisterContentScript");
1681
0
  }
1682
0
  NonNull<mozilla::extensions::WebExtensionContentScript> arg0;
1683
0
  if (args[0].isObject()) {
1684
0
    {
1685
0
      nsresult rv = UnwrapObject<prototypes::id::WebExtensionContentScript, mozilla::extensions::WebExtensionContentScript>(args[0], arg0);
1686
0
      if (NS_FAILED(rv)) {
1687
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebExtensionPolicy.unregisterContentScript", "WebExtensionContentScript");
1688
0
        return false;
1689
0
      }
1690
0
    }
1691
0
  } else {
1692
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebExtensionPolicy.unregisterContentScript");
1693
0
    return false;
1694
0
  }
1695
0
  FastErrorResult rv;
1696
0
  self->UnregisterContentScript(MOZ_KnownLive(NonNullHelper(arg0)), rv);
1697
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1698
0
    return false;
1699
0
  }
1700
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1701
0
  args.rval().setUndefined();
1702
0
  return true;
1703
0
}
1704
1705
static const JSJitInfo unregisterContentScript_methodinfo = {
1706
  { (JSJitGetterOp)unregisterContentScript },
1707
  { prototypes::id::WebExtensionPolicy },
1708
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1709
  JSJitInfo::Method,
1710
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1711
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1712
  false,  /* isInfallible. False in setters. */
1713
  false,  /* isMovable.  Not relevant for setters. */
1714
  false, /* isEliminatable.  Not relevant for setters. */
1715
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1716
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1717
  false,  /* isTypedMethod.  Only relevant for methods. */
1718
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1719
};
1720
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1721
static_assert(0 < 5, "There is no slot for us");
1722
1723
MOZ_CAN_RUN_SCRIPT static bool
1724
injectContentScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::WebExtensionPolicy* self, const JSJitMethodCallArgs& args)
1725
0
{
1726
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.injectContentScripts", DOM, cx);
1727
0
1728
0
  FastErrorResult rv;
1729
0
  self->InjectContentScripts(rv);
1730
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1731
0
    return false;
1732
0
  }
1733
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1734
0
  args.rval().setUndefined();
1735
0
  return true;
1736
0
}
1737
1738
static const JSJitInfo injectContentScripts_methodinfo = {
1739
  { (JSJitGetterOp)injectContentScripts },
1740
  { prototypes::id::WebExtensionPolicy },
1741
  { PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth },
1742
  JSJitInfo::Method,
1743
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1744
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1745
  false,  /* isInfallible. False in setters. */
1746
  false,  /* isMovable.  Not relevant for setters. */
1747
  false, /* isEliminatable.  Not relevant for setters. */
1748
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1749
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1750
  false,  /* isTypedMethod.  Only relevant for methods. */
1751
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1752
};
1753
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1754
static_assert(0 < 5, "There is no slot for us");
1755
1756
static bool
1757
getActiveExtensions(JSContext* cx, unsigned argc, JS::Value* vp)
1758
0
{
1759
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.getActiveExtensions", DOM, cx);
1760
0
1761
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1762
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1763
0
1764
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1765
0
  if (global.Failed()) {
1766
0
    return false;
1767
0
  }
1768
0
1769
0
  nsTArray<StrongPtrForMember<mozilla::extensions::WebExtensionPolicy>::Type> result;
1770
0
  mozilla::extensions::WebExtensionPolicy::GetActiveExtensions(global, result);
1771
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1772
0
1773
0
  uint32_t length = result.Length();
1774
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1775
0
  if (!returnArray) {
1776
0
    return false;
1777
0
  }
1778
0
  // Scope for 'tmp'
1779
0
  {
1780
0
    JS::Rooted<JS::Value> tmp(cx);
1781
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1782
0
      // Control block to let us common up the JS_DefineElement calls when there
1783
0
      // are different ways to succeed at wrapping the object.
1784
0
      do {
1785
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
1786
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
1787
0
          return false;
1788
0
        }
1789
0
        break;
1790
0
      } while (false);
1791
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1792
0
                            JSPROP_ENUMERATE)) {
1793
0
        return false;
1794
0
      }
1795
0
    }
1796
0
  }
1797
0
  args.rval().setObject(*returnArray);
1798
0
  return true;
1799
0
}
1800
1801
static bool
1802
getByID(JSContext* cx, unsigned argc, JS::Value* vp)
1803
0
{
1804
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.getByID", DOM, cx);
1805
0
1806
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1807
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1808
0
1809
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1810
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.getByID");
1811
0
  }
1812
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1813
0
  if (global.Failed()) {
1814
0
    return false;
1815
0
  }
1816
0
1817
0
  binding_detail::FakeString arg0;
1818
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1819
0
    return false;
1820
0
  }
1821
0
  auto result(StrongOrRawPtr<mozilla::extensions::WebExtensionPolicy>(mozilla::extensions::WebExtensionPolicy::GetByID(global, NonNullHelper(Constify(arg0)))));
1822
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1823
0
  if (!result) {
1824
0
    args.rval().setNull();
1825
0
    return true;
1826
0
  }
1827
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1828
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1829
0
    return false;
1830
0
  }
1831
0
  return true;
1832
0
}
1833
1834
static bool
1835
getByHostname(JSContext* cx, unsigned argc, JS::Value* vp)
1836
0
{
1837
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.getByHostname", DOM, cx);
1838
0
1839
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1840
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1841
0
1842
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1843
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.getByHostname");
1844
0
  }
1845
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1846
0
  if (global.Failed()) {
1847
0
    return false;
1848
0
  }
1849
0
1850
0
  nsCString arg0;
1851
0
  if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) {
1852
0
    return false;
1853
0
  }
1854
0
  auto result(StrongOrRawPtr<mozilla::extensions::WebExtensionPolicy>(mozilla::extensions::WebExtensionPolicy::GetByHostname(global, Constify(arg0))));
1855
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1856
0
  if (!result) {
1857
0
    args.rval().setNull();
1858
0
    return true;
1859
0
  }
1860
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1861
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1862
0
    return false;
1863
0
  }
1864
0
  return true;
1865
0
}
1866
1867
static bool
1868
getByURI(JSContext* cx, unsigned argc, JS::Value* vp)
1869
0
{
1870
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.getByURI", DOM, cx);
1871
0
1872
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1873
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1874
0
1875
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1876
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.getByURI");
1877
0
  }
1878
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1879
0
  if (global.Failed()) {
1880
0
    return false;
1881
0
  }
1882
0
1883
0
  nsIURI* arg0;
1884
0
  RefPtr<nsIURI> arg0_holder;
1885
0
  if (args[0].isObject()) {
1886
0
    JS::Rooted<JSObject*> source(cx, &args[0].toObject());
1887
0
    if (NS_FAILED(UnwrapArg<nsIURI>(cx, source, getter_AddRefs(arg0_holder)))) {
1888
0
      ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebExtensionPolicy.getByURI", "URI");
1889
0
      return false;
1890
0
    }
1891
0
    MOZ_ASSERT(arg0_holder);
1892
0
    arg0 = arg0_holder;
1893
0
  } else {
1894
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebExtensionPolicy.getByURI");
1895
0
    return false;
1896
0
  }
1897
0
  auto result(StrongOrRawPtr<mozilla::extensions::WebExtensionPolicy>(mozilla::extensions::WebExtensionPolicy::GetByURI(global, MOZ_KnownLive(NonNullHelper(arg0)))));
1898
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1899
0
  if (!result) {
1900
0
    args.rval().setNull();
1901
0
    return true;
1902
0
  }
1903
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1904
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1905
0
    return false;
1906
0
  }
1907
0
  return true;
1908
0
}
1909
1910
static bool
1911
isRestrictedURI(JSContext* cx, unsigned argc, JS::Value* vp)
1912
0
{
1913
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy.isRestrictedURI", DOM, cx);
1914
0
1915
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1916
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1917
0
1918
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1919
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy.isRestrictedURI");
1920
0
  }
1921
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
1922
0
  if (global.Failed()) {
1923
0
    return false;
1924
0
  }
1925
0
1926
0
  nsIURI* arg0;
1927
0
  RefPtr<nsIURI> arg0_holder;
1928
0
  if (args[0].isObject()) {
1929
0
    JS::Rooted<JSObject*> source(cx, &args[0].toObject());
1930
0
    if (NS_FAILED(UnwrapArg<nsIURI>(cx, source, getter_AddRefs(arg0_holder)))) {
1931
0
      ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebExtensionPolicy.isRestrictedURI", "URI");
1932
0
      return false;
1933
0
    }
1934
0
    MOZ_ASSERT(arg0_holder);
1935
0
    arg0 = arg0_holder;
1936
0
  } else {
1937
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebExtensionPolicy.isRestrictedURI");
1938
0
    return false;
1939
0
  }
1940
0
  bool result(mozilla::extensions::WebExtensionPolicy::IsRestrictedURI(global, MOZ_KnownLive(NonNullHelper(arg0))));
1941
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1942
0
  args.rval().setBoolean(result);
1943
0
  return true;
1944
0
}
1945
1946
static bool
1947
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1948
0
{
1949
0
  mozilla::extensions::WebExtensionPolicy* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::extensions::WebExtensionPolicy>(obj);
1950
0
  // We don't want to preserve if we don't have a wrapper, and we
1951
0
  // obviously can't preserve if we're not initialized.
1952
0
  if (self && self->GetWrapperPreserveColor()) {
1953
0
    PreserveWrapper(self);
1954
0
  }
1955
0
  return true;
1956
0
}
1957
1958
static void
1959
_finalize(js::FreeOp* fop, JSObject* obj)
1960
0
{
1961
0
  mozilla::extensions::WebExtensionPolicy* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::extensions::WebExtensionPolicy>(obj);
1962
0
  if (self) {
1963
0
    ClearWrapper(self, self, obj);
1964
0
    AddForDeferredFinalization<mozilla::extensions::WebExtensionPolicy>(self);
1965
0
  }
1966
0
}
1967
1968
static size_t
1969
_objectMoved(JSObject* obj, JSObject* old)
1970
0
{
1971
0
  mozilla::extensions::WebExtensionPolicy* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::extensions::WebExtensionPolicy>(obj);
1972
0
  if (self) {
1973
0
    UpdateWrapper(self, self, obj, old);
1974
0
  }
1975
0
1976
0
  return 0;
1977
0
}
1978
1979
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1980
#if defined(__clang__)
1981
#pragma clang diagnostic push
1982
#pragma clang diagnostic ignored "-Wmissing-braces"
1983
#endif
1984
static const JSFunctionSpec sStaticMethods_specs[] = {
1985
  JS_FNSPEC("getActiveExtensions", getActiveExtensions, nullptr, 0, JSPROP_ENUMERATE, nullptr),
1986
  JS_FNSPEC("getByID", getByID, nullptr, 1, JSPROP_ENUMERATE, nullptr),
1987
  JS_FNSPEC("getByHostname", getByHostname, nullptr, 1, JSPROP_ENUMERATE, nullptr),
1988
  JS_FNSPEC("getByURI", getByURI, nullptr, 1, JSPROP_ENUMERATE, nullptr),
1989
  JS_FNSPEC("isRestrictedURI", isRestrictedURI, nullptr, 1, JSPROP_ENUMERATE, nullptr),
1990
  JS_FS_END
1991
};
1992
#if defined(__clang__)
1993
#pragma clang diagnostic pop
1994
#endif
1995
1996
1997
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
1998
  { nullptr, &sStaticMethods_specs[0] },
1999
  { nullptr, nullptr }
2000
};
2001
2002
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2003
#if defined(__clang__)
2004
#pragma clang diagnostic push
2005
#pragma clang diagnostic ignored "-Wmissing-braces"
2006
#endif
2007
static const JSPropertySpec sStaticAttributes_specs[] = {
2008
  { "useRemoteWebExtensions", JSPROP_ENUMERATE, get_useRemoteWebExtensions, nullptr, nullptr, nullptr },
2009
  { "isExtensionProcess", JSPROP_ENUMERATE, get_isExtensionProcess, nullptr, nullptr, nullptr },
2010
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
2011
};
2012
#if defined(__clang__)
2013
#pragma clang diagnostic pop
2014
#endif
2015
2016
2017
static const Prefable<const JSPropertySpec> sStaticAttributes[] = {
2018
  { nullptr, &sStaticAttributes_specs[0] },
2019
  { nullptr, nullptr }
2020
};
2021
2022
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2023
#if defined(__clang__)
2024
#pragma clang diagnostic push
2025
#pragma clang diagnostic ignored "-Wmissing-braces"
2026
#endif
2027
static const JSFunctionSpec sMethods_specs[] = {
2028
  JS_FNSPEC("canAccessURI", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&canAccessURI_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2029
  JS_FNSPEC("hasPermission", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&hasPermission_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2030
  JS_FNSPEC("isPathWebAccessible", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&isPathWebAccessible_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2031
  JS_FNSPEC("localize", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&localize_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2032
  JS_FNSPEC("getURL", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getURL_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
2033
  JS_FNSPEC("registerContentScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&registerContentScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2034
  JS_FNSPEC("unregisterContentScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&unregisterContentScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
2035
  JS_FNSPEC("injectContentScripts", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&injectContentScripts_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
2036
  JS_FS_END
2037
};
2038
#if defined(__clang__)
2039
#pragma clang diagnostic pop
2040
#endif
2041
2042
2043
static const Prefable<const JSFunctionSpec> sMethods[] = {
2044
  { nullptr, &sMethods_specs[0] },
2045
  { nullptr, nullptr }
2046
};
2047
2048
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
2049
#if defined(__clang__)
2050
#pragma clang diagnostic push
2051
#pragma clang diagnostic ignored "-Wmissing-braces"
2052
#endif
2053
static const JSPropertySpec sAttributes_specs[] = {
2054
  { "id", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &id_getterinfo, nullptr, nullptr },
2055
  { "mozExtensionHostname", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mozExtensionHostname_getterinfo, nullptr, nullptr },
2056
  { "baseURL", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &baseURL_getterinfo, nullptr, nullptr },
2057
  { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr },
2058
  { "contentSecurityPolicy", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &contentSecurityPolicy_getterinfo, nullptr, nullptr },
2059
  { "permissions", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &permissions_getterinfo, GenericSetter<NormalThisPolicy>, &permissions_setterinfo },
2060
  { "allowedOrigins", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &allowedOrigins_getterinfo, GenericSetter<NormalThisPolicy>, &allowedOrigins_setterinfo },
2061
  { "contentScripts", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &contentScripts_getterinfo, nullptr, nullptr },
2062
  { "active", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &active_getterinfo, GenericSetter<NormalThisPolicy>, &active_setterinfo },
2063
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
2064
};
2065
#if defined(__clang__)
2066
#pragma clang diagnostic pop
2067
#endif
2068
2069
2070
static const Prefable<const JSPropertySpec> sAttributes[] = {
2071
  { nullptr, &sAttributes_specs[0] },
2072
  { nullptr, nullptr }
2073
};
2074
2075
2076
static const NativePropertiesN<4> sNativeProperties = {
2077
  true,  0 /* sStaticMethods */,
2078
  true,  1 /* sStaticAttributes */,
2079
  true,  2 /* sMethods */,
2080
  true,  3 /* sAttributes */,
2081
  false, 0,
2082
  false, 0,
2083
  false, 0,
2084
  -1,
2085
  0,
2086
  nullptr,
2087
  {
2088
    { sStaticMethods, nullptr },
2089
    { sStaticAttributes, nullptr },
2090
    { sMethods, nullptr },
2091
    { sAttributes, nullptr }
2092
  }
2093
};
2094
2095
static bool
2096
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
2097
0
{
2098
0
  AUTO_PROFILER_LABEL_FAST("WebExtensionPolicy constructor", DOM, cx);
2099
0
2100
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2101
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
2102
0
  if (!args.isConstructing()) {
2103
0
    // XXXbz wish I could get the name from the callee instead of
2104
0
    // Adding more relocations
2105
0
    return ThrowConstructorWithoutNew(cx, "WebExtensionPolicy");
2106
0
  }
2107
0
2108
0
  JS::Rooted<JSObject*> desiredProto(cx);
2109
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
2110
0
    return false;
2111
0
  }
2112
0
2113
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
2114
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebExtensionPolicy");
2115
0
  }
2116
0
  GlobalObject global(cx, obj);
2117
0
  if (global.Failed()) {
2118
0
    return false;
2119
0
  }
2120
0
2121
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
2122
0
  binding_detail::FastWebExtensionInit arg0;
2123
0
  if (!arg0.Init(cx, args[0],  "Argument 1 of WebExtensionPolicy.constructor", false)) {
2124
0
    return false;
2125
0
  }
2126
0
  Maybe<JSAutoRealm> ar;
2127
0
  if (objIsXray) {
2128
0
    obj = js::CheckedUnwrap(obj);
2129
0
    if (!obj) {
2130
0
      return false;
2131
0
    }
2132
0
    ar.emplace(cx, obj);
2133
0
    if (!JS_WrapObject(cx, &desiredProto)) {
2134
0
      return false;
2135
0
    }
2136
0
  }
2137
0
  FastErrorResult rv;
2138
0
  auto result(StrongOrRawPtr<mozilla::extensions::WebExtensionPolicy>(mozilla::extensions::WebExtensionPolicy::Constructor(global, Constify(arg0), rv)));
2139
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
2140
0
    return false;
2141
0
  }
2142
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
2143
0
  static_assert(!IsPointer<decltype(result)>::value,
2144
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
2145
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
2146
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
2147
0
    return false;
2148
0
  }
2149
0
  return true;
2150
0
}
2151
2152
static const js::ClassOps sInterfaceObjectClassOps = {
2153
    nullptr,               /* addProperty */
2154
    nullptr,               /* delProperty */
2155
    nullptr,               /* enumerate */
2156
    nullptr,               /* newEnumerate */
2157
    nullptr,               /* resolve */
2158
    nullptr,               /* mayResolve */
2159
    nullptr,               /* finalize */
2160
    _constructor, /* call */
2161
    nullptr,               /* hasInstance */
2162
    _constructor, /* construct */
2163
    nullptr,               /* trace */
2164
};
2165
2166
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
2167
  {
2168
    "Function",
2169
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
2170
    &sInterfaceObjectClassOps,
2171
    JS_NULL_CLASS_SPEC,
2172
    JS_NULL_CLASS_EXT,
2173
    &sInterfaceObjectClassObjectOps
2174
  },
2175
  eInterface,
2176
  true,
2177
  prototypes::id::WebExtensionPolicy,
2178
  PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth,
2179
  &sEmptyNativePropertyHooks,
2180
  "function WebExtensionPolicy() {\n    [native code]\n}",
2181
  JS::GetRealmFunctionPrototype
2182
};
2183
2184
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
2185
  {
2186
    "WebExtensionPolicyPrototype",
2187
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
2188
    JS_NULL_CLASS_OPS,
2189
    JS_NULL_CLASS_SPEC,
2190
    JS_NULL_CLASS_EXT,
2191
    JS_NULL_OBJECT_OPS
2192
  },
2193
  eInterfacePrototype,
2194
  false,
2195
  prototypes::id::WebExtensionPolicy,
2196
  PrototypeTraits<prototypes::id::WebExtensionPolicy>::Depth,
2197
  &sEmptyNativePropertyHooks,
2198
  "[object WebExtensionPolicyPrototype]",
2199
  JS::GetRealmObjectPrototype
2200
};
2201
2202
bool
2203
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
2204
0
{
2205
0
  return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
2206
0
}
2207
2208
static const js::ClassOps sClassOps = {
2209
  _addProperty, /* addProperty */
2210
  nullptr,               /* delProperty */
2211
  nullptr,               /* enumerate */
2212
  nullptr, /* newEnumerate */
2213
  nullptr, /* resolve */
2214
  nullptr, /* mayResolve */
2215
  _finalize, /* finalize */
2216
  nullptr, /* call */
2217
  nullptr,               /* hasInstance */
2218
  nullptr,               /* construct */
2219
  nullptr, /* trace */
2220
};
2221
2222
static const js::ClassExtension sClassExtension = {
2223
  nullptr, /* weakmapKeyDelegateOp */
2224
  _objectMoved /* objectMovedOp */
2225
};
2226
2227
static const DOMJSClass sClass = {
2228
  { "WebExtensionPolicy",
2229
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(5),
2230
    &sClassOps,
2231
    JS_NULL_CLASS_SPEC,
2232
    &sClassExtension,
2233
    JS_NULL_OBJECT_OPS
2234
  },
2235
  { prototypes::id::WebExtensionPolicy, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
2236
  IsBaseOf<nsISupports, mozilla::extensions::WebExtensionPolicy >::value,
2237
  &sEmptyNativePropertyHooks,
2238
  FindAssociatedGlobalForNative<mozilla::extensions::WebExtensionPolicy>::Get,
2239
  GetProtoObjectHandle,
2240
  GetCCParticipant<mozilla::extensions::WebExtensionPolicy>::Get()
2241
};
2242
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
2243
              "Must have the right minimal number of reserved slots.");
2244
static_assert(5 >= 5,
2245
              "Must have enough reserved slots.");
2246
2247
const JSClass*
2248
GetJSClass()
2249
0
{
2250
0
  return sClass.ToJSClass();
2251
0
}
2252
2253
static bool
2254
UpdateMemberSlots(JSContext* aCx, JS::Handle<JSObject*> aWrapper, mozilla::extensions::WebExtensionPolicy* aObject)
2255
0
{
2256
0
  JS::Rooted<JS::Value> temp(aCx);
2257
0
  JSJitGetterCallArgs args(&temp);
2258
0
2259
0
  static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < js::shadow::Object::MAX_FIXED_SLOTS,
2260
0
                "Not enough fixed slots to fit 'WebExtensionPolicy.id.  Ion's visitGetDOMMemberV/visitGetDOMMemberT assume StoreInSlot things are all in fixed slots.");
2261
0
  if (!get_id(aCx, aWrapper, aObject, args)) {
2262
0
    return false;
2263
0
  }
2264
0
  // Getter handled setting our reserved slots
2265
0
2266
0
  static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) < js::shadow::Object::MAX_FIXED_SLOTS,
2267
0
                "Not enough fixed slots to fit 'WebExtensionPolicy.mozExtensionHostname.  Ion's visitGetDOMMemberV/visitGetDOMMemberT assume StoreInSlot things are all in fixed slots.");
2268
0
  if (!get_mozExtensionHostname(aCx, aWrapper, aObject, args)) {
2269
0
    return false;
2270
0
  }
2271
0
  // Getter handled setting our reserved slots
2272
0
2273
0
  return true;
2274
0
}
2275
2276
bool
2277
Wrap(JSContext* aCx, mozilla::extensions::WebExtensionPolicy* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
2278
0
{
2279
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::extensions::WebExtensionPolicy>::value,
2280
0
                "Shouldn't have wrappercached things that are not refcounted.");
2281
0
  MOZ_ASSERT(static_cast<mozilla::extensions::WebExtensionPolicy*>(aObject) ==
2282
0
             reinterpret_cast<mozilla::extensions::WebExtensionPolicy*>(aObject),
2283
0
             "Multiple inheritance for mozilla::extensions::WebExtensionPolicy is broken.");
2284
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
2285
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
2286
0
  MOZ_ASSERT(!aCache->GetWrapper(),
2287
0
             "You should probably not be using Wrap() directly; use "
2288
0
             "GetOrCreateDOMReflector instead");
2289
0
2290
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
2291
0
             "nsISupports must be on our primary inheritance chain");
2292
0
2293
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
2294
0
  if (!global) {
2295
0
    return false;
2296
0
  }
2297
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
2298
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
2299
0
2300
0
  // That might have ended up wrapping us already, due to the wonders
2301
0
  // of XBL.  Check for that, and bail out as needed.
2302
0
  aReflector.set(aCache->GetWrapper());
2303
0
  if (aReflector) {
2304
#ifdef DEBUG
2305
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
2306
#endif // DEBUG
2307
    return true;
2308
0
  }
2309
0
2310
0
  JSAutoRealm ar(aCx, global);
2311
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
2312
0
  if (!canonicalProto) {
2313
0
    return false;
2314
0
  }
2315
0
  JS::Rooted<JSObject*> proto(aCx);
2316
0
  if (aGivenProto) {
2317
0
    proto = aGivenProto;
2318
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
2319
0
    // coming in, we changed compartments to that of "parent" so may need
2320
0
    // to wrap the proto here.
2321
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
2322
0
      if (!JS_WrapObject(aCx, &proto)) {
2323
0
        return false;
2324
0
      }
2325
0
    }
2326
0
  } else {
2327
0
    proto = canonicalProto;
2328
0
  }
2329
0
2330
0
  BindingJSObjectCreator<mozilla::extensions::WebExtensionPolicy> creator(aCx);
2331
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
2332
0
  if (!aReflector) {
2333
0
    return false;
2334
0
  }
2335
0
2336
0
  aCache->SetWrapper(aReflector);
2337
0
  if (!UpdateMemberSlots(aCx, aReflector, aObject)) {
2338
0
    aCache->ReleaseWrapper(aObject);
2339
0
    aCache->ClearWrapper();
2340
0
    return false;
2341
0
  }
2342
0
  creator.InitializationSucceeded();
2343
0
2344
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
2345
0
             aCache->GetWrapperPreserveColor() == aReflector);
2346
0
  // If proto != canonicalProto, we have to preserve our wrapper;
2347
0
  // otherwise we won't be able to properly recreate it later, since
2348
0
  // we won't know what proto to use.  Note that we don't check
2349
0
  // aGivenProto here, since it's entirely possible (and even
2350
0
  // somewhat common) to have a non-null aGivenProto which is the
2351
0
  // same as canonicalProto.
2352
0
  if (proto != canonicalProto) {
2353
0
    PreserveWrapper(aObject);
2354
0
  }
2355
0
2356
0
  return true;
2357
0
}
2358
2359
void
2360
ClearCachedPermissionsValue(mozilla::extensions::WebExtensionPolicy* aObject)
2361
0
{
2362
0
  JSObject* obj;
2363
0
  obj = aObject->GetWrapper();
2364
0
  if (!obj) {
2365
0
    return;
2366
0
  }
2367
0
  js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 2), JS::UndefinedValue());
2368
0
}
2369
2370
void
2371
ClearCachedContentScriptsValue(mozilla::extensions::WebExtensionPolicy* aObject)
2372
0
{
2373
0
  JSObject* obj;
2374
0
  obj = aObject->GetWrapper();
2375
0
  if (!obj) {
2376
0
    return;
2377
0
  }
2378
0
  js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 3), JS::UndefinedValue());
2379
0
}
2380
2381
void
2382
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
2383
0
{
2384
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
2385
0
  if (!parentProto) {
2386
0
    return;
2387
0
  }
2388
0
2389
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
2390
0
  if (!constructorProto) {
2391
0
    return;
2392
0
  }
2393
0
2394
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebExtensionPolicy);
2395
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebExtensionPolicy);
2396
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
2397
0
                              &sPrototypeClass.mBase, protoCache,
2398
0
                              nullptr,
2399
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
2400
0
                              interfaceCache,
2401
0
                              sNativeProperties.Upcast(),
2402
0
                              nullptr,
2403
0
                              "WebExtensionPolicy", aDefineOnGlobal,
2404
0
                              nullptr,
2405
0
                              false);
2406
0
}
2407
2408
JSObject*
2409
GetConstructorObject(JSContext* aCx)
2410
0
{
2411
0
  return GetConstructorObjectHandle(aCx);
2412
0
}
2413
2414
} // namespace WebExtensionPolicy_Binding
2415
2416
2417
2418
} // namespace dom
2419
} // namespace mozilla