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() { private_->serializer.WriteHeader(); } |
| 2851 |
| 2852 Maybe<bool> ValueSerializer::WriteValue(Local<Context> context, |
| 2853 Local<Value> value) { |
| 2854 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueSerializer, WriteValue, bool); |
| 2855 i::Handle<i::Object> object = Utils::OpenHandle(*value); |
| 2856 Maybe<bool> result = private_->serializer.WriteObject(object); |
| 2857 if (result.IsNothing()) { |
| 2858 has_pending_exception = private_->isolate->has_pending_exception(); |
| 2859 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 2860 } |
| 2861 return result; |
| 2862 } |
| 2863 |
| 2864 std::vector<uint8_t> ValueSerializer::ReleaseBuffer() { |
| 2865 return private_->serializer.ReleaseBuffer(); |
| 2866 } |
| 2867 |
| 2868 struct ValueDeserializer::PrivateData { |
| 2869 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data) |
| 2870 : isolate(i), deserializer(i, data) {} |
| 2871 i::Isolate* isolate; |
| 2872 i::ValueDeserializer deserializer; |
| 2873 bool supports_legacy_wire_format = false; |
| 2874 }; |
| 2875 |
| 2876 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, |
| 2877 size_t size) { |
| 2878 if (base::IsValueInRangeForNumericType<int>(size)) { |
| 2879 private_ = |
| 2880 new PrivateData(reinterpret_cast<i::Isolate*>(isolate), |
| 2881 i::Vector<const uint8_t>(data, static_cast<int>(size))); |
| 2882 } else { |
| 2883 private_ = nullptr; |
| 2884 } |
| 2885 } |
| 2886 |
| 2887 ValueDeserializer::~ValueDeserializer() { delete private_; } |
| 2888 |
| 2889 Maybe<bool> ValueDeserializer::ReadHeader() { |
| 2890 // TODO(jbroman): Today, all wire formats are "legacy". When a more supported |
| 2891 // format is added, compare the version of the internal serializer to the |
| 2892 // minimum non-legacy version number. |
| 2893 if (!private_ || !private_->deserializer.ReadHeader().FromMaybe(false) || |
| 2894 !private_->supports_legacy_wire_format) { |
| 2895 delete private_; |
| 2896 private_ = nullptr; |
| 2897 return Nothing<bool>(); |
| 2898 } |
| 2899 return Just(true); |
| 2900 } |
| 2901 |
| 2902 void ValueDeserializer::SetSupportsLegacyWireFormat( |
| 2903 bool supports_legacy_wire_format) { |
| 2904 if (!private_) return; |
| 2905 private_->supports_legacy_wire_format = supports_legacy_wire_format; |
| 2906 } |
| 2907 |
| 2908 uint32_t ValueDeserializer::GetWireFormatVersion() const { |
| 2909 CHECK(private_); |
| 2910 return private_->deserializer.GetWireFormatVersion(); |
| 2911 } |
| 2912 |
| 2913 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { |
| 2914 CHECK(private_); |
| 2915 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); |
| 2916 i::MaybeHandle<i::Object> result; |
| 2917 if (GetWireFormatVersion() > 0) { |
| 2918 result = private_->deserializer.ReadObject(); |
| 2919 } else { |
| 2920 result = |
| 2921 private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat(); |
| 2922 } |
| 2923 Local<Value> value; |
| 2924 if (!ToLocal(result, &value)) { |
| 2925 has_pending_exception = private_->isolate->has_pending_exception(); |
| 2926 RETURN_ON_FAILED_EXECUTION(Value); |
| 2927 return MaybeLocal<Value>(); |
| 2928 } |
| 2929 RETURN_ESCAPED(value); |
| 2930 } |
| 2931 |
2835 // --- D a t a --- | 2932 // --- D a t a --- |
2836 | 2933 |
2837 bool Value::FullIsUndefined() const { | 2934 bool Value::FullIsUndefined() const { |
2838 i::Handle<i::Object> object = Utils::OpenHandle(this); | 2935 i::Handle<i::Object> object = Utils::OpenHandle(this); |
2839 bool result = false; | 2936 bool result = false; |
2840 if (!object->IsSmi()) { | 2937 if (!object->IsSmi()) { |
2841 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); | 2938 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); |
2842 } | 2939 } |
2843 DCHECK_EQ(result, QuickIsUndefined()); | 2940 DCHECK_EQ(result, QuickIsUndefined()); |
2844 return result; | 2941 return result; |
(...skipping 6143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8988 Address callback_address = | 9085 Address callback_address = |
8989 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9086 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8990 VMState<EXTERNAL> state(isolate); | 9087 VMState<EXTERNAL> state(isolate); |
8991 ExternalCallbackScope call_scope(isolate, callback_address); | 9088 ExternalCallbackScope call_scope(isolate, callback_address); |
8992 callback(info); | 9089 callback(info); |
8993 } | 9090 } |
8994 | 9091 |
8995 | 9092 |
8996 } // namespace internal | 9093 } // namespace internal |
8997 } // namespace v8 | 9094 } // namespace v8 |
OLD | NEW |