TestFunctions.webidl (6388B)
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. 5 */ 6 7 // A dumping ground for random testing functions 8 9 callback PromiseReturner = Promise<any>(); 10 callback PromiseReturner2 = Promise<any>(any arg, DOMString arg2); 11 12 [Pref="dom.expose_test_interfaces", 13 Exposed=Window] 14 interface WrapperCachedNonISupportsTestInterface { 15 [Pref="dom.webidl.test1"] constructor(); 16 }; 17 18 [Trial="TestTrial", Exposed=*] 19 interface TestTrialInterface { 20 constructor(); 21 }; 22 23 [Pref="dom.expose_test_interfaces", 24 Exposed=Window] 25 interface TestInterfaceLength { 26 [ChromeOnly] 27 constructor(boolean arg); 28 }; 29 30 // The type of string C++ sees. 31 enum StringType { 32 "literal", // A string with the LITERAL flag. 33 "stringbuffer", // A string with the REFCOUNTED flag. 34 "inline", // A string with the INLINE flag. 35 "other", // Anything else. 36 }; 37 38 [Pref="dom.expose_test_interfaces", 39 Exposed=Window] 40 interface TestFunctions { 41 constructor(); 42 43 [Throws] 44 static undefined throwUncatchableException(); 45 46 // Simply returns its argument. Can be used to test Promise 47 // argument processing behavior. 48 static Promise<any> passThroughPromise(Promise<any> arg); 49 50 // Returns whatever Promise the given PromiseReturner returned. 51 [Throws] 52 static Promise<any> passThroughCallbackPromise(PromiseReturner callback); 53 54 // Some basic tests for string binding round-tripping behavior. 55 undefined setStringData(DOMString arg); 56 57 // Get the string data, using an nsAString argument on the C++ side. 58 // This will just use Assign/operator=, whatever that does. 59 DOMString getStringDataAsAString(); 60 61 // Get the string data, but only "length" chars of it, using an 62 // nsAString argument on the C++ side. This will always copy on the 63 // C++ side. 64 DOMString getStringDataAsAString(unsigned long length); 65 66 // Get the string data, but only "length" chars of it, using a 67 // DOMString argument on the C++ side and trying to hand it 68 // stringbuffers. If length not passed, use our full length. 69 DOMString getStringDataAsDOMString(optional unsigned long length); 70 71 // Get a short (short enough to fit in a JS inline string) literal string. 72 DOMString getShortLiteralString(); 73 74 // Get a medium (long enough to not be a JS inline, but short enough 75 // to fit in a FakeString inline buffer) literal string. 76 DOMString getMediumLiteralString(); 77 78 // Get a long (long enough to not fit in any inline buffers) literal string. 79 DOMString getLongLiteralString(); 80 81 // Get a stringbuffer string for whatever string is passed in. 82 DOMString getStringbufferString(DOMString input); 83 84 // Get the type of string that the C++ sees after going through bindings. 85 StringType getStringType(DOMString str); 86 87 // Returns true if both the incoming string and the stored (via setStringData()) 88 // string have stringbuffers and they're the same stringbuffer. 89 boolean stringbufferMatchesStored(DOMString str); 90 91 // Functions that just punch through to mozITestInterfaceJS.idl 92 [Throws] 93 undefined testThrowNsresult(); 94 [Throws] 95 undefined testThrowNsresultFromNative(); 96 97 // Throws an InvalidStateError to auto-create a rejected promise. 98 [Throws] 99 static Promise<any> throwToRejectPromise(); 100 101 // Some attributes for the toJSON to work with. 102 readonly attribute long one; 103 [Func="mozilla::dom::TestFunctions::ObjectFromAboutBlank"] 104 readonly attribute long two; 105 106 // Testing for how default toJSON behaves. 107 [Default] object toJSON(); 108 109 // This returns a wrappercached non-ISupports object. While this will always 110 // return the same object, no optimization attributes like [Pure] should be 111 // used here because the object should not be held alive from JS by the 112 // bindings. This is needed to test wrapper preservation for weak map keys. 113 // See bug 1351501. 114 readonly attribute WrapperCachedNonISupportsTestInterface wrapperCachedNonISupportsObject; 115 116 attribute [Clamp] octet? clampedNullableOctet; 117 attribute [EnforceRange] octet? enforcedNullableOctet; 118 119 // Testing for [AllowShared] 120 [GetterThrows] 121 attribute ArrayBufferView arrayBufferView; 122 [GetterThrows] 123 attribute [AllowShared] ArrayBufferView allowSharedArrayBufferView; 124 [Cached, Pure, GetterThrows] 125 attribute sequence<ArrayBufferView> sequenceOfArrayBufferView; 126 [Cached, Pure, GetterThrows] 127 attribute sequence<[AllowShared] ArrayBufferView> sequenceOfAllowSharedArrayBufferView; 128 [GetterThrows] 129 attribute ArrayBuffer arrayBuffer; 130 [GetterThrows] 131 attribute [AllowShared] ArrayBuffer allowSharedArrayBuffer; 132 [Cached, Pure, GetterThrows] 133 attribute sequence<ArrayBuffer> sequenceOfArrayBuffer; 134 [Cached, Pure, GetterThrows] 135 attribute sequence<[AllowShared] ArrayBuffer> sequenceOfAllowSharedArrayBuffer; 136 undefined testNotAllowShared(ArrayBufferView buffer); 137 undefined testNotAllowShared(ArrayBuffer buffer); 138 undefined testNotAllowShared(DOMString buffer); 139 undefined testAllowShared([AllowShared] ArrayBufferView buffer); 140 undefined testAllowShared([AllowShared] ArrayBuffer buffer); 141 undefined testDictWithAllowShared(optional DictWithAllowSharedBufferSource buffer = {}); 142 undefined testUnionOfBufferSource((ArrayBuffer or ArrayBufferView or DOMString) foo); 143 undefined testUnionOfAllowSharedBufferSource(AllowSharedBufferSource foo); 144 undefined testUnionWithAllowShared([AllowShared] (Int8Array or Int16Array) foo); 145 146 boolean staticAndNonStaticOverload(); 147 static boolean staticAndNonStaticOverload(optional unsigned long foo); 148 149 [ChromeOnly, NewObject] 150 static TestChromeOnlyInterface createTestChromeOnlyInterface(); 151 }; 152 153 [Pref="dom.expose_test_interfaces", 154 ChromeOnly, 155 Exposed=Window] 156 interface TestChromeOnlyInterface { 157 }; 158 159 [Pref="dom.expose_test_interfaces", 160 Exposed=Window] 161 interface TestReflectedHTMLAttribute { 162 constructor(); 163 164 [Frozen, ReflectedHTMLAttributeReturningFrozenArray] 165 attribute sequence<Element>? reflectedHTMLAttribute; 166 undefined setReflectedHTMLAttributeValue(sequence<Element> seq); 167 }; 168 169 dictionary DictWithAllowSharedBufferSource { 170 ArrayBuffer arrayBuffer; 171 ArrayBufferView arrayBufferView; 172 [AllowShared] ArrayBuffer allowSharedArrayBuffer; 173 [AllowShared] ArrayBufferView allowSharedArrayBufferView; 174 };