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

Side by Side Diff: src/compiler.h

Issue 12613007: Harden Function()'s parsing of function literals. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 years, 9 months 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
« no previous file with comments | « no previous file | src/compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 22 matching lines...) Expand all
33 #include "zone.h" 33 #include "zone.h"
34 34
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 static const int kPrologueOffsetNotSet = -1; 38 static const int kPrologueOffsetNotSet = -1;
39 39
40 class ScriptDataImpl; 40 class ScriptDataImpl;
41 class HydrogenCodeStub; 41 class HydrogenCodeStub;
42 42
43 // ParseRestriction is used to restrict the set of valid statements in a
44 // unit of compilation. Restriction violations cause a syntax error.
45 enum ParseRestriction {
46 NO_PARSE_RESTRICTION, // All expressions are allowed.
47 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
48 };
49
43 // CompilationInfo encapsulates some information known at compile time. It 50 // CompilationInfo encapsulates some information known at compile time. It
44 // is constructed based on the resources available at compile-time. 51 // is constructed based on the resources available at compile-time.
45 class CompilationInfo { 52 class CompilationInfo {
46 public: 53 public:
47 CompilationInfo(Handle<Script> script, Zone* zone); 54 CompilationInfo(Handle<Script> script, Zone* zone);
48 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); 55 CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone);
49 CompilationInfo(Handle<JSFunction> closure, Zone* zone); 56 CompilationInfo(Handle<JSFunction> closure, Zone* zone);
50 CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone); 57 CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone);
51 58
52 ~CompilationInfo(); 59 ~CompilationInfo();
53 60
54 Isolate* isolate() { 61 Isolate* isolate() {
55 ASSERT(Isolate::Current() == isolate_); 62 ASSERT(Isolate::Current() == isolate_);
56 return isolate_; 63 return isolate_;
57 } 64 }
58 Zone* zone() { 65 Zone* zone() { return zone_; }
59 return zone_;
60 }
61 bool is_lazy() const { return IsLazy::decode(flags_); } 66 bool is_lazy() const { return IsLazy::decode(flags_); }
62 bool is_eval() const { return IsEval::decode(flags_); } 67 bool is_eval() const { return IsEval::decode(flags_); }
63 bool is_global() const { return IsGlobal::decode(flags_); } 68 bool is_global() const { return IsGlobal::decode(flags_); }
64 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } 69 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; }
65 bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; } 70 bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; }
66 LanguageMode language_mode() const { 71 LanguageMode language_mode() const {
67 return LanguageModeField::decode(flags_); 72 return LanguageModeField::decode(flags_);
68 } 73 }
69 bool is_in_loop() const { return IsInLoop::decode(flags_); } 74 bool is_in_loop() const { return IsInLoop::decode(flags_); }
70 FunctionLiteral* function() const { return function_; } 75 FunctionLiteral* function() const { return function_; }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 136 }
132 137
133 void MarkAsSavesCallerDoubles() { 138 void MarkAsSavesCallerDoubles() {
134 flags_ |= SavesCallerDoubles::encode(true); 139 flags_ |= SavesCallerDoubles::encode(true);
135 } 140 }
136 141
137 bool saves_caller_doubles() const { 142 bool saves_caller_doubles() const {
138 return SavesCallerDoubles::decode(flags_); 143 return SavesCallerDoubles::decode(flags_);
139 } 144 }
140 145
146 void SetParseRestriction(ParseRestriction restriction) {
147 flags_ = ParseRestricitonField::update(flags_, restriction);
148 }
149
150 ParseRestriction parse_restriction() const {
151 return ParseRestricitonField::decode(flags_);
152 }
153
141 void SetFunction(FunctionLiteral* literal) { 154 void SetFunction(FunctionLiteral* literal) {
142 ASSERT(function_ == NULL); 155 ASSERT(function_ == NULL);
143 function_ = literal; 156 function_ = literal;
144 } 157 }
145 void SetScope(Scope* scope) { 158 void SetScope(Scope* scope) {
146 ASSERT(scope_ == NULL); 159 ASSERT(scope_ == NULL);
147 scope_ = scope; 160 scope_ = scope;
148 } 161 }
149 void SetGlobalScope(Scope* global_scope) { 162 void SetGlobalScope(Scope* global_scope) {
150 ASSERT(global_scope_ == NULL); 163 ASSERT(global_scope_ == NULL);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // initial mode setting. 291 // initial mode setting.
279 class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; 292 class IsCompilingForDebugging: public BitField<bool, 8, 1> {};
280 // If the compiled code contains calls that require building a frame 293 // If the compiled code contains calls that require building a frame
281 class IsCalling: public BitField<bool, 9, 1> {}; 294 class IsCalling: public BitField<bool, 9, 1> {};
282 // If the compiled code contains calls that require building a frame 295 // If the compiled code contains calls that require building a frame
283 class IsDeferredCalling: public BitField<bool, 10, 1> {}; 296 class IsDeferredCalling: public BitField<bool, 10, 1> {};
284 // If the compiled code contains calls that require building a frame 297 // If the compiled code contains calls that require building a frame
285 class IsNonDeferredCalling: public BitField<bool, 11, 1> {}; 298 class IsNonDeferredCalling: public BitField<bool, 11, 1> {};
286 // If the compiled code saves double caller registers that it clobbers. 299 // If the compiled code saves double caller registers that it clobbers.
287 class SavesCallerDoubles: public BitField<bool, 12, 1> {}; 300 class SavesCallerDoubles: public BitField<bool, 12, 1> {};
288 301 // If the set of valid statements is restricted.
302 class ParseRestricitonField: public BitField<ParseRestriction, 13, 1> {};
289 303
290 unsigned flags_; 304 unsigned flags_;
291 305
292 // Fields filled in by the compilation pipeline. 306 // Fields filled in by the compilation pipeline.
293 // AST filled in by the parser. 307 // AST filled in by the parser.
294 FunctionLiteral* function_; 308 FunctionLiteral* function_;
295 // The scope of the function literal as a convenience. Set to indicate 309 // The scope of the function literal as a convenience. Set to indicate
296 // that scopes have been analyzed. 310 // that scopes have been analyzed.
297 Scope* scope_; 311 Scope* scope_;
298 // The global scope provided as a convenience. 312 // The global scope provided as a convenience.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 v8::Extension* extension, 509 v8::Extension* extension,
496 ScriptDataImpl* pre_data, 510 ScriptDataImpl* pre_data,
497 Handle<Object> script_data, 511 Handle<Object> script_data,
498 NativesFlag is_natives_code); 512 NativesFlag is_natives_code);
499 513
500 // Compile a String source within a context for Eval. 514 // Compile a String source within a context for Eval.
501 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, 515 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source,
502 Handle<Context> context, 516 Handle<Context> context,
503 bool is_global, 517 bool is_global,
504 LanguageMode language_mode, 518 LanguageMode language_mode,
519 ParseRestriction restriction,
505 int scope_position); 520 int scope_position);
506 521
507 // Compile from function info (used for lazy compilation). Returns true on 522 // Compile from function info (used for lazy compilation). Returns true on
508 // success and false if the compilation resulted in a stack overflow. 523 // success and false if the compilation resulted in a stack overflow.
509 static bool CompileLazy(CompilationInfo* info); 524 static bool CompileLazy(CompilationInfo* info);
510 525
511 static void RecompileParallel(Handle<JSFunction> function); 526 static void RecompileParallel(Handle<JSFunction> function);
512 527
513 // Compile a shared function info object (the function is possibly lazily 528 // Compile a shared function info object (the function is possibly lazily
514 // compiled). 529 // compiled).
(...skipping 14 matching lines...) Expand all
529 544
530 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 545 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
531 CompilationInfo* info, 546 CompilationInfo* info,
532 Handle<SharedFunctionInfo> shared); 547 Handle<SharedFunctionInfo> shared);
533 }; 548 };
534 549
535 550
536 } } // namespace v8::internal 551 } } // namespace v8::internal
537 552
538 #endif // V8_COMPILER_H_ 553 #endif // V8_COMPILER_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698