David said:
You don't normally go through all of that for every function (lots of
tests need these methods.)
This may be true because `document.body' could be considered to refer
to the same object on every call. However, that does not need to be so.
The method may be reused in another global context, for example.
I don't see why you need gEBI for this one.
Add me.
Don't need to test wrapper.
Not testing the return value would be at least unwise. Per W3C DOM Level 2
Core the createElement() method may throw a DOMException
(INVALID_CHARACTER_ERR) "if the specified name contains an illegal
character"; implementations vary, of course. For example, it is reasonable
to assume that if there is any error creating the object (that is, at least
reserving heap memory for it), the method call will fail in some way. So
the return value may as well not be a reference to a host object. However,
we can safely assume (based on empirical data) that if it is not a reference
to a host object it is a false-value, and (employing simple logic) that if
it is a reference to a host object that the result of the expression is a
true-value, and the property access does not throw an exception (else
`wrapper.style' aso. would not work, too).
The wise answer is "Yes and yes." `elAbs' is used as the base object of a
property access below, so it needs to be tested or the property access could
throw a ReferenceError (or worse). And since it does not make sense to
continue if creation of the object failed, that object reference should be
tested as early as possible, which would be exactly here.
var elRel = document.createElement('div');
// should we perform the same check here again?
No.
Yes.
[...]
var elStatic = document.createElement('div');
// what about this one?
No.
Yes.
elStatic.style.height = '10px';
elStatic.style.fontSize = '1px';
clearStyles(elStatic);
var el = document.createElement('div');
// do we test appendChild on every of these elements
// before calling it?
No.
The wise answer is "Definitely yes."; everything else would be a type II
object inference, known to be error-prone. Never rely on that if an object
implements one method specified for an API or is created by another
implemented method specified for the same API, it would support a third
method specified for that API.
Don't need to test el or el.style at this point.
Correct, that test should happen directly after the assignment to `el'.
Because currently we continue with body.insertBefore() despite the
possibility of `el' being not an object reference (which does not make
sense), and `el' is used as an argument to a host method without being
tested first.
Logic suggests that it SHOULD NOT be tested this way because the result of
the `typeof' operation may not indicate the type of the result of the plain
expression.
Yes, but again this should be a one-time test.
That test is fine as it is . It is already a one-time test for property of
the host object previously created, because that object is a different one
on every call.
Please trim your quotes to the necessary minimum required to retain the
context of your replies.
PointedEars