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

Side by Side Diff: src/api.cc

Issue 1005063002: Strawman: check strong mode free variables against the global object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: arrow func param fix Created 5 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
« no previous file with comments | « no previous file | src/messages.js » ('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 // 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
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::String> name_string(scope_info->StrongModeFreeVariableName(i));
1501 i::ScriptContextTable::LookupResult result;
1502 i::Handle<i::ScriptContextTable> script_context_table(
1503 isolate->native_context()->script_context_table());
1504 if (!i::ScriptContextTable::Lookup(script_context_table, name_string,
1505 &result)) {
1506 i::Handle<i::Name> name(scope_info->StrongModeFreeVariableName(i));
1507 Maybe<bool> has = i::JSReceiver::HasProperty(global, name);
1508 if (has.IsJust() && !has.FromJust()) {
1509 i::PendingCompilationErrorHandler pending_error_handler_;
1510 pending_error_handler_.ReportMessageAt(
1511 scope_info->StrongModeFreeVariableStartPosition(i),
1512 scope_info->StrongModeFreeVariableEndPosition(i),
1513 "strong_unbound_global", name_string, i::kReferenceError);
1514 i::Handle<i::Script> script(i::Script::cast(function_info->script()));
1515 pending_error_handler_.ThrowPendingError(isolate, script);
1516 isolate->ReportPendingMessages();
1517 isolate->OptionalRescheduleException(true);
1518 return Local<Script>();
1519 }
1520 }
1521 }
1493 i::Handle<i::JSFunction> function = 1522 i::Handle<i::JSFunction> function =
1494 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( 1523 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
1495 function_info, obj->GetIsolate()->native_context()); 1524 function_info, isolate->native_context());
1496 return ToApiHandle<Script>(function); 1525 return ToApiHandle<Script>(function);
1497 } 1526 }
1498 1527
1499 1528
1500 int UnboundScript::GetId() { 1529 int UnboundScript::GetId() {
1501 i::Handle<i::HeapObject> obj = 1530 i::Handle<i::HeapObject> obj =
1502 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); 1531 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
1503 i::Isolate* isolate = obj->GetIsolate(); 1532 i::Isolate* isolate = obj->GetIsolate();
1504 LOG_API(isolate, "v8::UnboundScript::GetId"); 1533 LOG_API(isolate, "v8::UnboundScript::GetId");
1505 i::HandleScope scope(isolate); 1534 i::HandleScope scope(isolate);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 if (has_pending_exception) isolate->ReportPendingMessages(); 1962 if (has_pending_exception) isolate->ReportPendingMessages();
1934 RETURN_ON_FAILED_EXECUTION(Script); 1963 RETURN_ON_FAILED_EXECUTION(Script);
1935 1964
1936 source->info->clear_script(); // because script goes out of scope. 1965 source->info->clear_script(); // because script goes out of scope.
1937 raw_result = *result; // TODO(titzer): use CloseAndEscape? 1966 raw_result = *result; // TODO(titzer): use CloseAndEscape?
1938 } 1967 }
1939 1968
1940 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); 1969 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1941 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result); 1970 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
1942 if (generic.IsEmpty()) return Local<Script>(); 1971 if (generic.IsEmpty()) return Local<Script>();
1943 RETURN_ESCAPED(generic->BindToCurrentContext()); 1972 Local<Script> bound = generic->BindToCurrentContext();
1973 if (bound.IsEmpty()) return Local<Script>();
1974 RETURN_ESCAPED(bound);
1944 } 1975 }
1945 1976
1946 1977
1947 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, 1978 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
1948 StreamedSource* v8_source, 1979 StreamedSource* v8_source,
1949 Handle<String> full_source_string, 1980 Handle<String> full_source_string,
1950 const ScriptOrigin& origin) { 1981 const ScriptOrigin& origin) {
1951 auto context = v8_isolate->GetCurrentContext(); 1982 auto context = v8_isolate->GetCurrentContext();
1952 RETURN_TO_LOCAL_UNCHECKED( 1983 RETURN_TO_LOCAL_UNCHECKED(
1953 Compile(context, v8_source, full_source_string, origin), Script); 1984 Compile(context, v8_source, full_source_string, origin), Script);
(...skipping 6062 matching lines...) Expand 10 before | Expand all | Expand 10 after
8016 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8047 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8017 Address callback_address = 8048 Address callback_address =
8018 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8049 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8019 VMState<EXTERNAL> state(isolate); 8050 VMState<EXTERNAL> state(isolate);
8020 ExternalCallbackScope call_scope(isolate, callback_address); 8051 ExternalCallbackScope call_scope(isolate, callback_address);
8021 callback(info); 8052 callback(info);
8022 } 8053 }
8023 8054
8024 8055
8025 } } // namespace v8::internal 8056 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698