Sha256: f192fcc3055bdcf66a996e1a934c8e800729bc8329652f94b50fd41dc7ca4db2

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

"use strict";
const DOMException = require("domexception/webidl2js-wrapper");
const MessageEvent = require("./generated/MessageEvent");
const idlUtils = require("./generated/utils");
const { isValidTargetOrigin } = require("../utils");
const { fireAnEvent } = require("./helpers/events");

module.exports = function (globalObject) {
  return function (message, targetOrigin) {
    if (arguments.length < 2) {
      throw new TypeError("'postMessage' requires 2 arguments: 'message' and 'targetOrigin'");
    }

    targetOrigin = String(targetOrigin);

    if (!isValidTargetOrigin(targetOrigin)) {
      // TODO: Fix me
      throw DOMException.create(globalObject, [
        "Failed to execute 'postMessage' on 'Window': " +
        "Invalid target origin '" + targetOrigin + "' in a call to 'postMessage'.",
        "SyntaxError"
      ]);
    }

    // TODO: targetOrigin === '/' - requires reference to source window
    // See https://github.com/jsdom/jsdom/pull/1140#issuecomment-111587499
    if (targetOrigin !== "*" && targetOrigin !== idlUtils.implForWrapper(globalObject._document)._origin) {
      return;
    }

    // TODO: event.source - requires reference to source window
    // TODO: event.origin - requires reference to source window
    // TODO: event.ports
    // TODO: event.data - structured clone message - requires cloning DOM nodes
    setTimeout(() => {
      fireAnEvent("message", this, MessageEvent, { data: message });
    }, 0);
  };
};

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.72.1 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.72.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.71.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.70.2 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.70.1 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.70.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.69.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.68.2 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.68.1 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.68.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.67.1 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.67.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.66.2 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.66.1 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.66.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.65.1 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.65.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.64.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js
appmap-0.63.0 ./node_modules/jsdom/lib/jsdom/living/post-message.js