| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 925b29f commit 5a9e795
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ | |||
| 11 | 11 | #define V8_MAJOR_VERSION 4 | |
| 12 | 12 | #define V8_MINOR_VERSION 5 | |
| 13 | 13 | #define V8_BUILD_NUMBER 103 | |
| 14 | - #define V8_PATCH_LEVEL 33 | ||
| 14 | + #define V8_PATCH_LEVEL 35 | ||
| 15 | 15 | ||
| 16 | 16 | // Use 1 for candidates and 0 otherwise. | |
| 17 | 17 | // (Boolean macro values are not supported by all preprocessors.) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -173,6 +173,7 @@ class CallSite { | |||
| 173 | 173 | T(ObserveCallbackFrozen, \ | |
| 174 | 174 | "Object.observe cannot deliver to a frozen function object") \ | |
| 175 | 175 | T(ObserveGlobalProxy, "% cannot be called on the global proxy object") \ | |
| 176 | + T(ObserveAccessChecked, "% cannot be called on access-checked objects") \ | ||
| 176 | 177 | T(ObserveInvalidAccept, \ | |
| 177 | 178 | "Third argument to Object.observe must be an array of strings.") \ | |
| 178 | 179 | T(ObserveNonFunction, "Object.% cannot deliver to non-function") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -389,6 +389,8 @@ function ObjectObserve(object, callback, acceptList) { | |||
| 389 | 389 | throw MakeTypeError(kObserveNonObject, "observe", "observe"); | |
| 390 | 390 | if (%IsJSGlobalProxy(object)) | |
| 391 | 391 | throw MakeTypeError(kObserveGlobalProxy, "observe"); | |
| 392 | + if (%IsAccessCheckNeeded(object)) | ||
| 393 | + throw MakeTypeError(kObserveAccessChecked, "observe"); | ||
| 392 | 394 | if (!IS_SPEC_FUNCTION(callback)) | |
| 393 | 395 | throw MakeTypeError(kObserveNonFunction, "observe"); | |
| 394 | 396 | if (ObjectIsFrozen(callback)) | |
@@ -617,6 +619,8 @@ function ObjectGetNotifier(object) { | |||
| 617 | 619 | throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier"); | |
| 618 | 620 | if (%IsJSGlobalProxy(object)) | |
| 619 | 621 | throw MakeTypeError(kObserveGlobalProxy, "getNotifier"); | |
| 622 | + if (%IsAccessCheckNeeded(object)) | ||
| 623 | + throw MakeTypeError(kObserveAccessChecked, "getNotifier"); | ||
| 620 | 624 | ||
| 621 | 625 | if (ObjectIsFrozen(object)) return null; | |
| 622 | 626 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1435,5 +1435,13 @@ RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) { | |||
| 1435 | 1435 | setter, attrs)); | |
| 1436 | 1436 | return isolate->heap()->undefined_value(); | |
| 1437 | 1437 | } | |
| 1438 | + | ||
| 1439 | + | ||
| 1440 | + RUNTIME_FUNCTION(Runtime_IsAccessCheckNeeded) { | ||
| 1441 | + SealHandleScope shs(isolate); | ||
| 1442 | + DCHECK_EQ(1, args.length()); | ||
| 1443 | + CONVERT_ARG_CHECKED(Object, object, 0); | ||
| 1444 | + return isolate->heap()->ToBoolean(object->IsAccessCheckNeeded()); | ||
| 1445 | + } | ||
| 1438 | 1446 | } // namespace internal | |
| 1439 | 1447 | } // namespace v8 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -483,7 +483,8 @@ namespace internal { | |||
| 483 | 483 | F(IsStrong, 1, 1) \ | |
| 484 | 484 | F(ClassOf, 1, 1) \ | |
| 485 | 485 | F(DefineGetterPropertyUnchecked, 4, 1) \ | |
| 486 | - F(DefineSetterPropertyUnchecked, 4, 1) | ||
| 486 | + F(DefineSetterPropertyUnchecked, 4, 1) \ | ||
| 487 | + F(IsAccessCheckNeeded, 1, 1) | ||
| 487 | 488 | ||
| 488 | 489 | ||
| 489 | 490 | #define FOR_EACH_INTRINSIC_OBSERVE(F) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,6 +346,7 @@ size_t ExternalStreamingStream::FillBuffer(size_t position) { | |||
| 346 | 346 | current_data_length_ = source_stream_->GetMoreData(¤t_data_); | |
| 347 | 347 | current_data_offset_ = 0; | |
| 348 | 348 | bool data_ends = current_data_length_ == 0; | |
| 349 | + bookmark_data_is_from_current_data_ = false; | ||
| 349 | 350 | ||
| 350 | 351 | // A caveat: a data chunk might end with bytes from an incomplete UTF-8 | |
| 351 | 352 | // character (the rest of the bytes will be in the next chunk). | |
@@ -405,6 +406,15 @@ bool ExternalStreamingStream::SetBookmark() { | |||
| 405 | 406 | // - buffer_[buffer_cursor_ .. buffer_end_] => bookmark_buffer_ | |
| 406 | 407 | // - current_data_[.._offset_ .. .._length_] => bookmark_data_ | |
| 407 | 408 | // - utf8_split_char_buffer_* => bookmark_utf8_split... | |
| 409 | + // | ||
| 410 | + // To make sure we don't unnecessarily copy data, we also maintain | ||
| 411 | + // whether bookmark_data_ contains a copy of the current current_data_ | ||
| 412 | + // block. This is done with: | ||
| 413 | + // - bookmark_data_is_from_current_data_ | ||
| 414 | + // - bookmark_data_offset_: offset into bookmark_data_ | ||
| 415 | + // | ||
| 416 | + // Note that bookmark_data_is_from_current_data_ must be maintained | ||
| 417 | + // whenever current_data_ is updated. | ||
| 408 | 418 | ||
| 409 | 419 | bookmark_ = pos_; | |
| 410 | 420 | ||
@@ -414,10 +424,21 @@ bool ExternalStreamingStream::SetBookmark() { | |||
| 414 | 424 | CopyCharsUnsigned(bookmark_buffer_.start(), buffer_cursor_, buffer_length); | |
| 415 | 425 | ||
| 416 | 426 | size_t data_length = current_data_length_ - current_data_offset_; | |
| 417 | - bookmark_data_.Dispose(); | ||
| 418 | - bookmark_data_ = Vector<uint8_t>::New(static_cast<int>(data_length)); | ||
| 419 | - CopyBytes(bookmark_data_.start(), current_data_ + current_data_offset_, | ||
| 420 | - data_length); | ||
| 427 | + size_t bookmark_data_length = static_cast<size_t>(bookmark_data_.length()); | ||
| 428 | + if (bookmark_data_is_from_current_data_ && | ||
| 429 | + data_length < bookmark_data_length) { | ||
| 430 | + // Fast case: bookmark_data_ was previously copied from the current | ||
| 431 | + // data block, and we have enough data for this bookmark. | ||
| 432 | + bookmark_data_offset_ = bookmark_data_length - data_length; | ||
| 433 | + } else { | ||
| 434 | + // Slow case: We need to copy current_data_. | ||
| 435 | + bookmark_data_.Dispose(); | ||
| 436 | + bookmark_data_ = Vector<uint8_t>::New(static_cast<int>(data_length)); | ||
| 437 | + CopyBytes(bookmark_data_.start(), current_data_ + current_data_offset_, | ||
| 438 | + data_length); | ||
| 439 | + bookmark_data_is_from_current_data_ = true; | ||
| 440 | + bookmark_data_offset_ = 0; | ||
| 441 | + } | ||
| 421 | 442 | ||
| 422 | 443 | bookmark_utf8_split_char_buffer_length_ = utf8_split_char_buffer_length_; | |
| 423 | 444 | for (size_t i = 0; i < utf8_split_char_buffer_length_; i++) { | |
@@ -436,12 +457,14 @@ void ExternalStreamingStream::ResetToBookmark() { | |||
| 436 | 457 | ||
| 437 | 458 | // bookmark_data_* => current_data_* | |
| 438 | 459 | // (current_data_ assumes ownership of its memory.) | |
| 439 | - uint8_t* data = new uint8_t[bookmark_data_.length()]; | ||
| 440 | 460 | current_data_offset_ = 0; | |
| 441 | - current_data_length_ = bookmark_data_.length(); | ||
| 442 | - CopyCharsUnsigned(data, bookmark_data_.begin(), bookmark_data_.length()); | ||
| 461 | + current_data_length_ = bookmark_data_.length() - bookmark_data_offset_; | ||
| 462 | + uint8_t* data = new uint8_t[current_data_length_]; | ||
| 463 | + CopyCharsUnsigned(data, bookmark_data_.begin() + bookmark_data_offset_, | ||
| 464 | + current_data_length_); | ||
| 443 | 465 | delete[] current_data_; | |
| 444 | 466 | current_data_ = data; | |
| 467 | + bookmark_data_is_from_current_data_ = true; | ||
| 445 | 468 | ||
| 446 | 469 | // bookmark_buffer_ needs to be copied to buffer_. | |
| 447 | 470 | CopyCharsUnsigned(buffer_, bookmark_buffer_.begin(), | |
@@ -462,6 +485,7 @@ void ExternalStreamingStream::FlushCurrent() { | |||
| 462 | 485 | current_data_ = NULL; | |
| 463 | 486 | current_data_length_ = 0; | |
| 464 | 487 | current_data_offset_ = 0; | |
| 488 | + bookmark_data_is_from_current_data_ = false; | ||
| 465 | 489 | } | |
| 466 | 490 | ||
| 467 | 491 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,6 +94,8 @@ class ExternalStreamingStream : public BufferedUtf16CharacterStream { | |||
| 94 | 94 | current_data_length_(0), | |
| 95 | 95 | utf8_split_char_buffer_length_(0), | |
| 96 | 96 | bookmark_(0), | |
| 97 | + bookmark_data_is_from_current_data_(false), | ||
| 98 | + bookmark_data_offset_(0), | ||
| 97 | 99 | bookmark_utf8_split_char_buffer_length_(0) {} | |
| 98 | 100 | ||
| 99 | 101 | virtual ~ExternalStreamingStream() { | |
@@ -134,6 +136,8 @@ class ExternalStreamingStream : public BufferedUtf16CharacterStream { | |||
| 134 | 136 | size_t bookmark_; | |
| 135 | 137 | Vector<uint16_t> bookmark_buffer_; | |
| 136 | 138 | Vector<uint8_t> bookmark_data_; | |
| 139 | + bool bookmark_data_is_from_current_data_; | ||
| 140 | + size_t bookmark_data_offset_; | ||
| 137 | 141 | uint8_t bookmark_utf8_split_char_buffer_[4]; | |
| 138 | 142 | size_t bookmark_utf8_split_char_buffer_length_; | |
| 139 | 143 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -885,3 +885,39 @@ TEST(UseCountObjectGetNotifier) { | |||
| 885 | 885 | CompileRun("Object.getNotifier(obj)"); | |
| 886 | 886 | CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]); | |
| 887 | 887 | } | |
| 888 | + | ||
| 889 | + | ||
| 890 | + static bool NamedAccessCheckAlwaysAllow(Local<v8::Object> global, | ||
| 891 | + Local<v8::Value> name, | ||
| 892 | + v8::AccessType type, | ||
| 893 | + Local<Value> data) { | ||
| 894 | + return true; | ||
| 895 | + } | ||
| 896 | + | ||
| 897 | + | ||
| 898 | + TEST(DisallowObserveAccessCheckedObject) { | ||
| 899 | + v8::Isolate* isolate = CcTest::isolate(); | ||
| 900 | + v8::HandleScope scope(isolate); | ||
| 901 | + LocalContext env; | ||
| 902 | + v8::Local<v8::ObjectTemplate> object_template = | ||
| 903 | + v8::ObjectTemplate::New(isolate); | ||
| 904 | + object_template->SetAccessCheckCallbacks(NamedAccessCheckAlwaysAllow, NULL); | ||
| 905 | + env->Global()->Set(v8_str("obj"), object_template->NewInstance()); | ||
| 906 | + v8::TryCatch try_catch(isolate); | ||
| 907 | + CompileRun("Object.observe(obj, function(){})"); | ||
| 908 | + CHECK(try_catch.HasCaught()); | ||
| 909 | + } | ||
| 910 | + | ||
| 911 | + | ||
| 912 | + TEST(DisallowGetNotifierAccessCheckedObject) { | ||
| 913 | + v8::Isolate* isolate = CcTest::isolate(); | ||
| 914 | + v8::HandleScope scope(isolate); | ||
| 915 | + LocalContext env; | ||
| 916 | + v8::Local<v8::ObjectTemplate> object_template = | ||
| 917 | + v8::ObjectTemplate::New(isolate); | ||
| 918 | + object_template->SetAccessCheckCallbacks(NamedAccessCheckAlwaysAllow, NULL); | ||
| 919 | + env->Global()->Set(v8_str("obj"), object_template->NewInstance()); | ||
| 920 | + v8::TryCatch try_catch(isolate); | ||
| 921 | + CompileRun("Object.getNotifier(obj)"); | ||
| 922 | + CHECK(try_catch.HasCaught()); | ||
| 923 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments