Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: src/parser.cc

Issue 11563: Fixing the detection of aliased eval so that it is exact.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); 320 virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with);
321 321
322 virtual Handle<String> LookupSymbol(const char* string, int length) { 322 virtual Handle<String> LookupSymbol(const char* string, int length) {
323 return Handle<String>(); 323 return Handle<String>();
324 } 324 }
325 325
326 virtual Handle<String> EmptySymbol() { 326 virtual Handle<String> EmptySymbol() {
327 return Handle<String>(); 327 return Handle<String>();
328 } 328 }
329 329
330
331
330 virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) { 332 virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) {
331 if (obj == VariableProxySentinel::this_proxy()) { 333 if (obj == VariableProxySentinel::this_proxy()) {
332 return Property::this_property(); 334 return Property::this_property();
333 } else { 335 } else {
334 return ValidLeftHandSideSentinel::instance(); 336 return ValidLeftHandSideSentinel::instance();
335 } 337 }
336 } 338 }
337 339
338 virtual Expression* NewCall(Expression* expression, 340 virtual Expression* NewCall(Expression* expression,
339 ZoneList<Expression*>* arguments, 341 ZoneList<Expression*>* arguments,
340 bool is_eval, int pos) { 342 Call::EvalType eval_type, int pos) {
341 return Call::sentinel(); 343 return Call::sentinel();
342 } 344 }
343 345
344 virtual Statement* EmptyStatement() { 346 virtual Statement* EmptyStatement() {
345 return NULL; 347 return NULL;
346 } 348 }
347 349
348 template <typename T> ZoneListWrapper<T> NewList(int size) { 350 template <typename T> ZoneListWrapper<T> NewList(int size) {
349 return is_pre_parsing_ ? ZoneListWrapper<T>() : ZoneListWrapper<T>(size); 351 return is_pre_parsing_ ? ZoneListWrapper<T>() : ZoneListWrapper<T>(size);
350 } 352 }
(...skipping 29 matching lines...) Expand all
380 virtual Handle<String> EmptySymbol() { 382 virtual Handle<String> EmptySymbol() {
381 return Factory::empty_symbol(); 383 return Factory::empty_symbol();
382 } 384 }
383 385
384 virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) { 386 virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) {
385 return new Property(obj, key, pos); 387 return new Property(obj, key, pos);
386 } 388 }
387 389
388 virtual Expression* NewCall(Expression* expression, 390 virtual Expression* NewCall(Expression* expression,
389 ZoneList<Expression*>* arguments, 391 ZoneList<Expression*>* arguments,
390 bool is_eval, int pos) { 392 Call::EvalType eval_type, int pos) {
391 return new Call(expression, arguments, is_eval, pos); 393 return new Call(expression, arguments, eval_type, pos);
392 } 394 }
393 395
394 virtual Statement* EmptyStatement() { 396 virtual Statement* EmptyStatement() {
395 // Use a statically allocated empty statement singleton to avoid 397 // Use a statically allocated empty statement singleton to avoid
396 // allocating lots and lots of empty statements. 398 // allocating lots and lots of empty statements.
397 static v8::internal::EmptyStatement empty; 399 static v8::internal::EmptyStatement empty;
398 return &empty; 400 return &empty;
399 } 401 }
400 }; 402 };
401 403
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 result = factory()->NewProperty(result, index, pos); 2289 result = factory()->NewProperty(result, index, pos);
2288 Expect(Token::RBRACK, CHECK_OK); 2290 Expect(Token::RBRACK, CHECK_OK);
2289 break; 2291 break;
2290 } 2292 }
2291 2293
2292 case Token::LPAREN: { 2294 case Token::LPAREN: {
2293 int pos = scanner().location().beg_pos; 2295 int pos = scanner().location().beg_pos;
2294 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2296 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2295 2297
2296 // Keep track of eval() calls since they disable all local variable 2298 // Keep track of eval() calls since they disable all local variable
2297 // optimizations. We can ignore locally declared variables with 2299 // optimizations.
2298 // name 'eval' since they override the global 'eval' function. We 2300 // The calls that need special treatment are the
2299 // only need to look at unresolved variables (VariableProxies). 2301 // direct (i.e. not aliased) eval calls. These calls are all of the
2302 // form eval(...) with no explicit receiver object where eval is not
2303 // declared in the current scope chain. These calls are marked as
2304 // potentially direct eval calls. Whether they are actually direct calls
2305 // to eval is determined at run time.
2300 2306
2307 Call::EvalType eval_type = Call::ALIASED;
2301 if (!is_pre_parsing_) { 2308 if (!is_pre_parsing_) {
2302 // We assume that only a function called 'eval' can be used
2303 // to invoke the global eval() implementation. This permits
2304 // for massive optimizations.
2305 VariableProxy* callee = result->AsVariableProxy(); 2309 VariableProxy* callee = result->AsVariableProxy();
2306 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) { 2310 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) {
2307 // We do not allow direct calls to 'eval' in our internal 2311 Handle<String> name = callee->name();
2308 // JS files. Use builtin functions instead. 2312 Variable* var = NULL;
2309 ASSERT(!Bootstrapper::IsActive()); 2313 for (Scope* scope = top_scope_;
2310 top_scope_->RecordEvalCall(); 2314 scope != NULL;
2311 } else { 2315 scope = scope->outer_scope()) {
2312 // This is rather convoluted code to check if we're calling 2316 var = scope->Lookup(callee->name());
2313 // a function named 'eval' through a property access. If so, 2317 if (var != NULL) break;
2314 // we mark it as a possible eval call (we don't know if the 2318 }
2315 // receiver will resolve to the global object or not), but 2319 if (var == NULL) {
2316 // we do not treat the call as an eval() call - we let the 2320 // We do not allow direct calls to 'eval' in our internal
2317 // call get through to the JavaScript eval code defined in 2321 // JS files. Use builtin functions instead.
2318 // v8natives.js. 2322 ASSERT(!Bootstrapper::IsActive());
2319 Property* property = result->AsProperty(); 2323 top_scope_->RecordEvalCall();
2320 if (property != NULL) { 2324 eval_type = Call::POTENTIALLY_DIRECT;
2321 Literal* key = property->key()->AsLiteral();
2322 if (key != NULL &&
2323 key->handle().is_identical_to(Factory::eval_symbol())) {
2324 // We do not allow direct calls to 'eval' in our
2325 // internal JS files. Use builtin functions instead.
2326 ASSERT(!Bootstrapper::IsActive());
2327 top_scope_->RecordEvalCall();
2328 }
2329 } 2325 }
2330 } 2326 }
2331 } 2327 }
2332 2328
2333 // Optimize the eval() case w/o arguments so we 2329 // Optimize the eval() case w/o arguments so we
2334 // don't need to handle it every time at runtime. 2330 // don't need to handle it every time at runtime.
2335 // 2331 //
2336 // Note: For now we don't do static eval analysis 2332 // Note: For now we don't do static eval analysis
2337 // as it appears that we need to be able to call 2333 // as it appears that we need to be able to call
2338 // eval() via alias names. We leave the code as 2334 // eval() via alias names. We leave the code as
2339 // is, in case we want to enable this again in the 2335 // is, in case we want to enable this again in the
2340 // future. 2336 // future.
2341 const bool is_eval = false; 2337 const bool is_eval = false;
2342 if (is_eval && args->length() == 0) { 2338 if (is_eval && args->length() == 0) {
2343 result = NEW(Literal(Factory::undefined_value())); 2339 result = NEW(Literal(Factory::undefined_value()));
2344 } else { 2340 } else {
2345 result = factory()->NewCall(result, args, is_eval, pos); 2341 result = factory()->NewCall(result, args, eval_type, pos);
2346 } 2342 }
2347 break; 2343 break;
2348 } 2344 }
2349 2345
2350 case Token::PERIOD: { 2346 case Token::PERIOD: {
2351 Consume(Token::PERIOD); 2347 Consume(Token::PERIOD);
2352 int pos = scanner().location().beg_pos; 2348 int pos = scanner().location().beg_pos;
2353 Handle<String> name = ParseIdentifier(CHECK_OK); 2349 Handle<String> name = ParseIdentifier(CHECK_OK);
2354 result = factory()->NewProperty(result, NEW(Literal(name)), pos); 2350 result = factory()->NewProperty(result, NEW(Literal(name)), pos);
2355 break; 2351 break;
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 start_position, 3252 start_position,
3257 is_expression); 3253 is_expression);
3258 return result; 3254 return result;
3259 } 3255 }
3260 3256
3261 3257
3262 #undef NEW 3258 #undef NEW
3263 3259
3264 3260
3265 } } // namespace v8::internal 3261 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug-delay.js ('k') | src/runtime.h » ('j') | test/cctest/test-api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698