From cdd48e1f570c817402bf62108847c4a9f4b00b1e Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 28 Mar 2016 17:16:32 +0200 Subject: [PATCH 1/2] Editorial: put properties shared across globals on mixin This makes the following editorial changes: * Groups base64, timer, and ImageBitmap properties on a single mixin. * Removes overloading of timer methods in favor of a union type It is expected that other standards will make use of this mixin, e.g., Fetch will use it to define fetch(). --- source | 210 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 108 insertions(+), 102 deletions(-) diff --git a/source b/source index 1e90b7b96f4..49927653dfb 100644 --- a/source +++ b/source @@ -87530,21 +87530,47 @@ interface DocumentAndElementEventHandlers { -

Base64 utility methods

+

The WindowOrWorkerGlobalScope mixin

-

The atob() and btoa() methods allow authors to transform content to and from - the base64 encoding.

+

The WindowOrWorkerGlobalScope mixin is for use of APIs that are to be exposed on + Window and WorkerGlobalScope objects.

- +

Other standards are encouraged to further extend it using partial + interface WindowOrWorkerGlobalScope { … }; along with an appropriate + reference.

-
[NoInterfaceObject, Exposed=(Window,Worker)]
-interface WindowBase64 {
-  DOMString btoa(DOMString btoa);
-  DOMString atob(DOMString atob);
+  
typedef (DOMString or Function) TimerHandler;
+
+[NoInterfaceObject, Exposed=(Window,Worker)]
+interface WindowOrWorkerGlobalScope {
+  // base64 utility methods
+  DOMString btoa(DOMString data);
+  DOMString atob(DOMString data);
+
+  // timers
+  long setTimeout(TimerHandler handler, optional long timeout = 0, any... arguments);
+  void clearTimeout(optional long handle = 0);
+  long setInterval(TimerHandler handler, optional long timeout = 0, any... arguments);
+  void clearInterval(optional long handle = 0);
+
+  // ImageBitmap
+  Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options);
+  Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options);
 };
-Window implements WindowBase64;
-WorkerGlobalScope implements WindowBase64;
+Window implements WindowOrWorkerGlobalScope; +WorkerGlobalScope implements WindowOrWorkerGlobalScope;
+ + + + +

Base64 utility methods

+ +

The atob() and btoa() methods + allow developers to transform content to and from the base64 encoding.

In these APIs, for mnemonic purposes, the "b" can be considered to stand for "binary", and the "a" for "ASCII". In practice, though, for primarily historical reasons, both the @@ -87552,7 +87578,7 @@ interface WindowBase64 {

-
result = window . btoa( data )
+
result = self . btoa( data )
@@ -87565,7 +87591,7 @@ interface WindowBase64 {
-
result = window . atob( data )
+
result = self . atob( data )
@@ -87583,17 +87609,19 @@ interface WindowBase64 {
-

The btoa() method must throw an - InvalidCharacterError exception if the method's first argument contains any character - whose code point is greater than U+00FF. Otherwise, the user agent must convert that argument to a - sequence of octets whose nth octet is the eight-bit representation of the code - point of the nth character of the argument, and then must apply the base64 - algorithm to that sequence of octets, and return the result.

+

The btoa(data) + method must throw an InvalidCharacterError exception if data contains any + character whose code point is greater than U+00FF. Otherwise, the user agent must convert + data to a sequence of octets whose nth octet is the eight-bit representation + of the code point of the nth character of data, and then must apply the + base64 algorithm to that sequence of octets, and return the result.

+ -

The atob() method must run the following - steps to parse the string passed in the method's first argument:

+

The atob(data) + method, when invoked, must run the following steps:

    @@ -87605,23 +87633,22 @@ interface WindowBase64 { https://lists.w3.org/Archives/Public/public-whatwg-archive/2011May/0207.html --> -
  1. Let input be the string being parsed.

  2. - -
  3. Let position be a pointer into input, initially +

  4. Let position be a pointer into data, initially pointing at the start of the string.

  5. -
  6. Remove all space characters from input.

  7. +
  8. Remove all space characters from + data.

  9. -
  10. If the length of input divides by 4 leaving no remainder, then: if - input ends with one or two U+003D EQUALS SIGN (=) characters, remove them - from input.

  11. +
  12. If the length of data divides by 4 leaving no remainder, then: if + data ends with one or two U+003D EQUALS SIGN (=) characters, remove them from + data.

  13. -
  14. If the length of input divides by 4 leaving a remainder of 1, throw an +

  15. If the length of data divides by 4 leaving a remainder of 1, throw an InvalidCharacterError exception and abort these steps.

  16. -

    If input contains a character that is not in the following list of +

    If data contains a character that is not in the following list of characters and character ranges, throw an InvalidCharacterError exception and abort these steps:

    @@ -87640,8 +87667,8 @@ interface WindowBase64 {
  17. -

    While position does not point past the end of input, - run these substeps:

    +

    While position does not point past the end of data, run these + substeps:

      @@ -88256,31 +88283,13 @@ interface WindowBase64 {

      Timers

      -

      The setTimeout() - and setInterval() - methods allow authors to schedule timer-based callbacks.

      - -
      [NoInterfaceObject, Exposed=(Window,Worker)]
      -interface WindowTimers {
      -  long setTimeout(Function handler, optional long timeout = 0, any... arguments);
      -  long setTimeout(DOMString handler, optional long timeout = 0, any... arguments);
      -  void clearTimeout(optional long handle = 0);
      -  long setInterval(Function handler, optional long timeout = 0, any... arguments);
      -  long setInterval(DOMString handler, optional long timeout = 0, any... arguments);
      -  void clearInterval(optional long handle = 0);
      -};
      -Window implements WindowTimers;
      -WorkerGlobalScope implements WindowTimers;
      - - +

      The setTimeout() and setInterval() methods allow authors to schedule timer-based + callbacks.

      -
      handle = window . setTimeout( handler [, timeout [, arguments... ] ] )
      +
      handle = self . setTimeout( handler [, timeout [, arguments... ] ] )
      @@ -88289,7 +88298,7 @@ interface WindowTimers {
      -
      handle = window . setTimeout( code [, timeout ] )
      +
      handle = self . setTimeout( code [, timeout ] )
      @@ -88297,18 +88306,17 @@ interface WindowTimers {
      -
      window . clearTimeout( handle )
      +
      self . clearTimeout( handle )
      -

      Cancels the timeout set with setTimeout() - or setInterval() identified by - handle.

      +

      Cancels the timeout set with setTimeout() or setInterval() identified by handle.

      -
      handle = window . setInterval( handler [, timeout [, arguments... ] ] )
      +
      handle = self . setInterval( handler [, timeout [, arguments... ] ] )
      @@ -88317,7 +88325,7 @@ interface WindowTimers {
      -
      handle = window . setInterval( code [, timeout ] )
      +
      handle = self . setInterval( code [, timeout ] )
      @@ -88325,14 +88333,13 @@ interface WindowTimers {
      -
      window . clearInterval( handle )
      +
      self . clearInterval( handle )
      -

      Cancels the timeout set with setInterval() - or setTimeout() identified by - handle.

      +

      Cancels the timeout set with setInterval() or setTimeout() identified by handle.

      @@ -88346,34 +88353,41 @@ interface WindowTimers {
      -

      Objects that implement the WindowTimers interface have a list of active - timers. Each entry in this lists is identified by a number, which must be unique within the - list for the lifetime of the object that implements the WindowTimers interface.

      +

      Objects that implement the WindowOrWorkerGlobalScope mixin have a list of + active timers. Each entry in this lists is identified by a number, which must be unique + within the list for the lifetime of the object that implements the + WindowOrWorkerGlobalScope mixin.


      -

      The setTimeout() method must return - the value returned by the timer initialisation steps, passing them the method's - arguments, the object on which the method for which the algorithm is running is implemented (a - Window or WorkerGlobalScope object) as the method - context, and the repeat flag set to false.

      - -

      The setInterval() method must - return the value returned by the timer initialisation steps, passing them the - method's arguments, the object on which the method for which the algorithm is running is - implemented (a Window or WorkerGlobalScope object) as the method context, and the repeat flag set to true.

      - -

      The clearTimeout() and clearInterval() methods must clear the - entry identified as handle from the list of active timers of the - WindowTimers object on which the method was invoked, if any, where handle is the argument passed to the method. (If handle does - not identify an entry in the list of active timers of the WindowTimers - object on which the method was invoked, the method does nothing.)

      - -

      Because clearTimeout() and - clearInterval() clear entries from the same - list, either method can be used to clear timers created by - setTimeout() or - setInterval().

      +

      The setTimeout() method must return the value returned + by the timer initialisation steps, passing them the method's arguments, the object on + which the method for which the algorithm is running is implemented (a Window or + WorkerGlobalScope object) as the method context, and the repeat + flag set to false.

      + +

      The setInterval() method must return the value returned + by the timer initialisation steps, passing them the method's arguments, the object on + which the method for which the algorithm is running is implemented (a Window or + WorkerGlobalScope object) as the method context, and the repeat + flag set to true.

      + +

      The clearTimeout() and clearInterval() + methods must clear the entry identified as handle from the list of active + timers of the WindowOrWorkerGlobalScope object on which the method was + invoked, if any, where handle is the argument passed to the method. (If + handle does not identify an entry in the list of active timers of the + WindowOrWorkerGlobalScope object on which the method was invoked, the method does + nothing.)

      + +

      Because clearTimeout() and clearInterval() clear entries from the same list, either method + can be used to clear timers created by setTimeout() or setInterval().


      @@ -90372,15 +90386,7 @@ dictionary ImageBitmapOptions { ImageOrientation imageOrientation = "none"; PremultiplyAlpha premultiplyAlpha = "default"; ColorspaceConversion colorspaceConversion = "default"; -}; - -[NoInterfaceObject, Exposed=(Window,Worker)] -interface ImageBitmapFactories { - Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options); - Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options); -}; -Window implements ImageBitmapFactories; -WorkerGlobalScope implements ImageBitmapFactories; +};

      An ImageBitmap object represents a bitmap image that can be painted to a canvas without undue latency.

      @@ -90392,8 +90398,8 @@ interface ImageBitmapFactories {
      -
      promise = Window . createImageBitmap(image [, options ])
      -
      promise = Window . createImageBitmap(image, sx, sy, sw, sh [, options ])
      +
      promise = self . createImageBitmap(image [, options ])
      +
      promise = self . createImageBitmap(image, sx, sy, sw, sh [, options ])
      From 6bdba31102d6aea442b215fe485093c0ad322425 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 28 Mar 2016 17:30:20 +0200 Subject: [PATCH 2/2] Introducing self.origin, a reliable way to get the origin of a global Fixes https://www.w3.org/Bugs/Public/show_bug.cgi?id=28801. --- source | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/source b/source index 49927653dfb..1b67596e13b 100644 --- a/source +++ b/source @@ -87543,6 +87543,8 @@ interface DocumentAndElementEventHandlers { [NoInterfaceObject, Exposed=(Window,Worker)] interface WindowOrWorkerGlobalScope { + [Replaceable] readonly attribute USVString origin; + // base64 utility methods DOMString btoa(DOMString data); DOMString atob(DOMString data); @@ -87566,6 +87568,33 @@ interface WindowOrWorkerGlobalScope { http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1229 --> +
      +
      origin = self . origin
      + +

      Returns the global object's origin, serialised as string.

      +
      + +
      +

      Developers are strongly encouraged to use self.origin over location.origin. The former returns the origin of the environment, + the latter of the URL of the environment. Imagine the following script executing in a document on + https://stargate.example/:

      + +
      var frame = document.createElement("iframe")
      +frame.onload = function() {
      +  var frameWin = frame.contentWindow
      +  console.log(frameWin.location.origin) // "null"
      +  console.log(frameWin.origin) // "https://stargate.example"
      +}
      +document.body.appendChild(frame)
      + +

      self.origin is a more reliable security indicator.

      +
      + +

      The origin attribute's getter must return this + object's relevant setting object's origin, serialised.

      +

      Base64 utility methods