Advertisement
Guest User

Untitled

a guest
May 24th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.54 KB | None | 0 0
  1. diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py
  2. --- a/dom/bindings/Codegen.py
  3. +++ b/dom/bindings/Codegen.py
  4. @@ -2356,17 +2356,18 @@ class MethodDefiner(PropertyDefiner):
  5. # identifier. For now we check if the name starts with __
  6.  
  7. # Ignore non-static methods for interfaces without a proto object
  8. if descriptor.interface.hasInterfacePrototypeObject() or static:
  9. methods = [m for m in descriptor.interface.members if
  10. m.isMethod() and m.isStatic() == static and
  11. MemberIsUnforgeable(m, descriptor) == unforgeable and
  12. (not crossOriginOnly or m.getExtendedAttribute("CrossOriginCallable")) and
  13. - not m.isIdentifierLess()]
  14. + not m.isIdentifierLess() and
  15. + not m.getExtendedAttribute("Unexposed")]
  16. else:
  17. methods = []
  18. self.chrome = []
  19. self.regular = []
  20. for m in methods:
  21. if m.identifier.name == 'QueryInterface':
  22. # QueryInterface is special, because instead of generating an
  23. # impl we just call out directly to our shared one.
  24. @@ -9638,21 +9639,29 @@ class CGMemberJITInfo(CGThing):
  25. $*{slotAssert}
  26. """,
  27. argTypesDecl=argTypesDecl,
  28. infoName=infoName,
  29. jitInfo=indent(jitInfoInitializer(True)),
  30. argTypes=argTypes,
  31. slotAssert=slotAssert)
  32.  
  33. + # Unexposed things are meant to be used from C++ directly, so we make
  34. + # their jitinfo non-static. That way C++ can get at it.
  35. + if self.member.getExtendedAttribute("Unexposed"):
  36. + storageClass = "extern "
  37. + else:
  38. + storageClass = "static "
  39. +
  40. return fill(
  41. """
  42. - static const JSJitInfo ${infoName} = ${jitInfo};
  43. + ${storageClass}const JSJitInfo ${infoName} = ${jitInfo};
  44. $*{slotAssert}
  45. """,
  46. + storageClass=storageClass,
  47. infoName=infoName,
  48. jitInfo=jitInfoInitializer(False),
  49. slotAssert=slotAssert)
  50.  
  51. def define(self):
  52. if self.member.isAttr():
  53. getterinfo = ("%s_getterinfo" %
  54. IDLToCIdentifier(self.member.identifier.name))
  55. diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py
  56. --- a/dom/bindings/parser/WebIDL.py
  57. +++ b/dom/bindings/parser/WebIDL.py
  58. @@ -5264,17 +5264,18 @@ class IDLMethod(IDLInterfaceMember, IDLS
  59. identifier == "Pref" or
  60. identifier == "Deprecated" or
  61. identifier == "Func" or
  62. identifier == "SecureContext" or
  63. identifier == "BinaryName" or
  64. identifier == "NeedsSubjectPrincipal" or
  65. identifier == "NeedsCallerType" or
  66. identifier == "StaticClassOverride" or
  67. - identifier == "NonEnumerable"):
  68. + identifier == "NonEnumerable" or
  69. + identifier == "Unexposed"):
  70. # Known attributes that we don't need to do anything with here
  71. pass
  72. else:
  73. raise WebIDLError("Unknown extended attribute %s on method" % identifier,
  74. [attr.location])
  75. IDLInterfaceMember.handleExtendedAttribute(self, attr)
  76.  
  77. def returnsPromise(self):
  78. diff --git a/dom/u2f/U2F.cpp b/dom/u2f/U2F.cpp
  79. --- a/dom/u2f/U2F.cpp
  80. +++ b/dom/u2f/U2F.cpp
  81. @@ -1,26 +1,24 @@
  82. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  83. /* vim: set ts=8 sts=2 et sw=2 tw=80: */
  84. /* This Source Code Form is subject to the terms of the Mozilla Public
  85. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  86. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  87.  
  88. #include "mozilla/dom/U2F.h"
  89. -#include "mozilla/dom/PrimitiveConversions.h" // For ValueToPrimitive
  90. #include "mozilla/dom/WebCryptoCommon.h"
  91. #include "mozilla/ipc/PBackgroundChild.h"
  92. #include "mozilla/ipc/BackgroundChild.h"
  93. #include "mozilla/dom/WebAuthnTransactionChild.h"
  94. #include "mozilla/dom/WebAuthnUtil.h"
  95. #include "nsContentUtils.h"
  96. #include "nsIEffectiveTLDService.h"
  97. #include "nsNetUtil.h"
  98. #include "nsURLParsers.h"
  99. -#include "js/ForOfIterator.h" // For JS::ForOfIterator
  100.  
  101. #ifdef OS_WIN
  102. # include "WinWebAuthnManager.h"
  103. #endif
  104.  
  105. using namespace mozilla::ipc;
  106.  
  107. // Forward decl because of nsHTMLDocument.h's complex dependency on
  108. @@ -291,25 +289,39 @@ void U2F::Register(const nsAString& aApp
  109. adjustedTimeoutMillis, excludeList,
  110. Nothing() /* no extra info for U2F */);
  111.  
  112. MOZ_ASSERT(mTransaction.isNothing());
  113. mTransaction = Some(U2FTransaction(AsVariant(callback)));
  114. mChild->SendRequestRegister(mTransaction.ref().mId, info);
  115. }
  116.  
  117. -// Implemented at end of file to avoid noise
  118. -static bool register_binding(JSContext* cx, unsigned argc, JS::Value* vp);
  119. +using binding_detail::GenericMethod;
  120. +using binding_detail::NormalThisPolicy;
  121. +using binding_detail::ThrowExceptions;
  122. +
  123. +// register_impl_methodinfo is generated by bindings.
  124. +namespace U2F_Binding {
  125. +extern JSJitInfo register_impl_methodinfo;
  126. +} // namespace U2F_Binding
  127. +
  128. +// We have 4 non-optional args.
  129. +static const JSFunctionSpec register_spec = JS_FNSPEC("register", (GenericMethod<NormalThisPolicy, ThrowExceptions>), &U2F_Binding::register_impl_methodinfo, 4, JSPROP_ENUMERATE, nullptr);
  130.  
  131. void U2F::GetRegister(JSContext* aCx,
  132. JS::MutableHandle<JSObject*> aRegisterFunc,
  133. ErrorResult& aRv) {
  134. - // We have 4 non-optional args.
  135. - JSFunction* fun = JS_NewFunction(aCx, register_binding, /* nargs = */ 4,
  136. - /* flags = */ 0, "registerx");
  137. + JS::Rooted<JSString*> str(aCx, JS_AtomizeAndPinString(aCx, "register"));
  138. + if (!str) {
  139. + aRv.NoteJSContextException(aCx);
  140. + return;
  141. + }
  142. +
  143. + JS::Rooted<jsid> id(aCx, INTERNED_STRING_TO_JSID(aCx, str));
  144. + JSFunction* fun = JS::NewFunctionFromSpec(aCx, &register_spec, id);
  145. if (!fun) {
  146. aRv.NoteJSContextException(aCx);
  147. return;
  148. }
  149.  
  150. aRegisterFunc.set(JS_GetFunctionObject(fun));
  151. }
  152.  
  153. @@ -468,24 +480,34 @@ void U2F::Sign(const nsAString& aAppId,
  154. adjustedTimeoutMillis, permittedList,
  155. Nothing() /* no extra info for U2F */);
  156.  
  157. MOZ_ASSERT(mTransaction.isNothing());
  158. mTransaction = Some(U2FTransaction(AsVariant(callback)));
  159. mChild->SendRequestSign(mTransaction.ref().mId, info);
  160. }
  161.  
  162. -// Implemented at end of file to avoid noise
  163. -static bool sign_binding(JSContext* cx, unsigned argc, JS::Value* vp);
  164. +// sign_impl_methodinfo is generated by bindings.
  165. +namespace U2F_Binding{
  166. +extern JSJitInfo sign_impl_methodinfo;
  167. +} // namespace U2F_Binding
  168. +
  169. +// We have 4 non-optional args.
  170. +static const JSFunctionSpec sign_spec = JS_FNSPEC("sign", (GenericMethod<NormalThisPolicy, ThrowExceptions>), &U2F_Binding::sign_impl_methodinfo, 4, JSPROP_ENUMERATE, nullptr);
  171.  
  172. void U2F::GetSign(JSContext* aCx, JS::MutableHandle<JSObject*> aSignFunc,
  173. ErrorResult& aRv) {
  174. - // We have 4 non-optional args.
  175. - JSFunction* fun = JS_NewFunction(aCx, sign_binding, /* nargs = */ 4,
  176. - /* flags = */ 0, "sign");
  177. + JS::Rooted<JSString*> str(aCx, JS_AtomizeAndPinString(aCx, "sign"));
  178. + if (!str) {
  179. + aRv.NoteJSContextException(aCx);
  180. + return;
  181. + }
  182. +
  183. + JS::Rooted<jsid> id(aCx, INTERNED_STRING_TO_JSID(aCx, str));
  184. + JSFunction* fun = JS::NewFunctionFromSpec(aCx, &sign_spec, id);
  185. if (!fun) {
  186. aRv.NoteJSContextException(aCx);
  187. return;
  188. }
  189.  
  190. aSignFunc.set(JS_GetFunctionObject(fun));
  191. }
  192.  
  193. @@ -611,272 +633,10 @@ void U2F::RequestAborted(const uint64_t&
  194. }
  195.  
  196. void U2F::HandleVisibilityChange() {
  197. if (mTransaction.isSome()) {
  198. mTransaction.ref().mVisibilityChanged = true;
  199. }
  200. }
  201.  
  202. -// clang-format off
  203. -
  204. -/**
  205. - * The register_binding and sign_binding implementations are copy/pasted from
  206. - * IDL method implementations with the following signatures:
  207. - *
  208. - * register_binding:
  209. - * void register(DOMString appId,
  210. - * sequence<RegisterRequest> registerRequests,
  211. - * sequence<RegisteredKey> registeredKeys,
  212. - * U2FRegisterCallback callback,
  213. - * optional long? opt_timeoutSeconds);
  214. - *
  215. - * sign_binding:
  216. - * void sign(DOMString appId,
  217. - * DOMString challenge,
  218. - * sequence<RegisteredKey> registeredKeys,
  219. - * U2FSignCallback callback,
  220. - * optional long? opt_timeoutSeconds);
  221. - *
  222. - * with a bit of boilerplate at the top to check for a valid "this" value.
  223. - */
  224. -using binding_detail::FastErrorResult;
  225. -
  226. -MOZ_CAN_RUN_SCRIPT static bool
  227. -register_binding(JSContext* cx, unsigned argc, JS::Value* vp)
  228. -{
  229. - JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
  230. - JS::Rooted<JS::Value> rootSelf(cx, args.thisv());
  231. - if (!rootSelf.isObject()) {
  232. - return ThrowInvalidThis(cx, args, false, "U2F");
  233. - }
  234. -
  235. - U2F* self;
  236. - { // Scope for rv
  237. - nsresult rv = UNWRAP_OBJECT(U2F, &rootSelf, self);
  238. - if (NS_FAILED(rv)) {
  239. - return ThrowInvalidThis(cx, args,
  240. - rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "U2F");
  241. - }
  242. - }
  243. -
  244. - AUTO_PROFILER_LABEL_DYNAMIC_FAST(
  245. - "U2F", "register", DOM, cx,
  246. - uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
  247. - uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
  248. -
  249. - if (!args.requireAtLeast(cx, "U2F.register", 4)) {
  250. - return false;
  251. - }
  252. - binding_detail::FakeString arg0;
  253. - if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
  254. - return false;
  255. - }
  256. - binding_detail::AutoSequence<RegisterRequest> arg1;
  257. - if (args[1].isObject()) {
  258. - JS::ForOfIterator iter(cx);
  259. - if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) {
  260. - return false;
  261. - }
  262. - if (!iter.valueIsIterable()) {
  263. - ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of U2F.register");
  264. - return false;
  265. - }
  266. - binding_detail::AutoSequence<RegisterRequest> &arr = arg1;
  267. - JS::Rooted<JS::Value> temp(cx);
  268. - while (true) {
  269. - bool done;
  270. - if (!iter.next(&temp, &done)) {
  271. - return false;
  272. - }
  273. - if (done) {
  274. - break;
  275. - }
  276. - RegisterRequest* slotPtr = arr.AppendElement(mozilla::fallible);
  277. - if (!slotPtr) {
  278. - JS_ReportOutOfMemory(cx);
  279. - return false;
  280. - }
  281. - RegisterRequest& slot = *slotPtr;
  282. - if (!slot.Init(cx, temp, "Element of argument 2 of U2F.register", false)) {
  283. - return false;
  284. - }
  285. - }
  286. - } else {
  287. - ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of U2F.register");
  288. - return false;
  289. - }
  290. - binding_detail::AutoSequence<RegisteredKey> arg2;
  291. - if (args[2].isObject()) {
  292. - JS::ForOfIterator iter(cx);
  293. - if (!iter.init(args[2], JS::ForOfIterator::AllowNonIterable)) {
  294. - return false;
  295. - }
  296. - if (!iter.valueIsIterable()) {
  297. - ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 3 of U2F.register");
  298. - return false;
  299. - }
  300. - binding_detail::AutoSequence<RegisteredKey> &arr = arg2;
  301. - JS::Rooted<JS::Value> temp(cx);
  302. - while (true) {
  303. - bool done;
  304. - if (!iter.next(&temp, &done)) {
  305. - return false;
  306. - }
  307. - if (done) {
  308. - break;
  309. - }
  310. - RegisteredKey* slotPtr = arr.AppendElement(mozilla::fallible);
  311. - if (!slotPtr) {
  312. - JS_ReportOutOfMemory(cx);
  313. - return false;
  314. - }
  315. - RegisteredKey& slot = *slotPtr;
  316. - if (!slot.Init(cx, temp, "Element of argument 3 of U2F.register", false)) {
  317. - return false;
  318. - }
  319. - }
  320. - } else {
  321. - ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 3 of U2F.register");
  322. - return false;
  323. - }
  324. - RootedCallback<OwningNonNull<binding_detail::FastU2FRegisterCallback>> arg3(cx);
  325. - if (args[3].isObject()) {
  326. - if (JS::IsCallable(&args[3].toObject())) {
  327. - { // scope for tempRoot and tempGlobalRoot if needed
  328. - arg3 = new binding_detail::FastU2FRegisterCallback(&args[3].toObject(), JS::CurrentGlobalOrNull(cx));
  329. - }
  330. - } else {
  331. - ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 4 of U2F.register");
  332. - return false;
  333. - }
  334. - } else {
  335. - ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of U2F.register");
  336. - return false;
  337. - }
  338. - Optional<Nullable<int32_t>> arg4;
  339. - if (args.hasDefined(4)) {
  340. - arg4.Construct();
  341. - if (args[4].isNullOrUndefined()) {
  342. - arg4.Value().SetNull();
  343. - } else if (!ValueToPrimitive<int32_t, eDefault>(cx, args[4], &arg4.Value().SetValue())) {
  344. - return false;
  345. - }
  346. - }
  347. - FastErrorResult rv;
  348. - // NOTE: This assert does NOT call the function.
  349. - static_assert(mozilla::IsVoid<decltype(MOZ_KnownLive(self)->Register(NonNullHelper(Constify(arg0)), Constify(arg1), Constify(arg2), MOZ_KnownLive(NonNullHelper(arg3)), Constify(arg4), rv))>::value, "Should be returning void here");
  350. - MOZ_KnownLive(self)->Register(NonNullHelper(Constify(arg0)), Constify(arg1), Constify(arg2), MOZ_KnownLive(NonNullHelper(arg3)), Constify(arg4), rv);
  351. - if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
  352. - return false;
  353. - }
  354. - MOZ_ASSERT(!JS_IsExceptionPending(cx));
  355. - args.rval().setUndefined();
  356. - return true;
  357. -}
  358. -
  359. -MOZ_CAN_RUN_SCRIPT static bool
  360. -sign_binding(JSContext* cx, unsigned argc, JS::Value* vp)
  361. -{
  362. - JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
  363. - JS::Rooted<JS::Value> rootSelf(cx, args.thisv());
  364. - if (!rootSelf.isObject()) {
  365. - return ThrowInvalidThis(cx, args, false, "U2F");
  366. - }
  367. -
  368. - U2F* self;
  369. - { // Scope for rv
  370. - nsresult rv = UNWRAP_OBJECT(U2F, &rootSelf, self);
  371. - if (NS_FAILED(rv)) {
  372. - return ThrowInvalidThis(cx, args,
  373. - rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "U2F");
  374. - }
  375. - }
  376. -
  377. - AUTO_PROFILER_LABEL_DYNAMIC_FAST(
  378. - "U2F", "sign", DOM, cx,
  379. - uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
  380. - uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
  381. -
  382. - if (!args.requireAtLeast(cx, "U2F.sign", 4)) {
  383. - return false;
  384. - }
  385. - binding_detail::FakeString arg0;
  386. - if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
  387. - return false;
  388. - }
  389. - binding_detail::FakeString arg1;
  390. - if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
  391. - return false;
  392. - }
  393. - binding_detail::AutoSequence<RegisteredKey> arg2;
  394. - if (args[2].isObject()) {
  395. - JS::ForOfIterator iter(cx);
  396. - if (!iter.init(args[2], JS::ForOfIterator::AllowNonIterable)) {
  397. - return false;
  398. - }
  399. - if (!iter.valueIsIterable()) {
  400. - ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 3 of U2F.sign");
  401. - return false;
  402. - }
  403. - binding_detail::AutoSequence<RegisteredKey> &arr = arg2;
  404. - JS::Rooted<JS::Value> temp(cx);
  405. - while (true) {
  406. - bool done;
  407. - if (!iter.next(&temp, &done)) {
  408. - return false;
  409. - }
  410. - if (done) {
  411. - break;
  412. - }
  413. - RegisteredKey* slotPtr = arr.AppendElement(mozilla::fallible);
  414. - if (!slotPtr) {
  415. - JS_ReportOutOfMemory(cx);
  416. - return false;
  417. - }
  418. - RegisteredKey& slot = *slotPtr;
  419. - if (!slot.Init(cx, temp, "Element of argument 3 of U2F.sign", false)) {
  420. - return false;
  421. - }
  422. - }
  423. - } else {
  424. - ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 3 of U2F.sign");
  425. - return false;
  426. - }
  427. - RootedCallback<OwningNonNull<binding_detail::FastU2FSignCallback>> arg3(cx);
  428. - if (args[3].isObject()) {
  429. - if (JS::IsCallable(&args[3].toObject())) {
  430. - { // scope for tempRoot and tempGlobalRoot if needed
  431. - arg3 = new binding_detail::FastU2FSignCallback(&args[3].toObject(), JS::CurrentGlobalOrNull(cx));
  432. - }
  433. - } else {
  434. - ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 4 of U2F.sign");
  435. - return false;
  436. - }
  437. - } else {
  438. - ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of U2F.sign");
  439. - return false;
  440. - }
  441. - Optional<Nullable<int32_t>> arg4;
  442. - if (args.hasDefined(4)) {
  443. - arg4.Construct();
  444. - if (args[4].isNullOrUndefined()) {
  445. - arg4.Value().SetNull();
  446. - } else if (!ValueToPrimitive<int32_t, eDefault>(cx, args[4], &arg4.Value().SetValue())) {
  447. - return false;
  448. - }
  449. - }
  450. - FastErrorResult rv;
  451. - // NOTE: This assert does NOT call the function.
  452. - static_assert(mozilla::IsVoid<decltype(MOZ_KnownLive(self)->Sign(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), MOZ_KnownLive(NonNullHelper(arg3)), Constify(arg4), rv))>::value, "Should be returning void here");
  453. - MOZ_KnownLive(self)->Sign(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), MOZ_KnownLive(NonNullHelper(arg3)), Constify(arg4), rv);
  454. - if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
  455. - return false;
  456. - }
  457. - MOZ_ASSERT(!JS_IsExceptionPending(cx));
  458. - args.rval().setUndefined();
  459. - return true;
  460. -}
  461. -
  462. -// clang-format on
  463. -
  464. } // namespace dom
  465. } // namespace mozilla
  466. diff --git a/dom/webidl/U2F.webidl b/dom/webidl/U2F.webidl
  467. --- a/dom/webidl/U2F.webidl
  468. +++ b/dom/webidl/U2F.webidl
  469. @@ -79,13 +79,29 @@ interface U2F {
  470. const unsigned short DEVICE_INELIGIBLE = 4;
  471. const unsigned short TIMEOUT = 5;
  472.  
  473. // Returns a Function. It's readonly + [LenientSetter] to keep the Google
  474. // U2F polyfill from stomping on the value.
  475. [LenientSetter, Pure, Cached, Throws]
  476. readonly attribute object register;
  477.  
  478. + // A way to generate the actual implementation of register()
  479. + [Unexposed, Throws, BinaryName="Register"]
  480. + void register_impl(DOMString appId,
  481. + sequence<RegisterRequest> registerRequests,
  482. + sequence<RegisteredKey> registeredKeys,
  483. + U2FRegisterCallback callback,
  484. + optional long? opt_timeoutSeconds);
  485. +
  486. // Returns a Function. It's readonly + [LenientSetter] to keep the Google
  487. // U2F polyfill from stomping on the value.
  488. [LenientSetter, Pure, Cached, Throws]
  489. readonly attribute object sign;
  490. +
  491. + // A way to generate the actual implementation of sign()
  492. + [Unexposed, Throws, BinaryName="Sign"]
  493. + void sign_impl (DOMString appId,
  494. + DOMString challenge,
  495. + sequence<RegisteredKey> registeredKeys,
  496. + U2FSignCallback callback,
  497. + optional long? opt_timeoutSeconds);
  498. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement