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

Unified Diff: src/ast/scopes.cc

Issue 1490783002: [bootstrapper] add checks for variable bindings in native scripts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index 1eb5b66a9377df597dca77325581b715479281c1..5817b13e763307dce041f172ecfdee4b322ccfed 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -308,14 +308,10 @@ bool Scope::Analyze(ParseInfo* info) {
}
#ifdef DEBUG
- bool native = info->isolate()->bootstrapper()->IsActive();
- if (!info->shared_info().is_null()) {
- Object* script = info->shared_info()->script();
- native = script->IsScript() &&
- Script::cast(script)->type() == Script::TYPE_NATIVE;
+ if (info->script_is_native() ? FLAG_print_builtin_scopes
+ : FLAG_print_scopes) {
+ scope->Print();
}
-
- if (native ? FLAG_print_builtin_scopes : FLAG_print_scopes) scope->Print();
#endif
info->set_scope(scope);
@@ -1161,6 +1157,22 @@ bool Scope::ResolveVariable(ParseInfo* info, VariableProxy* proxy,
// Otherwise, try to resolve the variable.
BindingKind binding_kind;
Variable* var = LookupRecursive(proxy, &binding_kind, factory);
+
+#ifdef DEBUG
+ if (info->script_is_native()) {
+ // To avoid polluting the global object in native scripts
+ // - Variables must not be allocated to the global scope.
+ CHECK_NOT_NULL(outer_scope());
+ // - Variables must be bound locally or unallocated.
+ CHECK_EQ(BOUND, binding_kind);
+ VariableLocation location = var->location();
+ CHECK(location == VariableLocation::LOCAL ||
+ location == VariableLocation::CONTEXT ||
+ location == VariableLocation::PARAMETER ||
+ location == VariableLocation::UNALLOCATED);
+ }
+#endif
+
switch (binding_kind) {
case BOUND:
// We found a variable binding.
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698