Comment #2 on issue 278 by isaacschlueter: Can't change a function's "name"
property
http://code.google.com/p/v8/issues/detail?id=278
Hm, it seems that you're right, Safari also sets the {ReadOnly} flag on
Function.name. Firefox lets you set a name for anonymous functions, but
you can't do
that in the spidermonkey shell, which is interesting.
Is this just a common implementation, or does the spec dictate this
behavior? I
can't seem to find *any* mention of Function.name in section 13 of the
ECMAScript 3 spec.
The use case is not terribly vital or common. I have some code that wraps a
function, and the intent was to have it be as transparent as possible to
the calling
code. So, if I do this:
wrap( function foo (n) {return n} );
it should return a different function with the same apparent properties
(toString()
result and name, specifically). The way that I was doing this is like this:
wrapFunction = function (fn) {
var f = function () {
return fn.apply(
this, Array.prototype.slice.call(arguments,0)
);
};
f.toString = function () { return fn.toString(); };
f.name = fn.name;
f.prototype = wrapObject(fn.prototype);
for (var i in fn) {
if (!(i in f)) f[i] = wrap(fn[i]);
}
return f;
};
I'm using this to create a "safe" sandbox for running code. I don't expect
it to be
a perfect protection against all possible malicious code, so being slightly
detectable is not necessarily a problem. However, I would prefer that the
wrapped
function be effectively identical to its parent, in case there are
situations where
function.name is used somehow.
I could get around that by using eval, but I'd hoped there was a "cleaner"
way:
var f = eval("function " + fn.name + "() {"+
"return fn.apply("+
"this, Array.prototype.slice.call(arguments,0)"+
");"+
"};");
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---