Commit 3a4846d2 authored by yangguo's avatar yangguo Committed by Commit bot

[bootstrapper] add checks for variable bindings in native scripts.

Native scripts must not accidentally pollute the global object.

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/1490783002

Cr-Commit-Position: refs/heads/master@{#32469}
parent 8c793fed
......@@ -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.
......
......@@ -3149,8 +3149,6 @@ Genesis::Genesis(Isolate* isolate,
InitializeGlobal(global_object, empty_function, context_type);
InitializeNormalizedMapCaches();
// TODO(yangguo): Find a way to prevent accidentially installing properties
// on the global object.
if (!InstallNatives(context_type)) return;
MakeFunctionInstancePrototypeWritable();
......
......@@ -1086,7 +1086,7 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
i::JSFunction::cast(*compiled_script)->shared()->script()))
: i::Handle<i::Script>(i::Script::cast(
i::SharedFunctionInfo::cast(*compiled_script)->script()));
script_object->set_type(i::Script::TYPE_NATIVE);
script_object->set_type(i::Script::TYPE_EXTENSION);
}
#endif // !V8_SHARED
......
......@@ -70,12 +70,6 @@ function MakeTime(hour, min, sec, ms) {
}
// ECMA 262 - 15.9.1.12
function TimeInYear(year) {
return DaysInYear(year) * msPerDay;
}
// Compute number of days given a year, month, date.
// Note that month and date can lie outside the normal range.
// For example:
......
......@@ -151,6 +151,10 @@ class ParseInfo {
context_ = Handle<Context>(*context_);
}
#ifdef DEBUG
bool script_is_native() { return script_->type() == Script::TYPE_NATIVE; }
#endif // DEBUG
private:
// Various configuration flags for parsing.
enum Flag {
......
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