How to use evalInRealmAndReturn method in wpt

Best JavaScript code snippet using wpt

realms.window.js

Source:realms.window.js Github

copy

Full Screen

...76 await waitOn;77}78// The same as evalInRealmAndWait but returns the result of evaluating "code" as79// an expression.80async function evalInRealmAndReturn(realm, code) {81 const myId = id();82 await evalInRealmAndWait(realm, `window.${myId} = ${code};`);83 return realm[myId];84}85// Constructs an object in constructedRealm and copies it into readRealm and86// writeRealm. Returns the id that can be used to access the object in those87// realms. |what| can contain constructor arguments.88async function constructAndStore(what) {89 const objId = id();90 // Call |constructorRealm|'s constructor from inside |constructedRealm|.91 writeRealm[objId] = await evalInRealmAndReturn(92 constructedRealm, `new parent.constructorRealm.${what}`);93 readRealm[objId] = writeRealm[objId];94 return objId;95}96// Calls read() on the readable side of the TransformStream stored in97// readRealm[objId]. Locks the readable side as a side-effect.98function readInReadRealm(objId) {99 return evalInRealmAndReturn(readRealm, `100parent.readMethod.call(window.${objId}.readable.getReader())`);101}102// Calls write() on the writable side of the TransformStream stored in103// writeRealm[objId], passing |value|. Locks the writable side as a104// side-effect.105function writeInWriteRealm(objId, value) {106 const valueId = id();107 writeRealm[valueId] = value;108 return evalInRealmAndReturn(writeRealm, `109parent.writeMethod.call(window.${objId}.writable.getWriter(),110 window.${valueId})`);111}112window.onload = () => {113 createRealms().then(() => {114 runGenericTests('TextEncoderStream');115 runTextEncoderStreamTests();116 runGenericTests('TextDecoderStream');117 runTextDecoderStreamTests();118 done();119 });120};121function runGenericTests(classname) {122 promise_test(async () => {123 const obj = await evalInRealmAndReturn(124 constructedRealm, `new parent.constructorRealm.${classname}()`);125 assert_equals(obj.constructor, constructorRealm[classname],126 'obj should be in constructor realm');127 }, `a ${classname} object should be associated with the realm the ` +128 'constructor came from');129 promise_test(async () => {130 const objId = await constructAndStore(classname);131 const readableGetterId = id();132 readRealm[readableGetterId] = Object.getOwnPropertyDescriptor(133 methodRealm[classname].prototype, 'readable').get;134 const writableGetterId = id();135 writeRealm[writableGetterId] = Object.getOwnPropertyDescriptor(136 methodRealm[classname].prototype, 'writable').get;137 const readable = await evalInRealmAndReturn(138 readRealm, `${readableGetterId}.call(${objId})`);139 const writable = await evalInRealmAndReturn(140 writeRealm, `${writableGetterId}.call(${objId})`);141 assert_equals(readable.constructor, constructorRealm.ReadableStream,142 'readable should be in constructor realm');143 assert_equals(writable.constructor, constructorRealm.WritableStream,144 'writable should be in constructor realm');145 }, `${classname}'s readable and writable attributes should come from the ` +146 'same realm as the constructor definition');147}148function runTextEncoderStreamTests() {149 promise_test(async () => {150 const objId = await constructAndStore('TextEncoderStream');151 const writePromise = writeInWriteRealm(objId, 'A');152 const result = await readInReadRealm(objId);153 await writePromise;154 assert_equals(result.constructor, constructorRealm.Object,155 'result should be in constructor realm');156 assert_equals(result.value.constructor, constructorRealm.Uint8Array,157 'chunk should be in constructor realm');158 }, 'the output chunks when read is called after write should come from the ' +159 'same realm as the constructor of TextEncoderStream');160 promise_test(async () => {161 const objId = await constructAndStore('TextEncoderStream');162 const chunkPromise = readInReadRealm(objId);163 writeInWriteRealm(objId, 'A');164 // Now the read() should resolve.165 const result = await chunkPromise;166 assert_equals(result.constructor, constructorRealm.Object,167 'result should be in constructor realm');168 assert_equals(result.value.constructor, constructorRealm.Uint8Array,169 'chunk should be in constructor realm');170 }, 'the output chunks when write is called with a pending read should come ' +171 'from the same realm as the constructor of TextEncoderStream');172 // There is not absolute consensus regarding what realm exceptions should be173 // created in. Implementations may vary. The expectations in exception-related174 // tests may change in future once consensus is reached.175 promise_test(async t => {176 const objId = await constructAndStore('TextEncoderStream');177 // Read first to relieve backpressure.178 const readPromise = readInReadRealm(objId);179 await promise_rejects_js(t, constructorRealm.TypeError,180 writeInWriteRealm(objId, {181 toString() { return {}; }182 }),183 'write TypeError should come from constructor realm');184 return promise_rejects_js(t, constructorRealm.TypeError, readPromise,185 'read TypeError should come from constructor realm');186 }, 'TypeError for unconvertable chunk should come from constructor realm ' +187 'of TextEncoderStream');188}189function runTextDecoderStreamTests() {190 promise_test(async () => {191 const objId = await constructAndStore('TextDecoderStream');192 const writePromise = writeInWriteRealm(objId, new Uint8Array([65]));193 const result = await readInReadRealm(objId);194 await writePromise;195 assert_equals(result.constructor, constructorRealm.Object,196 'result should be in constructor realm');197 // A string is not an object, so doesn't have an associated realm. Accessing198 // string properties will create a transient object wrapper belonging to the199 // current realm. So checking the realm of result.value is not useful.200 }, 'the result object when read is called after write should come from the ' +201 'same realm as the constructor of TextDecoderStream');202 promise_test(async () => {203 const objId = await constructAndStore('TextDecoderStream');204 const chunkPromise = readInReadRealm(objId);205 writeInWriteRealm(objId, new Uint8Array([65]));206 // Now the read() should resolve.207 const result = await chunkPromise;208 assert_equals(result.constructor, constructorRealm.Object,209 'result should be in constructor realm');210 // A string is not an object, so doesn't have an associated realm. Accessing211 // string properties will create a transient object wrapper belonging to the212 // current realm. So checking the realm of result.value is not useful.213 }, 'the result object when write is called with a pending ' +214 'read should come from the same realm as the constructor of TextDecoderStream');215 promise_test(async t => {216 const objId = await constructAndStore('TextDecoderStream');217 // Read first to relieve backpressure.218 const readPromise = readInReadRealm(objId);219 await promise_rejects_js(220 t, constructorRealm.TypeError,221 writeInWriteRealm(objId, {}),222 'write TypeError should come from constructor realm'223 );224 return promise_rejects_js(225 t, constructorRealm.TypeError, readPromise,226 'read TypeError should come from constructor realm'227 );228 }, 'TypeError for chunk with the wrong type should come from constructor ' +229 'realm of TextDecoderStream');230 promise_test(async t => {231 const objId =232 await constructAndStore(`TextDecoderStream('utf-8', {fatal: true})`);233 // Read first to relieve backpressure.234 const readPromise = readInReadRealm(objId);235 await promise_rejects_js(236 t, constructorRealm.TypeError,237 writeInWriteRealm(objId, new Uint8Array([0xff])),238 'write TypeError should come from constructor realm'239 );240 return promise_rejects_js(241 t, constructorRealm.TypeError, readPromise,242 'read TypeError should come from constructor realm'243 );244 }, 'TypeError for invalid chunk should come from constructor realm ' +245 'of TextDecoderStream');246 promise_test(async t => {247 const objId =248 await constructAndStore(`TextDecoderStream('utf-8', {fatal: true})`);249 // Read first to relieve backpressure.250 readInReadRealm(objId);251 // Write an unfinished sequence of bytes.252 const incompleteBytesId = id();253 writeRealm[incompleteBytesId] = new Uint8Array([0xf0]);254 return promise_rejects_js(255 t, constructorRealm.TypeError,256 // Can't use writeInWriteRealm() here because it doesn't make it possible257 // to reuse the writer.258 evalInRealmAndReturn(writeRealm, `259(() => {260 const writer = window.${objId}.writable.getWriter();261 parent.writeMethod.call(writer, window.${incompleteBytesId});262 return parent.methodRealm.WritableStreamDefaultWriter.prototype263 .close.call(writer);264})();265`),266 'close TypeError should come from constructor realm'267 );268 }, 'TypeError for incomplete input should come from constructor realm ' +269 'of TextDecoderStream');...

Full Screen

Full Screen

aflprep_realms.window.js

Source:aflprep_realms.window.js Github

copy

Full Screen

...54 evalInRealm(realm, code);55 evalInRealm(realm, `${resolve}();`);56 await waitOn;57}58async function evalInRealmAndReturn(realm, code) {59 const myId = id();60 await evalInRealmAndWait(realm, `window.${myId} = ${code};`);61 return realm[myId];62}63async function constructAndStore(what) {64 const objId = id();65 writeRealm[objId] = await evalInRealmAndReturn(66 constructedRealm, `new parent.constructorRealm.${what}`);67 readRealm[objId] = writeRealm[objId];68 return objId;69}70function readInReadRealm(objId) {71 return evalInRealmAndReturn(readRealm, `72parent.readMethod.call(window.${objId}.readable.getReader())`);73}74function writeInWriteRealm(objId, value) {75 const valueId = id();76 writeRealm[valueId] = value;77 return evalInRealmAndReturn(writeRealm, `78parent.writeMethod.call(window.${objId}.writable.getWriter(),79 window.${valueId})`);80}81window.onload = () => {82 createRealms().then(() => {83 runGenericTests('TextEncoderStream');84 runTextEncoderStreamTests();85 runGenericTests('TextDecoderStream');86 runTextDecoderStreamTests();87 done();88 });89};90function runGenericTests(classname) {91 promise_test(async () => {92 const obj = await evalInRealmAndReturn(93 constructedRealm, `new parent.constructorRealm.${classname}()`);94 assert_equals(obj.constructor, constructorRealm[classname],95 'obj should be in constructor realm');96 }, `a ${classname} object should be associated with the realm the ` +97 'constructor came from');98 promise_test(async () => {99 const objId = await constructAndStore(classname);100 const readableGetterId = id();101 readRealm[readableGetterId] = Object.getOwnPropertyDescriptor(102 methodRealm[classname].prototype, 'readable').get;103 const writableGetterId = id();104 writeRealm[writableGetterId] = Object.getOwnPropertyDescriptor(105 methodRealm[classname].prototype, 'writable').get;106 const readable = await evalInRealmAndReturn(107 readRealm, `${readableGetterId}.call(${objId})`);108 const writable = await evalInRealmAndReturn(109 writeRealm, `${writableGetterId}.call(${objId})`);110 assert_equals(readable.constructor, constructorRealm.ReadableStream,111 'readable should be in constructor realm');112 assert_equals(writable.constructor, constructorRealm.WritableStream,113 'writable should be in constructor realm');114 }, `${classname}'s readable and writable attributes should come from the ` +115 'same realm as the constructor definition');116}117function runTextEncoderStreamTests() {118 promise_test(async () => {119 const objId = await constructAndStore('TextEncoderStream');120 const writePromise = writeInWriteRealm(objId, 'A');121 const result = await readInReadRealm(objId);122 await writePromise;123 assert_equals(result.constructor, constructorRealm.Object,124 'result should be in constructor realm');125 assert_equals(result.value.constructor, constructorRealm.Uint8Array,126 'chunk should be in constructor realm');127 }, 'the output chunks when read is called after write should come from the ' +128 'same realm as the constructor of TextEncoderStream');129 promise_test(async () => {130 const objId = await constructAndStore('TextEncoderStream');131 const chunkPromise = readInReadRealm(objId);132 writeInWriteRealm(objId, 'A');133 const result = await chunkPromise;134 assert_equals(result.constructor, constructorRealm.Object,135 'result should be in constructor realm');136 assert_equals(result.value.constructor, constructorRealm.Uint8Array,137 'chunk should be in constructor realm');138 }, 'the output chunks when write is called with a pending read should come ' +139 'from the same realm as the constructor of TextEncoderStream');140 promise_test(async t => {141 const objId = await constructAndStore('TextEncoderStream');142 const readPromise = readInReadRealm(objId);143 await promise_rejects_js(t, constructorRealm.TypeError,144 writeInWriteRealm(objId, {145 toString() { return {}; }146 }),147 'write TypeError should come from constructor realm');148 return promise_rejects_js(t, constructorRealm.TypeError, readPromise,149 'read TypeError should come from constructor realm');150 }, 'TypeError for unconvertable chunk should come from constructor realm ' +151 'of TextEncoderStream');152}153function runTextDecoderStreamTests() {154 promise_test(async () => {155 const objId = await constructAndStore('TextDecoderStream');156 const writePromise = writeInWriteRealm(objId, new Uint8Array([65]));157 const result = await readInReadRealm(objId);158 await writePromise;159 assert_equals(result.constructor, constructorRealm.Object,160 'result should be in constructor realm');161 }, 'the result object when read is called after write should come from the ' +162 'same realm as the constructor of TextDecoderStream');163 promise_test(async () => {164 const objId = await constructAndStore('TextDecoderStream');165 const chunkPromise = readInReadRealm(objId);166 writeInWriteRealm(objId, new Uint8Array([65]));167 const result = await chunkPromise;168 assert_equals(result.constructor, constructorRealm.Object,169 'result should be in constructor realm');170 }, 'the result object when write is called with a pending ' +171 'read should come from the same realm as the constructor of TextDecoderStream');172 promise_test(async t => {173 const objId = await constructAndStore('TextDecoderStream');174 const readPromise = readInReadRealm(objId);175 await promise_rejects_js(176 t, constructorRealm.TypeError,177 writeInWriteRealm(objId, {}),178 'write TypeError should come from constructor realm'179 );180 return promise_rejects_js(181 t, constructorRealm.TypeError, readPromise,182 'read TypeError should come from constructor realm'183 );184 }, 'TypeError for chunk with the wrong type should come from constructor ' +185 'realm of TextDecoderStream');186 promise_test(async t => {187 const objId =188 await constructAndStore(`TextDecoderStream('utf-8', {fatal: true})`);189 const readPromise = readInReadRealm(objId);190 await promise_rejects_js(191 t, constructorRealm.TypeError,192 writeInWriteRealm(objId, new Uint8Array([0xff])),193 'write TypeError should come from constructor realm'194 );195 return promise_rejects_js(196 t, constructorRealm.TypeError, readPromise,197 'read TypeError should come from constructor realm'198 );199 }, 'TypeError for invalid chunk should come from constructor realm ' +200 'of TextDecoderStream');201 promise_test(async t => {202 const objId =203 await constructAndStore(`TextDecoderStream('utf-8', {fatal: true})`);204 readInReadRealm(objId);205 const incompleteBytesId = id();206 writeRealm[incompleteBytesId] = new Uint8Array([0xf0]);207 return promise_rejects_js(208 t, constructorRealm.TypeError,209 evalInRealmAndReturn(writeRealm, `210(() => {211 const writer = window.${objId}.writable.getWriter();212 parent.writeMethod.call(writer, window.${incompleteBytesId});213 return parent.methodRealm.WritableStreamDefaultWriter.prototype214 .close.call(writer);215})();216`),217 'close TypeError should come from constructor realm'218 );219 }, 'TypeError for incomplete input should come from constructor realm ' +220 'of TextDecoderStream');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptRunner = require("wpt-runner");2var wpt = new wptRunner();3var realm = wpt.createRealm();4var result = wpt.evalInRealmAndReturn(realm, "var a = 10; a + 20;");5var wptRunner = require("wpt-runner");6var wpt = new wptRunner();7var realm = wpt.createRealm();8var result = wpt.evalInRealmAndReturn(realm, "var a = 10; a + 20;");9var wptRunner = require("wpt-runner");10var wpt = new wptRunner();11var realm = wpt.createRealm();12var result = wpt.evalInRealmAndReturn(realm, "var a = 10; a + 20;");13var wptRunner = require("wpt-runner");14var wpt = new wptRunner();15var realm = wpt.createRealm();16var result = wpt.evalInRealmAndReturn(realm, "var a = 10; a + 20;");17var wptRunner = require("wpt-runner");18var wpt = new wptRunner();19var realm = wpt.createRealm();20var result = wpt.evalInRealmAndReturn(realm, "var a = 10; a + 20;");21var wptRunner = require("wpt-runner");22var wpt = new wptRunner();23var realm = wpt.createRealm();24var result = wpt.evalInRealmAndReturn(realm, "var a = 10; a + 20;");25var wptRunner = require("wpt-runner");26var wpt = new wptRunner();27var realm = wpt.createRealm();28var result = wpt.evalInRealmAndReturn(realm, "var a = 10

Full Screen

Using AI Code Generation

copy

Full Screen

1var realm = new Reflect.Realm();2var global = realm.global;3var code = "function foo() { return 'foo'; }";4var result = evalInRealmAndReturn(realm, code);5assert_equals(result, 'foo');6var realm = new Reflect.Realm();7var global = realm.global;8var code = "function foo() { return 'foo'; }";9var result = evalInRealm(realm, code);10assert_equals(result, 'foo');11var realm = new Reflect.Realm();12var global = realm.global;13var code = "function foo() { return 'foo'; }";14var result = evalInRealm(realm, code);15assert_equals(result, 'foo');

Full Screen

Using AI Code Generation

copy

Full Screen

1var result = evalInRealmAndReturn(function() {2 var a = 10;3 var b = 20;4 return a + b;5});6var result = evalInRealmAndReturn(function(a, b) {7 return a + b;8}, [10, 20]);9var result = evalInRealmAndReturn(function(a, b) {10 return a + b;11}, [10, function() {12 return 20;13}]);14var result = evalInRealmAndReturn(function(a, b) {15 return a + b;16}, [10, function() {17 return 20;18}]);19var result = evalInRealmAndReturn(function(a, b) {20 return a + b;21}, [10, function() {22 return 20;23}]);24var result = evalInRealmAndReturn(function(a, b) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var realm = evalInRealmAndReturn(`2 var realm = {};3 realm.a = 1;4 realm.b = 2;5 realm.add = function() {6 return this.a + this.b;7 }8`);9var result = realm.add();

Full Screen

Using AI Code Generation

copy

Full Screen

1var result = evalInRealmAndReturn("var x = 5; x");2assert_equals(result, 5, "result of script in new realm should be 5");3var result = evalInRealmAndReturn("var x = 5; x");4assert_equals(result, 5, "result of script in new realm should be 5");5var result = evalInRealmAndReturn("var x = 5; x");6assert_equals(result, 5, "result of script in new realm should be 5");7var result = evalInRealmAndReturn("var x = 5; x");8assert_equals(result, 5, "result of script in new realm should be 5");9var result = evalInRealmAndReturn("var x = 5; x");10assert_equals(result, 5, "result of script in new realm should be 5");11var result = evalInRealmAndReturn("var x = 5; x");12assert_equals(result, 5, "result of script in new realm should be 5");13var result = evalInRealmAndReturn("var x = 5; x");14assert_equals(result,

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful