js/src/builtin/Iterator.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function IteratorIdentity() {
michael@0 6 return this;
michael@0 7 }
michael@0 8
michael@0 9 var LegacyIteratorWrapperMap = new std_WeakMap();
michael@0 10
michael@0 11 function LegacyIteratorNext(arg) {
michael@0 12 var iter = callFunction(std_WeakMap_get, LegacyIteratorWrapperMap, this);
michael@0 13 try {
michael@0 14 return { value: iter.next(arg), done: false };
michael@0 15 } catch (e) {
michael@0 16 if (e instanceof std_StopIteration)
michael@0 17 return { value: undefined, done: true };
michael@0 18 throw e;
michael@0 19 }
michael@0 20 }
michael@0 21
michael@0 22 function LegacyIteratorThrow(exn) {
michael@0 23 var iter = callFunction(std_WeakMap_get, LegacyIteratorWrapperMap, this);
michael@0 24 try {
michael@0 25 return { value: iter.throw(exn), done: false };
michael@0 26 } catch (e) {
michael@0 27 if (e instanceof std_StopIteration)
michael@0 28 return { value: undefined, done: true };
michael@0 29 throw e;
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 function LegacyIterator(iter) {
michael@0 34 callFunction(std_WeakMap_set, LegacyIteratorWrapperMap, this, iter);
michael@0 35 }
michael@0 36
michael@0 37 function LegacyGeneratorIterator(iter) {
michael@0 38 callFunction(std_WeakMap_set, LegacyIteratorWrapperMap, this, iter);
michael@0 39 }
michael@0 40
michael@0 41 var LegacyIteratorsInitialized = std_Object_create(null);
michael@0 42
michael@0 43 function InitLegacyIterators() {
michael@0 44 var props = std_Object_create(null);
michael@0 45
michael@0 46 props.next = std_Object_create(null);
michael@0 47 props.next.value = LegacyIteratorNext;
michael@0 48 props.next.enumerable = false;
michael@0 49 props.next.configurable = true;
michael@0 50 props.next.writable = true;
michael@0 51
michael@0 52 props[std_iterator] = std_Object_create(null);
michael@0 53 props[std_iterator].value = IteratorIdentity;
michael@0 54 props[std_iterator].enumerable = false;
michael@0 55 props[std_iterator].configurable = true;
michael@0 56 props[std_iterator].writable = true;
michael@0 57
michael@0 58 var LegacyIteratorProto = std_Object_create(GetIteratorPrototype(), props);
michael@0 59 MakeConstructible(LegacyIterator, LegacyIteratorProto);
michael@0 60
michael@0 61 props.throw = std_Object_create(null);
michael@0 62 props.throw.value = LegacyIteratorThrow;
michael@0 63 props.throw.enumerable = false;
michael@0 64 props.throw.configurable = true;
michael@0 65 props.throw.writable = true;
michael@0 66
michael@0 67 var LegacyGeneratorIteratorProto = std_Object_create(GetIteratorPrototype(), props);
michael@0 68 MakeConstructible(LegacyGeneratorIterator, LegacyGeneratorIteratorProto);
michael@0 69
michael@0 70 LegacyIteratorsInitialized.initialized = true;
michael@0 71 }
michael@0 72
michael@0 73 function NewLegacyIterator(iter, wrapper) {
michael@0 74 if (!LegacyIteratorsInitialized.initialized)
michael@0 75 InitLegacyIterators();
michael@0 76
michael@0 77 return new wrapper(iter);
michael@0 78 }
michael@0 79
michael@0 80 function LegacyIteratorShim() {
michael@0 81 return NewLegacyIterator(ToObject(this), LegacyIterator);
michael@0 82 }
michael@0 83
michael@0 84 function LegacyGeneratorIteratorShim() {
michael@0 85 return NewLegacyIterator(ToObject(this), LegacyGeneratorIterator);
michael@0 86 }

mercurial