Tue, 06 Jan 2015 21:39:09 +0100
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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* JS::PropertyKey implementation. */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef js_PropertyKey_h |
michael@0 | 10 | #define js_PropertyKey_h |
michael@0 | 11 | |
michael@0 | 12 | #include "js/TypeDecls.h" |
michael@0 | 13 | #include "js/Value.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace JS { |
michael@0 | 16 | |
michael@0 | 17 | class PropertyKey; |
michael@0 | 18 | |
michael@0 | 19 | namespace detail { |
michael@0 | 20 | |
michael@0 | 21 | extern JS_PUBLIC_API(bool) |
michael@0 | 22 | ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); |
michael@0 | 23 | |
michael@0 | 24 | } // namespace detail |
michael@0 | 25 | |
michael@0 | 26 | /* |
michael@0 | 27 | * A PropertyKey is a key used to access some property on an object. It is a |
michael@0 | 28 | * natural way to represent a property accessed using a JavaScript value. |
michael@0 | 29 | * |
michael@0 | 30 | * PropertyKey can represent indexes, named properties, and ES6 symbols. The |
michael@0 | 31 | * latter aren't implemented in SpiderMonkey yet, but PropertyKey carves out |
michael@0 | 32 | * space for them. |
michael@0 | 33 | */ |
michael@0 | 34 | class PropertyKey |
michael@0 | 35 | { |
michael@0 | 36 | Value v; |
michael@0 | 37 | friend JS_PUBLIC_API(bool) detail::ToPropertyKeySlow(JSContext *cx, HandleValue v, PropertyKey *key); |
michael@0 | 38 | |
michael@0 | 39 | public: |
michael@0 | 40 | explicit PropertyKey(uint32_t index) : v(PrivateUint32Value(index)) {} |
michael@0 | 41 | |
michael@0 | 42 | /* |
michael@0 | 43 | * An index is a string property name whose characters exactly spell out an |
michael@0 | 44 | * unsigned 32-bit integer in decimal: "0", "1", "2", ...., "4294967294", |
michael@0 | 45 | * "4294967295". |
michael@0 | 46 | */ |
michael@0 | 47 | bool isIndex(uint32_t *index) { |
michael@0 | 48 | // The implementation here assumes that private uint32_t are stored |
michael@0 | 49 | // using the int32_t representation. This is purely an implementation |
michael@0 | 50 | // detail: embedders must not rely upon this! |
michael@0 | 51 | if (!v.isInt32()) |
michael@0 | 52 | return false; |
michael@0 | 53 | *index = v.toPrivateUint32(); |
michael@0 | 54 | return true; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | /* |
michael@0 | 58 | * A name is a string property name which is *not* an index. Note that by |
michael@0 | 59 | * the ECMAScript language grammar, any dotted property access |obj.prop| |
michael@0 | 60 | * will access a named property. |
michael@0 | 61 | */ |
michael@0 | 62 | bool isName(JSString **str) { |
michael@0 | 63 | uint32_t dummy; |
michael@0 | 64 | if (isIndex(&dummy)) |
michael@0 | 65 | return false; |
michael@0 | 66 | *str = v.toString(); |
michael@0 | 67 | return true; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | /* |
michael@0 | 71 | * A symbol is a property name that's a Symbol, a particular kind of object |
michael@0 | 72 | * in ES6. It is the only kind of property name that's not a string. |
michael@0 | 73 | * |
michael@0 | 74 | * SpiderMonkey doesn't yet implement symbols, but we're carving out API |
michael@0 | 75 | * space for them in advance. |
michael@0 | 76 | */ |
michael@0 | 77 | bool isSymbol() { |
michael@0 | 78 | return false; |
michael@0 | 79 | } |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | inline bool |
michael@0 | 83 | ToPropertyKey(JSContext *cx, HandleValue v, PropertyKey *key) |
michael@0 | 84 | { |
michael@0 | 85 | if (v.isInt32() && v.toInt32() >= 0) { |
michael@0 | 86 | *key = PropertyKey(uint32_t(v.toInt32())); |
michael@0 | 87 | return true; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | return detail::ToPropertyKeySlow(cx, v, key); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | } // namespace JS |
michael@0 | 94 | |
michael@0 | 95 | #endif /* js_PropertyKey_h */ |