Commit 2173d214 authored by olehougaard's avatar olehougaard

Restrict application of eval so it can only be used in the context of the...

Restrict application of eval so it can only be used in the context of the global object. For compatibility.
Review URL: http://codereview.chromium.org/10748

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@757 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1555d130
...@@ -105,6 +105,11 @@ function GlobalParseFloat(string) { ...@@ -105,6 +105,11 @@ function GlobalParseFloat(string) {
function GlobalEval(x) { function GlobalEval(x) {
if (!IS_STRING(x)) return x; if (!IS_STRING(x)) return x;
if (this !== %GlobalReceiver(global)) {
throw $EvalError('The "this" object passed to eval ' +
'must be the global object from which eval originated');
}
var f = %CompileString(x, 0, true); var f = %CompileString(x, 0, true);
if (!IS_FUNCTION(f)) return f; if (!IS_FUNCTION(f)) return f;
......
...@@ -4078,6 +4078,14 @@ THREADED_TEST(CrossEval) { ...@@ -4078,6 +4078,14 @@ THREADED_TEST(CrossEval) {
"with({x:2}){other.eval('x+y')}")); "with({x:2}){other.eval('x+y')}"));
result = script->Run(); result = script->Run();
CHECK_EQ(3, result->Int32Value()); CHECK_EQ(3, result->Int32Value());
// Check that you cannot use 'eval.call' with another object than the
// current global object.
v8::TryCatch try_catch;
script =
Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
result = script->Run();
CHECK(try_catch.HasCaught());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment