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

Side by Side Diff: src/api.cc

Issue 1040043002: ensure maybe results are checked in v8.h (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 | « include/v8.h ('k') | no next file » | 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
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 1668
1669 i::ScriptData* script_data = NULL; 1669 i::ScriptData* script_data = NULL;
1670 if (options == kConsumeParserCache || options == kConsumeCodeCache) { 1670 if (options == kConsumeParserCache || options == kConsumeCodeCache) {
1671 DCHECK(source->cached_data); 1671 DCHECK(source->cached_data);
1672 // ScriptData takes care of pointer-aligning the data. 1672 // ScriptData takes care of pointer-aligning the data.
1673 script_data = new i::ScriptData(source->cached_data->data, 1673 script_data = new i::ScriptData(source->cached_data->data,
1674 source->cached_data->length); 1674 source->cached_data->length);
1675 } 1675 }
1676 1676
1677 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); 1677 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string));
1678 i::SharedFunctionInfo* raw_result = NULL; 1678 i::Handle<i::SharedFunctionInfo> result;
1679 { i::HandleScope scope(isolate); 1679 {
1680 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); 1680 i::HistogramTimerScope total(isolate->counters()->compile_script(), true);
1681 i::Handle<i::Object> name_obj; 1681 i::Handle<i::Object> name_obj;
1682 i::Handle<i::Object> source_map_url; 1682 i::Handle<i::Object> source_map_url;
1683 int line_offset = 0; 1683 int line_offset = 0;
1684 int column_offset = 0; 1684 int column_offset = 0;
1685 bool is_embedder_debug_script = false; 1685 bool is_embedder_debug_script = false;
1686 bool is_shared_cross_origin = false; 1686 bool is_shared_cross_origin = false;
1687 if (!source->resource_name.IsEmpty()) { 1687 if (!source->resource_name.IsEmpty()) {
1688 name_obj = Utils::OpenHandle(*(source->resource_name)); 1688 name_obj = Utils::OpenHandle(*(source->resource_name));
1689 } 1689 }
1690 if (!source->resource_line_offset.IsEmpty()) { 1690 if (!source->resource_line_offset.IsEmpty()) {
1691 line_offset = static_cast<int>(source->resource_line_offset->Value()); 1691 line_offset = static_cast<int>(source->resource_line_offset->Value());
1692 } 1692 }
1693 if (!source->resource_column_offset.IsEmpty()) { 1693 if (!source->resource_column_offset.IsEmpty()) {
1694 column_offset = 1694 column_offset =
1695 static_cast<int>(source->resource_column_offset->Value()); 1695 static_cast<int>(source->resource_column_offset->Value());
1696 } 1696 }
1697 if (!source->resource_is_shared_cross_origin.IsEmpty()) { 1697 if (!source->resource_is_shared_cross_origin.IsEmpty()) {
1698 is_shared_cross_origin = 1698 is_shared_cross_origin =
1699 source->resource_is_shared_cross_origin->IsTrue(); 1699 source->resource_is_shared_cross_origin->IsTrue();
1700 } 1700 }
1701 if (!source->resource_is_embedder_debug_script.IsEmpty()) { 1701 if (!source->resource_is_embedder_debug_script.IsEmpty()) {
1702 is_embedder_debug_script = 1702 is_embedder_debug_script =
1703 source->resource_is_embedder_debug_script->IsTrue(); 1703 source->resource_is_embedder_debug_script->IsTrue();
1704 } 1704 }
1705 if (!source->source_map_url.IsEmpty()) { 1705 if (!source->source_map_url.IsEmpty()) {
1706 source_map_url = Utils::OpenHandle(*(source->source_map_url)); 1706 source_map_url = Utils::OpenHandle(*(source->source_map_url));
1707 } 1707 }
1708 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( 1708 result = i::Compiler::CompileScript(
1709 str, name_obj, line_offset, column_offset, is_embedder_debug_script, 1709 str, name_obj, line_offset, column_offset, is_embedder_debug_script,
1710 is_shared_cross_origin, source_map_url, isolate->native_context(), NULL, 1710 is_shared_cross_origin, source_map_url, isolate->native_context(), NULL,
1711 &script_data, options, i::NOT_NATIVES_CODE, is_module); 1711 &script_data, options, i::NOT_NATIVES_CODE, is_module);
1712 has_pending_exception = result.is_null(); 1712 has_pending_exception = result.is_null();
1713 if (has_pending_exception && script_data != NULL) { 1713 if (has_pending_exception && script_data != NULL) {
1714 // This case won't happen during normal operation; we have compiled 1714 // This case won't happen during normal operation; we have compiled
1715 // successfully and produced cached data, and but the second compilation 1715 // successfully and produced cached data, and but the second compilation
1716 // of the same source code fails. 1716 // of the same source code fails.
1717 delete script_data; 1717 delete script_data;
1718 script_data = NULL; 1718 script_data = NULL;
1719 } 1719 }
1720 RETURN_ON_FAILED_EXECUTION(UnboundScript); 1720 RETURN_ON_FAILED_EXECUTION(UnboundScript);
1721 raw_result = *result;
1722 1721
1723 if ((options == kProduceParserCache || options == kProduceCodeCache) && 1722 if ((options == kProduceParserCache || options == kProduceCodeCache) &&
1724 script_data != NULL) { 1723 script_data != NULL) {
1725 // script_data now contains the data that was generated. source will 1724 // script_data now contains the data that was generated. source will
1726 // take the ownership. 1725 // take the ownership.
1727 source->cached_data = new CachedData( 1726 source->cached_data = new CachedData(
1728 script_data->data(), script_data->length(), CachedData::BufferOwned); 1727 script_data->data(), script_data->length(), CachedData::BufferOwned);
1729 script_data->ReleaseDataOwnership(); 1728 script_data->ReleaseDataOwnership();
1730 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) { 1729 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) {
1731 source->cached_data->rejected = script_data->rejected(); 1730 source->cached_data->rejected = script_data->rejected();
1732 } 1731 }
1733 delete script_data; 1732 delete script_data;
1734 } 1733 }
1735 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1736 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); 1734 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
1737 } 1735 }
1738 1736
1739 1737
1740 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript( 1738 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript(
1741 Isolate* v8_isolate, Source* source, CompileOptions options) { 1739 Isolate* v8_isolate, Source* source, CompileOptions options) {
1742 return CompileUnboundInternal(v8_isolate, source, options, false); 1740 return CompileUnboundInternal(v8_isolate, source, options, false);
1743 } 1741 }
1744 1742
1745 1743
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 i::FLAG_stack_size, isolate); 1922 i::FLAG_stack_size, isolate);
1925 } 1923 }
1926 1924
1927 1925
1928 MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context, 1926 MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
1929 StreamedSource* v8_source, 1927 StreamedSource* v8_source,
1930 Handle<String> full_source_string, 1928 Handle<String> full_source_string,
1931 const ScriptOrigin& origin) { 1929 const ScriptOrigin& origin) {
1932 PREPARE_FOR_EXECUTION(context, "v8::ScriptCompiler::Compile()", Script); 1930 PREPARE_FOR_EXECUTION(context, "v8::ScriptCompiler::Compile()", Script);
1933 i::StreamedSource* source = v8_source->impl(); 1931 i::StreamedSource* source = v8_source->impl();
1934 i::SharedFunctionInfo* raw_result = nullptr; 1932 i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
1935 { 1933 i::Handle<i::Script> script = isolate->factory()->NewScript(str);
1936 i::HandleScope scope(isolate); 1934 if (!origin.ResourceName().IsEmpty()) {
1937 i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string)); 1935 script->set_name(*Utils::OpenHandle(*(origin.ResourceName())));
1938 i::Handle<i::Script> script = isolate->factory()->NewScript(str); 1936 }
1939 if (!origin.ResourceName().IsEmpty()) { 1937 if (!origin.ResourceLineOffset().IsEmpty()) {
1940 script->set_name(*Utils::OpenHandle(*(origin.ResourceName()))); 1938 script->set_line_offset(i::Smi::FromInt(
1941 } 1939 static_cast<int>(origin.ResourceLineOffset()->Value())));
1942 if (!origin.ResourceLineOffset().IsEmpty()) { 1940 }
1943 script->set_line_offset(i::Smi::FromInt( 1941 if (!origin.ResourceColumnOffset().IsEmpty()) {
1944 static_cast<int>(origin.ResourceLineOffset()->Value()))); 1942 script->set_column_offset(i::Smi::FromInt(
1945 } 1943 static_cast<int>(origin.ResourceColumnOffset()->Value())));
1946 if (!origin.ResourceColumnOffset().IsEmpty()) { 1944 }
1947 script->set_column_offset(i::Smi::FromInt( 1945 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) {
1948 static_cast<int>(origin.ResourceColumnOffset()->Value()))); 1946 script->set_is_shared_cross_origin(
1949 } 1947 origin.ResourceIsSharedCrossOrigin()->IsTrue());
1950 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { 1948 }
1951 script->set_is_shared_cross_origin( 1949 if (!origin.ResourceIsEmbedderDebugScript().IsEmpty()) {
1952 origin.ResourceIsSharedCrossOrigin()->IsTrue()); 1950 script->set_is_embedder_debug_script(
1953 } 1951 origin.ResourceIsEmbedderDebugScript()->IsTrue());
1954 if (!origin.ResourceIsEmbedderDebugScript().IsEmpty()) { 1952 }
1955 script->set_is_embedder_debug_script( 1953 if (!origin.SourceMapUrl().IsEmpty()) {
1956 origin.ResourceIsEmbedderDebugScript()->IsTrue()); 1954 script->set_source_mapping_url(
1957 } 1955 *Utils::OpenHandle(*(origin.SourceMapUrl())));
1958 if (!origin.SourceMapUrl().IsEmpty()) {
1959 script->set_source_mapping_url(
1960 *Utils::OpenHandle(*(origin.SourceMapUrl())));
1961 }
1962
1963 source->info->set_script(script);
1964 source->info->set_context(isolate->native_context());
1965
1966 // Do the parsing tasks which need to be done on the main thread. This will
1967 // also handle parse errors.
1968 source->parser->Internalize(isolate, script,
1969 source->info->function() == nullptr);
1970 source->parser->HandleSourceURLComments(isolate, script);
1971
1972 i::Handle<i::SharedFunctionInfo> result;
1973 if (source->info->function() != nullptr) {
1974 // Parsing has succeeded.
1975 result = i::Compiler::CompileStreamedScript(script, source->info.get(),
1976 str->length());
1977 }
1978 has_pending_exception = result.is_null();
1979 if (has_pending_exception) isolate->ReportPendingMessages();
1980 RETURN_ON_FAILED_EXECUTION(Script);
1981
1982 source->info->clear_script(); // because script goes out of scope.
1983 raw_result = *result; // TODO(titzer): use CloseAndEscape?
1984 } 1956 }
1985 1957
1986 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); 1958 source->info->set_script(script);
1959 source->info->set_context(isolate->native_context());
1960
1961 // Do the parsing tasks which need to be done on the main thread. This will
1962 // also handle parse errors.
1963 source->parser->Internalize(isolate, script,
1964 source->info->function() == nullptr);
1965 source->parser->HandleSourceURLComments(isolate, script);
1966
1967 i::Handle<i::SharedFunctionInfo> result;
1968 if (source->info->function() != nullptr) {
1969 // Parsing has succeeded.
1970 result = i::Compiler::CompileStreamedScript(script, source->info.get(),
1971 str->length());
1972 }
1973 has_pending_exception = result.is_null();
1974 if (has_pending_exception) isolate->ReportPendingMessages();
1975 RETURN_ON_FAILED_EXECUTION(Script);
1976
1977 source->info->clear_script(); // because script goes out of scope.
1978
1987 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result); 1979 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
1988 if (generic.IsEmpty()) return Local<Script>(); 1980 if (generic.IsEmpty()) return Local<Script>();
1989 Local<Script> bound = generic->BindToCurrentContext(); 1981 Local<Script> bound = generic->BindToCurrentContext();
1990 if (bound.IsEmpty()) return Local<Script>(); 1982 if (bound.IsEmpty()) return Local<Script>();
1991 RETURN_ESCAPED(bound); 1983 RETURN_ESCAPED(bound);
1992 } 1984 }
1993 1985
1994 1986
1995 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, 1987 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
1996 StreamedSource* v8_source, 1988 StreamedSource* v8_source,
(...skipping 4251 matching lines...) Expand 10 before | Expand all | Expand 10 after
6248 isolate->factory()->undefined_value(), 6240 isolate->factory()->undefined_value(),
6249 arraysize(argv), argv, 6241 arraysize(argv), argv,
6250 false).is_null(); 6242 false).is_null();
6251 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 6243 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
6252 return Just(true); 6244 return Just(true);
6253 } 6245 }
6254 6246
6255 6247
6256 void Promise::Resolver::Resolve(Handle<Value> value) { 6248 void Promise::Resolver::Resolve(Handle<Value> value) {
6257 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 6249 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
6258 Resolve(context, value); 6250 USE(Resolve(context, value));
6259 } 6251 }
6260 6252
6261 6253
6262 Maybe<bool> Promise::Resolver::Reject(Local<Context> context, 6254 Maybe<bool> Promise::Resolver::Reject(Local<Context> context,
6263 Handle<Value> value) { 6255 Handle<Value> value) {
6264 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Promise::Resolver::Resolve", bool); 6256 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Promise::Resolver::Resolve", bool);
6265 auto self = Utils::OpenHandle(this); 6257 auto self = Utils::OpenHandle(this);
6266 i::Handle<i::Object> argv[] = {self, Utils::OpenHandle(*value)}; 6258 i::Handle<i::Object> argv[] = {self, Utils::OpenHandle(*value)};
6267 has_pending_exception = i::Execution::Call( 6259 has_pending_exception = i::Execution::Call(
6268 isolate, 6260 isolate,
6269 isolate->promise_reject(), 6261 isolate->promise_reject(),
6270 isolate->factory()->undefined_value(), 6262 isolate->factory()->undefined_value(),
6271 arraysize(argv), argv, 6263 arraysize(argv), argv,
6272 false).is_null(); 6264 false).is_null();
6273 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 6265 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
6274 return Just(true); 6266 return Just(true);
6275 } 6267 }
6276 6268
6277 6269
6278 void Promise::Resolver::Reject(Handle<Value> value) { 6270 void Promise::Resolver::Reject(Handle<Value> value) {
6279 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 6271 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
6280 Reject(context, value); 6272 USE(Reject(context, value));
6281 } 6273 }
6282 6274
6283 6275
6284 MaybeLocal<Promise> Promise::Chain(Local<Context> context, 6276 MaybeLocal<Promise> Promise::Chain(Local<Context> context,
6285 Handle<Function> handler) { 6277 Handle<Function> handler) {
6286 PREPARE_FOR_EXECUTION(context, "Promise::Chain", Promise); 6278 PREPARE_FOR_EXECUTION(context, "Promise::Chain", Promise);
6287 auto self = Utils::OpenHandle(this); 6279 auto self = Utils::OpenHandle(this);
6288 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*handler)}; 6280 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*handler)};
6289 i::Handle<i::Object> result; 6281 i::Handle<i::Object> result;
6290 has_pending_exception = 6282 has_pending_exception =
(...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
8062 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8054 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8063 Address callback_address = 8055 Address callback_address =
8064 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8056 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8065 VMState<EXTERNAL> state(isolate); 8057 VMState<EXTERNAL> state(isolate);
8066 ExternalCallbackScope call_scope(isolate, callback_address); 8058 ExternalCallbackScope call_scope(isolate, callback_address);
8067 callback(info); 8059 callback(info);
8068 } 8060 }
8069 8061
8070 8062
8071 } } // namespace v8::internal 8063 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698