| OLD | NEW |
| 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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 i::Parser parser(&info, &parse_info); | 1018 i::Parser parser(&info, &parse_info); |
| 1019 parser.set_allow_arrow_functions(true); | 1019 parser.set_allow_arrow_functions(true); |
| 1020 parser.set_allow_classes(true); | 1020 parser.set_allow_classes(true); |
| 1021 parser.set_allow_harmony_scoping(true); | 1021 parser.set_allow_harmony_scoping(true); |
| 1022 info.MarkAsGlobal(); | 1022 info.MarkAsGlobal(); |
| 1023 parser.Parse(); | 1023 parser.Parse(); |
| 1024 CHECK(i::Rewriter::Rewrite(&info)); | 1024 CHECK(i::Rewriter::Rewrite(&info)); |
| 1025 CHECK(i::Scope::Analyze(&info)); | 1025 CHECK(i::Scope::Analyze(&info)); |
| 1026 CHECK(info.function() != NULL); | 1026 CHECK(info.function() != NULL); |
| 1027 | 1027 |
| 1028 i::Scope* global_scope = info.function()->scope(); | 1028 i::Scope* script_scope = info.function()->scope(); |
| 1029 CHECK(global_scope->is_global_scope()); | 1029 CHECK(script_scope->is_script_scope()); |
| 1030 CHECK_EQ(1, global_scope->inner_scopes()->length()); | 1030 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
| 1031 | 1031 |
| 1032 i::Scope* scope = global_scope->inner_scopes()->at(0); | 1032 i::Scope* scope = script_scope->inner_scopes()->at(0); |
| 1033 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, | 1033 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, |
| 1034 scope->uses_arguments()); | 1034 scope->uses_arguments()); |
| 1035 CHECK_EQ((source_data[i].expected & SUPER) != 0, scope->uses_super()); | 1035 CHECK_EQ((source_data[i].expected & SUPER) != 0, scope->uses_super()); |
| 1036 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); | 1036 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); |
| 1037 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, | 1037 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, |
| 1038 scope->inner_uses_arguments()); | 1038 scope->inner_uses_arguments()); |
| 1039 CHECK_EQ((source_data[i].expected & INNER_SUPER) != 0, | 1039 CHECK_EQ((source_data[i].expected & INNER_SUPER) != 0, |
| 1040 scope->inner_uses_super()); | 1040 scope->inner_uses_super()); |
| 1041 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0, | 1041 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0, |
| 1042 scope->inner_uses_this()); | 1042 scope->inner_uses_this()); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 parser.set_allow_lazy(true); | 1265 parser.set_allow_lazy(true); |
| 1266 parser.set_allow_harmony_scoping(true); | 1266 parser.set_allow_harmony_scoping(true); |
| 1267 parser.set_allow_arrow_functions(true); | 1267 parser.set_allow_arrow_functions(true); |
| 1268 info.MarkAsGlobal(); | 1268 info.MarkAsGlobal(); |
| 1269 info.SetStrictMode(source_data[i].strict_mode); | 1269 info.SetStrictMode(source_data[i].strict_mode); |
| 1270 parser.Parse(); | 1270 parser.Parse(); |
| 1271 CHECK(info.function() != NULL); | 1271 CHECK(info.function() != NULL); |
| 1272 | 1272 |
| 1273 // Check scope types and positions. | 1273 // Check scope types and positions. |
| 1274 i::Scope* scope = info.function()->scope(); | 1274 i::Scope* scope = info.function()->scope(); |
| 1275 CHECK(scope->is_global_scope()); | 1275 CHECK(scope->is_script_scope()); |
| 1276 CHECK_EQ(scope->start_position(), 0); | 1276 CHECK_EQ(scope->start_position(), 0); |
| 1277 CHECK_EQ(scope->end_position(), kProgramSize); | 1277 CHECK_EQ(scope->end_position(), kProgramSize); |
| 1278 CHECK_EQ(scope->inner_scopes()->length(), 1); | 1278 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 1279 | 1279 |
| 1280 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1280 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 1281 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); | 1281 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); |
| 1282 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1282 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
| 1283 // The end position of a token is one position after the last | 1283 // The end position of a token is one position after the last |
| 1284 // character belonging to that token. | 1284 // character belonging to that token. |
| 1285 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1285 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
| (...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3063 i::Zone zone(isolate); | 3063 i::Zone zone(isolate); |
| 3064 v8::Local<v8::Value> v = CompileRun(src); | 3064 v8::Local<v8::Value> v = CompileRun(src); |
| 3065 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3065 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
| 3066 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3066 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
| 3067 i::Context* context = f->context(); | 3067 i::Context* context = f->context(); |
| 3068 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); | 3068 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); |
| 3069 avf.Internalize(isolate); | 3069 avf.Internalize(isolate); |
| 3070 const i::AstRawString* name = avf.GetOneByteString("result"); | 3070 const i::AstRawString* name = avf.GetOneByteString("result"); |
| 3071 i::Handle<i::String> str = name->string(); | 3071 i::Handle<i::String> str = name->string(); |
| 3072 CHECK(str->IsInternalizedString()); | 3072 CHECK(str->IsInternalizedString()); |
| 3073 i::Scope* global_scope = | 3073 i::Scope* script_scope = |
| 3074 new (&zone) i::Scope(NULL, i::GLOBAL_SCOPE, &avf, &zone); | 3074 new (&zone) i::Scope(NULL, i::SCRIPT_SCOPE, &avf, &zone); |
| 3075 global_scope->Initialize(); | 3075 script_scope->Initialize(); |
| 3076 i::Scope* s = i::Scope::DeserializeScopeChain(context, global_scope, &zone); | 3076 i::Scope* s = i::Scope::DeserializeScopeChain(context, script_scope, &zone); |
| 3077 DCHECK(s != global_scope); | 3077 DCHECK(s != script_scope); |
| 3078 DCHECK(name != NULL); | 3078 DCHECK(name != NULL); |
| 3079 | 3079 |
| 3080 // Get result from h's function context (that is f's context) | 3080 // Get result from h's function context (that is f's context) |
| 3081 i::Variable* var = s->Lookup(name); | 3081 i::Variable* var = s->Lookup(name); |
| 3082 | 3082 |
| 3083 CHECK(var != NULL); | 3083 CHECK(var != NULL); |
| 3084 // Maybe assigned should survive deserialization | 3084 // Maybe assigned should survive deserialization |
| 3085 CHECK(var->maybe_assigned() == i::kMaybeAssigned); | 3085 CHECK(var->maybe_assigned() == i::kMaybeAssigned); |
| 3086 // TODO(sigurds) Figure out if is_used should survive context serialization. | 3086 // TODO(sigurds) Figure out if is_used should survive context serialization. |
| 3087 } | 3087 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3110 source->PrintOn(stdout); | 3110 source->PrintOn(stdout); |
| 3111 printf("\n"); | 3111 printf("\n"); |
| 3112 i::Zone zone(isolate); | 3112 i::Zone zone(isolate); |
| 3113 v8::Local<v8::Value> v = CompileRun(src); | 3113 v8::Local<v8::Value> v = CompileRun(src); |
| 3114 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3114 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
| 3115 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3115 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
| 3116 i::Context* context = f->context(); | 3116 i::Context* context = f->context(); |
| 3117 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); | 3117 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); |
| 3118 avf.Internalize(isolate); | 3118 avf.Internalize(isolate); |
| 3119 | 3119 |
| 3120 i::Scope* global_scope = | 3120 i::Scope* script_scope = |
| 3121 new (&zone) i::Scope(NULL, i::GLOBAL_SCOPE, &avf, &zone); | 3121 new (&zone) i::Scope(NULL, i::SCRIPT_SCOPE, &avf, &zone); |
| 3122 global_scope->Initialize(); | 3122 script_scope->Initialize(); |
| 3123 i::Scope* s = i::Scope::DeserializeScopeChain(context, global_scope, &zone); | 3123 i::Scope* s = i::Scope::DeserializeScopeChain(context, script_scope, &zone); |
| 3124 DCHECK(s != global_scope); | 3124 DCHECK(s != script_scope); |
| 3125 const i::AstRawString* name_x = avf.GetOneByteString("x"); | 3125 const i::AstRawString* name_x = avf.GetOneByteString("x"); |
| 3126 | 3126 |
| 3127 // Get result from f's function context (that is g's outer context) | 3127 // Get result from f's function context (that is g's outer context) |
| 3128 i::Variable* var_x = s->Lookup(name_x); | 3128 i::Variable* var_x = s->Lookup(name_x); |
| 3129 CHECK(var_x != NULL); | 3129 CHECK(var_x != NULL); |
| 3130 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); | 3130 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); |
| 3131 } | 3131 } |
| 3132 | 3132 |
| 3133 | 3133 |
| 3134 TEST(ExportsMaybeAssigned) { | 3134 TEST(ExportsMaybeAssigned) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3157 source->PrintOn(stdout); | 3157 source->PrintOn(stdout); |
| 3158 printf("\n"); | 3158 printf("\n"); |
| 3159 i::Zone zone(isolate); | 3159 i::Zone zone(isolate); |
| 3160 v8::Local<v8::Value> v = CompileRun(src); | 3160 v8::Local<v8::Value> v = CompileRun(src); |
| 3161 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3161 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
| 3162 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3162 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
| 3163 i::Context* context = f->context(); | 3163 i::Context* context = f->context(); |
| 3164 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); | 3164 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); |
| 3165 avf.Internalize(isolate); | 3165 avf.Internalize(isolate); |
| 3166 | 3166 |
| 3167 i::Scope* global_scope = | 3167 i::Scope* script_scope = |
| 3168 new (&zone) i::Scope(NULL, i::GLOBAL_SCOPE, &avf, &zone); | 3168 new (&zone) i::Scope(NULL, i::SCRIPT_SCOPE, &avf, &zone); |
| 3169 global_scope->Initialize(); | 3169 script_scope->Initialize(); |
| 3170 i::Scope* s = i::Scope::DeserializeScopeChain(context, global_scope, &zone); | 3170 i::Scope* s = i::Scope::DeserializeScopeChain(context, script_scope, &zone); |
| 3171 DCHECK(s != global_scope); | 3171 DCHECK(s != script_scope); |
| 3172 const i::AstRawString* name_x = avf.GetOneByteString("x"); | 3172 const i::AstRawString* name_x = avf.GetOneByteString("x"); |
| 3173 const i::AstRawString* name_f = avf.GetOneByteString("f"); | 3173 const i::AstRawString* name_f = avf.GetOneByteString("f"); |
| 3174 const i::AstRawString* name_y = avf.GetOneByteString("y"); | 3174 const i::AstRawString* name_y = avf.GetOneByteString("y"); |
| 3175 const i::AstRawString* name_B = avf.GetOneByteString("B"); | 3175 const i::AstRawString* name_B = avf.GetOneByteString("B"); |
| 3176 const i::AstRawString* name_C = avf.GetOneByteString("C"); | 3176 const i::AstRawString* name_C = avf.GetOneByteString("C"); |
| 3177 | 3177 |
| 3178 // Get result from h's function context (that is f's context) | 3178 // Get result from h's function context (that is f's context) |
| 3179 i::Variable* var_x = s->Lookup(name_x); | 3179 i::Variable* var_x = s->Lookup(name_x); |
| 3180 CHECK(var_x != NULL); | 3180 CHECK(var_x != NULL); |
| 3181 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); | 3181 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4311 const char* data[] = { | 4311 const char* data[] = { |
| 4312 "var foob\\u123r = 0;", | 4312 "var foob\\u123r = 0;", |
| 4313 "var \\u123roo = 0;", | 4313 "var \\u123roo = 0;", |
| 4314 "\"foob\\u123rr\"", | 4314 "\"foob\\u123rr\"", |
| 4315 // No escapes allowed in regexp flags | 4315 // No escapes allowed in regexp flags |
| 4316 "/regex/\\u0069g", | 4316 "/regex/\\u0069g", |
| 4317 "/regex/\\u006g", | 4317 "/regex/\\u006g", |
| 4318 NULL}; | 4318 NULL}; |
| 4319 RunParserSyncTest(context_data, data, kError); | 4319 RunParserSyncTest(context_data, data, kError); |
| 4320 } | 4320 } |
| OLD | NEW |