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 <limits> | 12 #include <limits> |
13 #include <vector> | 13 #include <vector> |
14 #include "include/v8-debug.h" | 14 #include "include/v8-debug.h" |
15 #include "include/v8-experimental.h" | 15 #include "include/v8-experimental.h" |
16 #include "include/v8-profiler.h" | 16 #include "include/v8-profiler.h" |
17 #include "include/v8-testing.h" | 17 #include "include/v8-testing.h" |
18 #include "include/v8-util.h" | 18 #include "include/v8-util.h" |
19 #include "src/accessors.h" | 19 #include "src/accessors.h" |
20 #include "src/api-experimental.h" | 20 #include "src/api-experimental.h" |
21 #include "src/api-natives.h" | 21 #include "src/api-natives.h" |
22 #include "src/assert-scope.h" | 22 #include "src/assert-scope.h" |
23 #include "src/background-parsing-task.h" | 23 #include "src/background-parsing-task.h" |
24 #include "src/base/functional.h" | 24 #include "src/base/functional.h" |
25 #include "src/base/platform/platform.h" | 25 #include "src/base/platform/platform.h" |
26 #include "src/base/platform/time.h" | 26 #include "src/base/platform/time.h" |
27 #include "src/base/safe_conversions.h" | |
27 #include "src/base/utils/random-number-generator.h" | 28 #include "src/base/utils/random-number-generator.h" |
28 #include "src/bootstrapper.h" | 29 #include "src/bootstrapper.h" |
29 #include "src/char-predicates-inl.h" | 30 #include "src/char-predicates-inl.h" |
30 #include "src/code-stubs.h" | 31 #include "src/code-stubs.h" |
31 #include "src/compiler.h" | 32 #include "src/compiler.h" |
32 #include "src/context-measure.h" | 33 #include "src/context-measure.h" |
33 #include "src/contexts.h" | 34 #include "src/contexts.h" |
34 #include "src/conversions-inl.h" | 35 #include "src/conversions-inl.h" |
35 #include "src/counters.h" | 36 #include "src/counters.h" |
36 #include "src/debug/debug.h" | 37 #include "src/debug/debug.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
61 #include "src/runtime/runtime.h" | 62 #include "src/runtime/runtime.h" |
62 #include "src/simulator.h" | 63 #include "src/simulator.h" |
63 #include "src/snapshot/code-serializer.h" | 64 #include "src/snapshot/code-serializer.h" |
64 #include "src/snapshot/natives.h" | 65 #include "src/snapshot/natives.h" |
65 #include "src/snapshot/snapshot.h" | 66 #include "src/snapshot/snapshot.h" |
66 #include "src/startup-data-util.h" | 67 #include "src/startup-data-util.h" |
67 #include "src/tracing/trace-event.h" | 68 #include "src/tracing/trace-event.h" |
68 #include "src/unicode-inl.h" | 69 #include "src/unicode-inl.h" |
69 #include "src/v8.h" | 70 #include "src/v8.h" |
70 #include "src/v8threads.h" | 71 #include "src/v8threads.h" |
72 #include "src/value-serializer.h" | |
71 #include "src/version.h" | 73 #include "src/version.h" |
72 #include "src/vm-state-inl.h" | 74 #include "src/vm-state-inl.h" |
73 #include "src/wasm/wasm-module.h" | 75 #include "src/wasm/wasm-module.h" |
74 | 76 |
75 namespace v8 { | 77 namespace v8 { |
76 | 78 |
77 #define LOG_API(isolate, class_name, function_name) \ | 79 #define LOG_API(isolate, class_name, function_name) \ |
78 i::RuntimeCallTimerScope _runtime_timer( \ | 80 i::RuntimeCallTimerScope _runtime_timer( \ |
79 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ | 81 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ |
80 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( \ | 82 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( \ |
(...skipping 2744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2825 .Stringify(object, replacer, gap_string) | 2827 .Stringify(object, replacer, gap_string) |
2826 .ToHandle(&maybe); | 2828 .ToHandle(&maybe); |
2827 RETURN_ON_FAILED_EXECUTION(String); | 2829 RETURN_ON_FAILED_EXECUTION(String); |
2828 Local<String> result; | 2830 Local<String> result; |
2829 has_pending_exception = | 2831 has_pending_exception = |
2830 !ToLocal<String>(i::Object::ToString(isolate, maybe), &result); | 2832 !ToLocal<String>(i::Object::ToString(isolate, maybe), &result); |
2831 RETURN_ON_FAILED_EXECUTION(String); | 2833 RETURN_ON_FAILED_EXECUTION(String); |
2832 RETURN_ESCAPED(result); | 2834 RETURN_ESCAPED(result); |
2833 } | 2835 } |
2834 | 2836 |
2837 // --- V a l u e S e r i a l i z a t i o n --- | |
2838 | |
2839 struct ValueSerializer::PrivateData { | |
2840 explicit PrivateData(i::Isolate* i) : isolate(i), serializer(i) {} | |
2841 i::Isolate* isolate; | |
2842 i::ValueSerializer serializer; | |
2843 }; | |
2844 | |
2845 ValueSerializer::ValueSerializer(Isolate* isolate) | |
2846 : private_(new PrivateData(reinterpret_cast<i::Isolate*>(isolate))) {} | |
2847 | |
2848 ValueSerializer::~ValueSerializer() { delete private_; } | |
2849 | |
2850 void ValueSerializer::WriteHeader() { | |
2851 CHECK(private_); | |
Jakob Kummerow
2016/08/24 17:41:04
What does this guard against? A future constructor
jbroman
2016/08/24 21:26:36
Fair enough, it's probably premature since there's
| |
2852 private_->serializer.WriteHeader(); | |
2853 } | |
2854 | |
2855 Maybe<bool> ValueSerializer::WriteValue(Local<Context> context, | |
2856 Local<Value> value) { | |
2857 CHECK(private_); | |
2858 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueSerializer, WriteValue, bool); | |
2859 i::Handle<i::Object> object = Utils::OpenHandle(*value); | |
2860 Maybe<bool> result = private_->serializer.WriteObject(object); | |
2861 if (result.IsNothing()) { | |
2862 has_pending_exception = private_->isolate->has_pending_exception(); | |
2863 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
2864 } | |
2865 return result; | |
2866 } | |
2867 | |
2868 std::vector<uint8_t> ValueSerializer::ReleaseBuffer() { | |
2869 CHECK(private_); | |
2870 return private_->serializer.ReleaseBuffer(); | |
2871 } | |
2872 | |
2873 struct ValueDeserializer::PrivateData { | |
2874 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data) | |
2875 : isolate(i), deserializer(i, data) {} | |
2876 i::Isolate* isolate; | |
2877 i::ValueDeserializer deserializer; | |
2878 bool supports_legacy_wire_format; | |
Jakob Kummerow
2016/08/24 17:41:03
How about initializing this?
jbroman
2016/08/24 21:26:36
Done.
| |
2879 }; | |
2880 | |
2881 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, | |
2882 size_t size) { | |
2883 if (base::IsValueInRangeForNumericType<int>(size)) { | |
2884 private_ = | |
2885 new PrivateData(reinterpret_cast<i::Isolate*>(isolate), | |
2886 i::Vector<const uint8_t>(data, static_cast<int>(size))); | |
2887 } | |
Jakob Kummerow
2016/08/24 17:41:04
how about: else { private_ = nullptr; } ?
jbroman
2016/08/24 21:26:36
Not one, but two uninitialized variables in one sm
| |
2888 } | |
2889 | |
2890 ValueDeserializer::~ValueDeserializer() { delete private_; } | |
2891 | |
2892 Maybe<bool> ValueDeserializer::ReadHeader() { | |
2893 // TODO(jbroman): Today, all wire formats are "legacy". When a more supported | |
2894 // format is added, compare the version of the internal serializer to the | |
2895 // minimum non-legacy version number. | |
2896 if (!private_ || !private_->deserializer.ReadHeader().FromMaybe(false) || | |
2897 !private_->supports_legacy_wire_format) { | |
2898 delete private_; | |
2899 private_ = nullptr; | |
2900 return Nothing<bool>(); | |
2901 } | |
2902 return Just(true); | |
2903 } | |
2904 | |
2905 void ValueDeserializer::SetSupportsLegacyWireFormat( | |
2906 bool supports_legacy_wire_format) { | |
2907 CHECK(private_); | |
Jakob Kummerow
2016/08/24 17:41:04
Presumably this needs to be called before ReadHead
jbroman
2016/08/24 21:26:36
Added a comment to clarify usage, and made it just
| |
2908 private_->supports_legacy_wire_format = supports_legacy_wire_format; | |
2909 } | |
2910 | |
2911 uint32_t ValueDeserializer::GetWireFormatVersion() const { | |
2912 CHECK(private_); | |
2913 return private_->deserializer.GetWireFormatVersion(); | |
2914 } | |
2915 | |
2916 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { | |
2917 CHECK(private_); | |
2918 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); | |
2919 i::MaybeHandle<i::Object> result; | |
2920 if (GetWireFormatVersion() > 0) { | |
2921 result = private_->deserializer.ReadObject(); | |
2922 } else { | |
2923 result = | |
2924 private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat(); | |
2925 } | |
2926 Local<Value> value; | |
2927 if (!ToLocal(result, &value)) { | |
2928 has_pending_exception = private_->isolate->has_pending_exception(); | |
2929 RETURN_ON_FAILED_EXECUTION(Value); | |
2930 return MaybeLocal<Value>(); | |
2931 } | |
2932 RETURN_ESCAPED(value); | |
2933 } | |
2934 | |
2835 // --- D a t a --- | 2935 // --- D a t a --- |
2836 | 2936 |
2837 bool Value::FullIsUndefined() const { | 2937 bool Value::FullIsUndefined() const { |
2838 i::Handle<i::Object> object = Utils::OpenHandle(this); | 2938 i::Handle<i::Object> object = Utils::OpenHandle(this); |
2839 bool result = false; | 2939 bool result = false; |
2840 if (!object->IsSmi()) { | 2940 if (!object->IsSmi()) { |
2841 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); | 2941 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); |
2842 } | 2942 } |
2843 DCHECK_EQ(result, QuickIsUndefined()); | 2943 DCHECK_EQ(result, QuickIsUndefined()); |
2844 return result; | 2944 return result; |
(...skipping 6143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8988 Address callback_address = | 9088 Address callback_address = |
8989 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9089 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8990 VMState<EXTERNAL> state(isolate); | 9090 VMState<EXTERNAL> state(isolate); |
8991 ExternalCallbackScope call_scope(isolate, callback_address); | 9091 ExternalCallbackScope call_scope(isolate, callback_address); |
8992 callback(info); | 9092 callback(info); |
8993 } | 9093 } |
8994 | 9094 |
8995 | 9095 |
8996 } // namespace internal | 9096 } // namespace internal |
8997 } // namespace v8 | 9097 } // namespace v8 |
OLD | NEW |