Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

52 lines
1.2 KiB
Plaintext

== Why is this an issue?
The use of the ``++with++`` keyword produces an error in JavaScript strict mode code. However, that's not the worst that can be said against ``++with++``.
Using ``++with++`` allows a short-hand access to an object's properties - assuming they're already set. But use ``++with++`` to access some property not already set in the object, and suddenly you're catapulted out of the object scope and into the global scope, creating or overwriting variables there. Since the effects of ``++with++`` are entirely dependent on the object passed to it, ``++with++`` can be dangerously unpredictable, and should never be used.
=== Noncompliant code example
[source,javascript]
----
var x = 'a';
var foo = {
y: 1
}
with (foo) { // Noncompliant
y = 4; // updates foo.y
x = 3; // does NOT add a foo.x property; updates x var in outer scope
}
print(foo.x + " " + x); // shows: undefined 3
----
=== Compliant solution
[source,javascript]
----
var x = 'a';
var foo = {
y: 1
}
foo.y = 4;
foo.x = 3;
print(foo.x + " " + x); // shows: 3 a
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]