dom/bindings/ToJSValue.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
     2 /* vim: set ts=2 sw=2 et tw=79: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "mozilla/dom/ToJSValue.h"
     8 #include "mozilla/dom/DOMException.h"
     9 #include "mozilla/dom/Exceptions.h"
    10 #include "nsAString.h"
    11 #include "nsContentUtils.h"
    12 #include "nsStringBuffer.h"
    13 #include "xpcpublic.h"
    15 namespace mozilla {
    16 namespace dom {
    18 bool
    19 ToJSValue(JSContext* aCx, const nsAString& aArgument,
    20           JS::MutableHandle<JS::Value> aValue)
    21 {
    22   // Make sure we're called in a compartment
    23   MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
    25 // XXXkhuey I'd love to use xpc::NonVoidStringToJsval here, but it requires
    26   // a non-const nsAString for silly reasons.
    27   nsStringBuffer* sharedBuffer;
    28   if (!XPCStringConvert::ReadableToJSVal(aCx, aArgument, &sharedBuffer,
    29                                          aValue)) {
    30     return false;
    31   }
    33   if (sharedBuffer) {
    34     NS_ADDREF(sharedBuffer);
    35   }
    37   return true;
    38 }
    41 namespace tojsvalue_detail {
    43 bool
    44 ISupportsToJSValue(JSContext* aCx,
    45                    nsISupports* aArgument,
    46                    JS::MutableHandle<JS::Value> aValue)
    47 {
    48   nsresult rv = nsContentUtils::WrapNative(aCx, aArgument, aValue);
    49   return NS_SUCCEEDED(rv);
    50 }
    52 } // namespace tojsvalue_detail
    54 bool
    55 ToJSValue(JSContext* aCx,
    56           nsresult aArgument,
    57           JS::MutableHandle<JS::Value> aValue)
    58 {
    59   nsRefPtr<Exception> exception = CreateException(aCx, aArgument);
    60   return ToJSValue(aCx, exception, aValue);
    61 }
    63 } // namespace dom
    64 } // namespace mozilla

mercurial