From 0e5ae0a2f4879c9cacbc2f8ea87d26747c1ec49e Mon Sep 17 00:00:00 2001
From: Nicolas Chevobbe
Date: Mon, 26 May 2025 14:12:35 +0200
Subject: [PATCH 1/3] [WIP] Specify console.context
This specifies the console.context(label) method which
returns a new console namespace object with an optional
context name label.
Tests: TBD
Fixes #193
---
index.bs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/index.bs b/index.bs
index 6a6ea21..b84c509 100644
--- a/index.bs
+++ b/index.bs
@@ -83,6 +83,9 @@ namespace console { // but see namespace object requirements below
undefined time(optional DOMString label = "default");
undefined timeLog(optional DOMString label = "default", any... data);
undefined timeEnd(optional DOMString label = "default");
+
+ // Contextualizing
+ console context(optional DOMString label = "");
};
@@ -291,6 +294,18 @@ for plans to make {{console/timeEnd()}} and {{console/timeLog()}} formally repor
console when a given |label| does not exist in the associated timer table.
+Contextualizing
+
+Each {{console}} namespace object has an associated context name, empty by default.
+
+context(|label|)
+
+1. Let |context| be a new {{console}} namespace object.
+1. Let |contextName| be the empty string.
+1. If |label| is not null, let |contextName| be |label|.
+1. Let |context|'s context name be |contextName|.
+1. Return |context|.
+
Supporting abstract operations
Logger(|logLevel|, |args|)
@@ -513,6 +528,9 @@ enhancements:
src="images/severity-filter.png">
+
+ Extra UI allowing the user to filter messages by context name
+
Extra UI off to the side indicating the current state of the timer table,
group stack, or other internally maintained data.
From b45179685d77b8232fbd1fb24c7a4f32e9c7167b Mon Sep 17 00:00:00 2001
From: Nicolas Chevobbe
Date: Mon, 26 May 2025 15:03:35 +0200
Subject: [PATCH 2/3] accept @annevk suggestions
---
index.bs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/index.bs b/index.bs
index b84c509..245e6ed 100644
--- a/index.bs
+++ b/index.bs
@@ -302,8 +302,8 @@ Each {{console}} namespace object has an associated context name, emp
1. Let |context| be a new {{console}} namespace object.
1. Let |contextName| be the empty string.
-1. If |label| is not null, let |contextName| be |label|.
-1. Let |context|'s context name be |contextName|.
+1. If |label| is not null, then set |contextName| to |label|.
+1. Set |context|'s context name to |contextName|.
1. Return |context|.
Supporting abstract operations
From bbb38cb0edb18fd2007d696f6af1ef12c8abd222 Mon Sep 17 00:00:00 2001
From: Nicolas Chevobbe
Date: Mon, 17 Nov 2025 09:22:30 +0100
Subject: [PATCH 3/3] Add ConsoleContext interface
---
index.bs | 84 ++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 60 insertions(+), 24 deletions(-)
diff --git a/index.bs b/index.bs
index 245e6ed..e4087cb 100644
--- a/index.bs
+++ b/index.bs
@@ -85,7 +85,7 @@ namespace console { // but see namespace object requirements below
undefined timeEnd(optional DOMString label = "default");
// Contextualizing
- console context(optional DOMString label = "");
+ ConsoleContext context(optional DOMString label = "");
};
@@ -104,7 +104,7 @@ its \[[Prototype]] an empty object, created as if by
Logging functions
-assert(|condition|, ...|data|)
+assert(|condition|, ...|data|)
1. If |condition| is true, return.
1. Let |message| be a string without any formatting specifiers indicating generically an assertion
@@ -118,28 +118,28 @@ its \[[Prototype]] an empty object, created as if by
1. Set |data|[0] to |concat|.
1. Perform Logger("assert", |data|).
-clear()
+clear()
1. [=stack/Empty=] the appropriate group stack.
1. If possible for the environment, clear the console. (Otherwise, do nothing.)
-debug(...|data|)
+debug(...|data|)
1. Perform Logger("debug", |data|).
-error(...|data|)
+error(...|data|)
1. Perform Logger("error", |data|).
-info(...|data|)
+info(...|data|)
1. Perform Logger("info", |data|).
-log(...|data|)
+log(...|data|)
1. Perform Logger("log", |data|).
-table(|tabularData|, |properties|)
+table(|tabularData|, |properties|)
Try to construct a table with the columns of the properties of |tabularData| (or use
|properties|) and rows of |tabularData| and log it with a logLevel of "log". Fall
@@ -147,7 +147,7 @@ back to just logging the argument if it can't be parsed as tabular.
TODO: This will need a good algorithm.
-trace(...|data|)
+trace(...|data|)
1. Let |trace| be some implementation-defined, potentially-interactive representation of the
callstack from where this function was called.
@@ -160,16 +160,16 @@ back to just logging the argument if it can't be parsed as tabular.
not guaranteed to be the same identifier that would be seen in `new Error().stack`.
-warn(...|data|)
+warn(...|data|)
1. Perform Logger("warn", |data|).
-dir(|item|, |options|)
+dir(|item|, |options|)
1. Let |object| be |item| with generic JavaScript object formatting applied.
1. Perform Printer("dir", « |object| », |options|).
-dirxml(...|data|)
+dirxml(...|data|)
1. Let |finalList| be a new [=/list=], initially empty.
1. [=list/For each=] |item| of |data|:
@@ -180,10 +180,10 @@ back to just logging the argument if it can't be parsed as tabular.
Counting functions
-Each {{console}} namespace object has an associated count map, which is a map of
+Each {{console}} namespace object and {{ConsoleContext}} instance has an associated count map, which is a map of
strings to numbers, initially empty.
-count(|label|)
+count(|label|)
1. Let |map| be the associated count map.
1. If |map|[|label|] [=map/exists=], [=map/set=] |map|[|label|] to |map|[|label|] + 1.
@@ -192,7 +192,7 @@ Each {{console}} namespace object has an associated count map, which
ToString(|map|[|label|]).
1. Perform Logger("count", « |concat| »).
-countReset(|label|)
+countReset(|label|)
1. Let |map| be the associated count map.
1. If |map|[|label|] [=map/exists=], [=map/set=] |map|[|label|] to 0.
@@ -205,11 +205,11 @@ Each {{console}} namespace object has an associated count map, which
A group is an implementation-defined, potentially-interactive
view for output produced by calls to Printer, with one further level of
-indentation than its parent. Each {{console}} namespace object has an associated group
+indentation than its parent. Each {{console}} namespace object and {{ConsoleContext}} instance has an associated group
stack, which is a stack, initially empty. Only the last group in a group
stack will host output produced by calls to Printer.
-group(...|data|)
+group(...|data|)
1. Let |group| be a new group.
1. If |data| is not [=list/is empty|empty=], let |groupLabel| be the result of
@@ -221,7 +221,7 @@ stack will host output produced by calls to Printer.
1. Perform Printer("group", « |group| »).
1. [=stack/Push=] |group| onto the appropriate group stack.
-groupCollapsed(...|data|)
+groupCollapsed(...|data|)
1. Let |group| be a new group.
1. If |data| is not empty, let |groupLabel| be the result of
@@ -233,7 +233,7 @@ stack will host output produced by calls to Printer.
1. Perform Printer("groupCollapsed", « |group| »).
1. [=stack/Push=] |group| onto the appropriate group stack.
-groupEnd()
+groupEnd()
1. Pop the last group from the group stack.
@@ -242,7 +242,7 @@ stack will host output produced by calls to Printer.
Each {{console}} namespace object has an associated timer table, which is a map of
strings to times, initially empty.
-time(|label|)
+time(|label|)
1. If the associated timer table [=map/contains=] an entry with key |label|, return,
optionally reporting a warning to the console indicating that a timer with label |label| has
@@ -250,7 +250,7 @@ Each {{console}} namespace object has an associated timer table, whic
1. Otherwise, [=map/set=] the value of the entry with key |label| in the associated
timer table to the current time.
-timeLog(|label|, ...|data|)
+timeLog(|label|, ...|data|)
1. Let |timerTable| be the associated timer table.
1. Let |startTime| be |timerTable|[|label|].
@@ -279,7 +279,7 @@ Each {{console}} namespace object has an associated timer table, whic
-timeEnd(|label|)
+timeEnd(|label|)
1. Let |timerTable| be the associated timer table.
1. Let |startTime| be |timerTable|[|label|].
@@ -296,16 +296,52 @@ console when a given |label| does not exist in the associated timer table
Contextualizing
-Each {{console}} namespace object has an associated context name, empty by default.
+Each {{ConsoleContext}} instance has an associated context name, empty by default.
context(|label|)
-1. Let |context| be a new {{console}} namespace object.
+1. Let |context| be a new {{ConsoleContext}} instance.
1. Let |contextName| be the empty string.
1. If |label| is not null, then set |contextName| to |label|.
1. Set |context|'s context name to |contextName|.
1. Return |context|.
+The {{ConsoleContext}} interface
+
+The IDL for the {{ConsoleContext}} interface is as follows, with the various methods defined in the {{console}} section:
+
+
+[Exposed=*]
+interface ConsoleContext {
+ // Logging
+ undefined assert(optional boolean condition = false, any... data);
+ undefined clear();
+ undefined debug(any... data);
+ undefined error(any... data);
+ undefined info(any... data);
+ undefined log(any... data);
+ undefined table(optional any tabularData, optional sequence<DOMString> properties);
+ undefined trace(any... data);
+ undefined warn(any... data);
+ undefined dir(optional any item, optional object? options);
+ undefined dirxml(any... data);
+
+ // Counting
+ undefined count(optional DOMString label = "default");
+ undefined countReset(optional DOMString label = "default");
+
+ // Grouping
+ undefined group(any... data);
+ undefined groupCollapsed(any... data);
+ undefined groupEnd();
+
+ // Timing
+ undefined time(optional DOMString label = "default");
+ undefined timeLog(optional DOMString label = "default", any... data);
+ undefined timeEnd(optional DOMString label = "default");
+};
+
+
Supporting abstract operations
Logger(|logLevel|, |args|)