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 |
(...skipping 6124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6135 i::Handle<i::FixedArray>::cast(i_isolate->eternal_handles()->GetSingleton( | 6135 i::Handle<i::FixedArray>::cast(i_isolate->eternal_handles()->GetSingleton( |
6136 i::EternalHandles::DATE_CACHE_VERSION)); | 6136 i::EternalHandles::DATE_CACHE_VERSION)); |
6137 DCHECK_EQ(1, date_cache_version->length()); | 6137 DCHECK_EQ(1, date_cache_version->length()); |
6138 CHECK(date_cache_version->get(0)->IsSmi()); | 6138 CHECK(date_cache_version->get(0)->IsSmi()); |
6139 date_cache_version->set( | 6139 date_cache_version->set( |
6140 0, | 6140 0, |
6141 i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1)); | 6141 i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1)); |
6142 } | 6142 } |
6143 | 6143 |
6144 | 6144 |
6145 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { | |
6146 i::Isolate* isolate = i::Isolate::Current(); | |
6147 uint8_t flags_buf[5]; | |
6148 int num_flags = 0; | |
6149 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; | |
6150 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; | |
6151 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; | |
6152 if ((flags & RegExp::kSticky) != 0) flags_buf[num_flags++] = 'y'; | |
6153 if ((flags & RegExp::kUnicode) != 0) flags_buf[num_flags++] = 'u'; | |
6154 DCHECK(num_flags <= static_cast<int>(arraysize(flags_buf))); | |
6155 return isolate->factory()->InternalizeOneByteString( | |
6156 i::Vector<const uint8_t>(flags_buf, num_flags)); | |
6157 } | |
6158 | |
6159 | |
6160 MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context, | 6145 MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context, |
6161 Local<String> pattern, Flags flags) { | 6146 Local<String> pattern, Flags flags) { |
6162 PREPARE_FOR_EXECUTION(context, "RegExp::New", RegExp); | 6147 PREPARE_FOR_EXECUTION(context, "RegExp::New", RegExp); |
6163 Local<v8::RegExp> result; | 6148 Local<v8::RegExp> result; |
6164 has_pending_exception = !ToLocal<RegExp>( | 6149 has_pending_exception = |
6165 i::JSRegExp::New(Utils::OpenHandle(*pattern), RegExpFlagsToString(flags)), | 6150 !ToLocal<RegExp>(i::JSRegExp::New(Utils::OpenHandle(*pattern), |
6166 &result); | 6151 static_cast<i::JSRegExp::Flags>(flags)), |
| 6152 &result); |
6167 RETURN_ON_FAILED_EXECUTION(RegExp); | 6153 RETURN_ON_FAILED_EXECUTION(RegExp); |
6168 RETURN_ESCAPED(result); | 6154 RETURN_ESCAPED(result); |
6169 } | 6155 } |
6170 | 6156 |
6171 | 6157 |
6172 Local<v8::RegExp> v8::RegExp::New(Local<String> pattern, Flags flags) { | 6158 Local<v8::RegExp> v8::RegExp::New(Local<String> pattern, Flags flags) { |
6173 auto isolate = | 6159 auto isolate = |
6174 reinterpret_cast<Isolate*>(Utils::OpenHandle(*pattern)->GetIsolate()); | 6160 reinterpret_cast<Isolate*>(Utils::OpenHandle(*pattern)->GetIsolate()); |
6175 auto context = isolate->GetCurrentContext(); | 6161 auto context = isolate->GetCurrentContext(); |
6176 RETURN_TO_LOCAL_UNCHECKED(New(context, pattern, flags), RegExp); | 6162 RETURN_TO_LOCAL_UNCHECKED(New(context, pattern, flags), RegExp); |
6177 } | 6163 } |
6178 | 6164 |
6179 | 6165 |
6180 Local<v8::String> v8::RegExp::GetSource() const { | 6166 Local<v8::String> v8::RegExp::GetSource() const { |
6181 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); | 6167 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
6182 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); | 6168 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
6183 } | 6169 } |
6184 | 6170 |
6185 | 6171 |
6186 // Assert that the static flags cast in GetFlags is valid. | 6172 // Assert that the static flags cast in GetFlags is valid. |
6187 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ | 6173 #define REGEXP_FLAG_ASSERT_EQ(flag) \ |
6188 STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ | 6174 STATIC_ASSERT(static_cast<int>(v8::RegExp::flag) == \ |
6189 static_cast<int>(i::JSRegExp::internal_flag)) | 6175 static_cast<int>(i::JSRegExp::flag)) |
6190 REGEXP_FLAG_ASSERT_EQ(kNone, NONE); | 6176 REGEXP_FLAG_ASSERT_EQ(kNone); |
6191 REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); | 6177 REGEXP_FLAG_ASSERT_EQ(kGlobal); |
6192 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); | 6178 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase); |
6193 REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); | 6179 REGEXP_FLAG_ASSERT_EQ(kMultiline); |
6194 REGEXP_FLAG_ASSERT_EQ(kSticky, STICKY); | 6180 REGEXP_FLAG_ASSERT_EQ(kSticky); |
6195 REGEXP_FLAG_ASSERT_EQ(kUnicode, UNICODE_ESCAPES); | 6181 REGEXP_FLAG_ASSERT_EQ(kUnicode); |
6196 #undef REGEXP_FLAG_ASSERT_EQ | 6182 #undef REGEXP_FLAG_ASSERT_EQ |
6197 | 6183 |
6198 v8::RegExp::Flags v8::RegExp::GetFlags() const { | 6184 v8::RegExp::Flags v8::RegExp::GetFlags() const { |
6199 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); | 6185 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
6200 return static_cast<RegExp::Flags>(obj->GetFlags().value()); | 6186 return RegExp::Flags(static_cast<int>(obj->GetFlags())); |
6201 } | 6187 } |
6202 | 6188 |
6203 | 6189 |
6204 Local<v8::Array> v8::Array::New(Isolate* isolate, int length) { | 6190 Local<v8::Array> v8::Array::New(Isolate* isolate, int length) { |
6205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6191 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6206 LOG_API(i_isolate, "Array::New"); | 6192 LOG_API(i_isolate, "Array::New"); |
6207 ENTER_V8(i_isolate); | 6193 ENTER_V8(i_isolate); |
6208 int real_length = length > 0 ? length : 0; | 6194 int real_length = length > 0 ? length : 0; |
6209 i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length); | 6195 i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length); |
6210 i::Handle<i::Object> length_obj = | 6196 i::Handle<i::Object> length_obj = |
(...skipping 2322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8533 Address callback_address = | 8519 Address callback_address = |
8534 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8520 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8535 VMState<EXTERNAL> state(isolate); | 8521 VMState<EXTERNAL> state(isolate); |
8536 ExternalCallbackScope call_scope(isolate, callback_address); | 8522 ExternalCallbackScope call_scope(isolate, callback_address); |
8537 callback(info); | 8523 callback(info); |
8538 } | 8524 } |
8539 | 8525 |
8540 | 8526 |
8541 } // namespace internal | 8527 } // namespace internal |
8542 } // namespace v8 | 8528 } // namespace v8 |
OLD | NEW |