OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
11 #include <cmath> // For isnan. | 11 #include <cmath> // For isnan. |
12 #include "include/v8-debug.h" | 12 #include "include/v8-debug.h" |
13 #include "include/v8-profiler.h" | 13 #include "include/v8-profiler.h" |
14 #include "include/v8-testing.h" | 14 #include "include/v8-testing.h" |
15 #include "src/api-natives.h" | 15 #include "src/api-natives.h" |
16 #include "src/assert-scope.h" | 16 #include "src/assert-scope.h" |
17 #include "src/background-parsing-task.h" | 17 #include "src/background-parsing-task.h" |
18 #include "src/base/functional.h" | 18 #include "src/base/functional.h" |
19 #include "src/base/platform/platform.h" | 19 #include "src/base/platform/platform.h" |
20 #include "src/base/platform/time.h" | 20 #include "src/base/platform/time.h" |
21 #include "src/base/utils/random-number-generator.h" | 21 #include "src/base/utils/random-number-generator.h" |
22 #include "src/bootstrapper.h" | 22 #include "src/bootstrapper.h" |
23 #include "src/code-stubs.h" | 23 #include "src/code-stubs.h" |
24 #include "src/compiler.h" | 24 #include "src/compiler.h" |
25 #include "src/contexts.h" | |
25 #include "src/conversions-inl.h" | 26 #include "src/conversions-inl.h" |
26 #include "src/counters.h" | 27 #include "src/counters.h" |
27 #include "src/cpu-profiler.h" | 28 #include "src/cpu-profiler.h" |
28 #include "src/debug.h" | 29 #include "src/debug.h" |
29 #include "src/deoptimizer.h" | 30 #include "src/deoptimizer.h" |
30 #include "src/execution.h" | 31 #include "src/execution.h" |
31 #include "src/global-handles.h" | 32 #include "src/global-handles.h" |
32 #include "src/heap-profiler.h" | 33 #include "src/heap-profiler.h" |
33 #include "src/heap-snapshot-generator-inl.h" | 34 #include "src/heap-snapshot-generator-inl.h" |
34 #include "src/icu_util.h" | 35 #include "src/icu_util.h" |
35 #include "src/json-parser.h" | 36 #include "src/json-parser.h" |
36 #include "src/messages.h" | 37 #include "src/messages.h" |
37 #include "src/natives.h" | 38 #include "src/natives.h" |
38 #include "src/parser.h" | 39 #include "src/parser.h" |
40 #include "src/pending-compilation-error-handler.h" | |
39 #include "src/profile-generator-inl.h" | 41 #include "src/profile-generator-inl.h" |
40 #include "src/property.h" | 42 #include "src/property.h" |
41 #include "src/property-details.h" | 43 #include "src/property-details.h" |
42 #include "src/prototype.h" | 44 #include "src/prototype.h" |
43 #include "src/runtime/runtime.h" | 45 #include "src/runtime/runtime.h" |
44 #include "src/runtime-profiler.h" | 46 #include "src/runtime-profiler.h" |
45 #include "src/sampler.h" | 47 #include "src/sampler.h" |
46 #include "src/scanner-character-streams.h" | 48 #include "src/scanner-character-streams.h" |
47 #include "src/simulator.h" | 49 #include "src/simulator.h" |
48 #include "src/snapshot.h" | 50 #include "src/snapshot.h" |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1483 ScriptCompiler::StreamedSource::GetCachedData() const { | 1485 ScriptCompiler::StreamedSource::GetCachedData() const { |
1484 return impl_->cached_data.get(); | 1486 return impl_->cached_data.get(); |
1485 } | 1487 } |
1486 | 1488 |
1487 | 1489 |
1488 Local<Script> UnboundScript::BindToCurrentContext() { | 1490 Local<Script> UnboundScript::BindToCurrentContext() { |
1489 i::Handle<i::HeapObject> obj = | 1491 i::Handle<i::HeapObject> obj = |
1490 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1492 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
1491 i::Handle<i::SharedFunctionInfo> | 1493 i::Handle<i::SharedFunctionInfo> |
1492 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); | 1494 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); |
1495 i::Isolate* isolate = obj->GetIsolate(); | |
1496 | |
1497 i::ScopeInfo* scope_info = function_info->scope_info(); | |
1498 i::Handle<i::JSReceiver> global(isolate->native_context()->global_object()); | |
1499 for (int i = 0; i < scope_info->StrongModeFreeVariableCount(); ++i) { | |
1500 i::Handle<i::Name> name(scope_info->StrongModeFreeVariableName(i)); | |
1501 Maybe<bool> has = i::JSReceiver::HasProperty(global, name); | |
1502 if (has.IsJust() && !has.FromJust()) { | |
1503 i::ScriptContextTable::LookupResult result; | |
Dmitry Lomov (no reviews)
2015/03/24 14:51:46
Maybe change order of lookup: lexicals trump globa
marja
2015/03/24 16:46:14
Done.
| |
1504 i::Handle<i::String> name_string( | |
1505 scope_info->StrongModeFreeVariableName(i)); | |
1506 i::Handle<i::ScriptContextTable> script_context_table( | |
1507 isolate->native_context()->script_context_table()); | |
1508 if (!i::ScriptContextTable::Lookup(script_context_table, name_string, | |
1509 &result)) { | |
1510 i::PendingCompilationErrorHandler pending_error_handler_; | |
1511 pending_error_handler_.ReportMessageAt( | |
1512 scope_info->StrongModeFreeVariableStartPosition(i), | |
1513 scope_info->StrongModeFreeVariableEndPosition(i), | |
1514 "strong_unbound_global", name_string, i::kReferenceError); | |
1515 i::Handle<i::Script> script(i::Script::cast(function_info->script())); | |
1516 pending_error_handler_.ThrowPendingError(isolate, script); | |
1517 isolate->ReportPendingMessages(); | |
1518 isolate->OptionalRescheduleException(true); | |
1519 return Local<Script>(); | |
1520 } | |
1521 } | |
1522 } | |
1493 i::Handle<i::JSFunction> function = | 1523 i::Handle<i::JSFunction> function = |
1494 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( | 1524 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( |
1495 function_info, obj->GetIsolate()->native_context()); | 1525 function_info, isolate->native_context()); |
1496 return ToApiHandle<Script>(function); | 1526 return ToApiHandle<Script>(function); |
1497 } | 1527 } |
1498 | 1528 |
1499 | 1529 |
1500 int UnboundScript::GetId() { | 1530 int UnboundScript::GetId() { |
1501 i::Handle<i::HeapObject> obj = | 1531 i::Handle<i::HeapObject> obj = |
1502 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1532 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
1503 i::Isolate* isolate = obj->GetIsolate(); | 1533 i::Isolate* isolate = obj->GetIsolate(); |
1504 LOG_API(isolate, "v8::UnboundScript::GetId"); | 1534 LOG_API(isolate, "v8::UnboundScript::GetId"); |
1505 i::HandleScope scope(isolate); | 1535 i::HandleScope scope(isolate); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1933 if (has_pending_exception) isolate->ReportPendingMessages(); | 1963 if (has_pending_exception) isolate->ReportPendingMessages(); |
1934 RETURN_ON_FAILED_EXECUTION(Script); | 1964 RETURN_ON_FAILED_EXECUTION(Script); |
1935 | 1965 |
1936 source->info->clear_script(); // because script goes out of scope. | 1966 source->info->clear_script(); // because script goes out of scope. |
1937 raw_result = *result; // TODO(titzer): use CloseAndEscape? | 1967 raw_result = *result; // TODO(titzer): use CloseAndEscape? |
1938 } | 1968 } |
1939 | 1969 |
1940 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | 1970 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
1941 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result); | 1971 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result); |
1942 if (generic.IsEmpty()) return Local<Script>(); | 1972 if (generic.IsEmpty()) return Local<Script>(); |
1943 RETURN_ESCAPED(generic->BindToCurrentContext()); | 1973 Local<Script> bound = generic->BindToCurrentContext(); |
1974 if (bound.IsEmpty()) return Local<Script>(); | |
1975 RETURN_ESCAPED(bound); | |
1944 } | 1976 } |
1945 | 1977 |
1946 | 1978 |
1947 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, | 1979 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, |
1948 StreamedSource* v8_source, | 1980 StreamedSource* v8_source, |
1949 Handle<String> full_source_string, | 1981 Handle<String> full_source_string, |
1950 const ScriptOrigin& origin) { | 1982 const ScriptOrigin& origin) { |
1951 auto context = v8_isolate->GetCurrentContext(); | 1983 auto context = v8_isolate->GetCurrentContext(); |
1952 RETURN_TO_LOCAL_UNCHECKED( | 1984 RETURN_TO_LOCAL_UNCHECKED( |
1953 Compile(context, v8_source, full_source_string, origin), Script); | 1985 Compile(context, v8_source, full_source_string, origin), Script); |
(...skipping 6062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8016 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8048 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8017 Address callback_address = | 8049 Address callback_address = |
8018 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8050 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8019 VMState<EXTERNAL> state(isolate); | 8051 VMState<EXTERNAL> state(isolate); |
8020 ExternalCallbackScope call_scope(isolate, callback_address); | 8052 ExternalCallbackScope call_scope(isolate, callback_address); |
8021 callback(info); | 8053 callback(info); |
8022 } | 8054 } |
8023 | 8055 |
8024 | 8056 |
8025 } } // namespace v8::internal | 8057 } } // namespace v8::internal |
OLD | NEW |