Skip to content

Commit 5a9e795

Browse files
ofrobotsrvagg
authored andcommitted
deps: upgrade V8 to 4.5.103.35
Apply the latest fixes from V8 4.5 branch & bring us up to 4.5.103.35: * Disallow Object.observe calls on access checked objects. v8/v8@134e541 * Avoid excessive data copying for ExternalStreamingStream::SetBookmark. v8/v8@96dddb4 PR-URL: #3117 Reviewed-By: indutny - Fedor Indutny <[email protected]> Reviewed-By: bnoordhuis - Ben Noordhuis <[email protected]> Reviewed-By: trevnorris - Trevor Norris <[email protected]> Reviewed-By: targos - Michaël Zasso <[email protected]>
1 parent 925b29f commit 5a9e795

File tree

8 files changed

+87
-9
lines changed

8 files changed

+87
-9
lines changed

deps/v8/include/v8-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 4
1212
#define V8_MINOR_VERSION 5
1313
#define V8_BUILD_NUMBER 103
14-
#define V8_PATCH_LEVEL 33
14+
#define V8_PATCH_LEVEL 35
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/messages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class CallSite {
173173
T(ObserveCallbackFrozen, \
174174
"Object.observe cannot deliver to a frozen function object") \
175175
T(ObserveGlobalProxy, "% cannot be called on the global proxy object") \
176+
T(ObserveAccessChecked, "% cannot be called on access-checked objects") \
176177
T(ObserveInvalidAccept, \
177178
"Third argument to Object.observe must be an array of strings.") \
178179
T(ObserveNonFunction, "Object.% cannot deliver to non-function") \

deps/v8/src/object-observe.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ function ObjectObserve(object, callback, acceptList) {
389389
throw MakeTypeError(kObserveNonObject, "observe", "observe");
390390
if (%IsJSGlobalProxy(object))
391391
throw MakeTypeError(kObserveGlobalProxy, "observe");
392+
if (%IsAccessCheckNeeded(object))
393+
throw MakeTypeError(kObserveAccessChecked, "observe");
392394
if (!IS_SPEC_FUNCTION(callback))
393395
throw MakeTypeError(kObserveNonFunction, "observe");
394396
if (ObjectIsFrozen(callback))
@@ -617,6 +619,8 @@ function ObjectGetNotifier(object) {
617619
throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier");
618620
if (%IsJSGlobalProxy(object))
619621
throw MakeTypeError(kObserveGlobalProxy, "getNotifier");
622+
if (%IsAccessCheckNeeded(object))
623+
throw MakeTypeError(kObserveAccessChecked, "getNotifier");
620624

621625
if (ObjectIsFrozen(object)) return null;
622626

deps/v8/src/runtime/runtime-object.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,5 +1435,13 @@ RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) {
14351435
setter, attrs));
14361436
return isolate->heap()->undefined_value();
14371437
}
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+
}
14381446
} // namespace internal
14391447
} // namespace v8

deps/v8/src/runtime/runtime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ namespace internal {
483483
F(IsStrong, 1, 1) \
484484
F(ClassOf, 1, 1) \
485485
F(DefineGetterPropertyUnchecked, 4, 1) \
486-
F(DefineSetterPropertyUnchecked, 4, 1)
486+
F(DefineSetterPropertyUnchecked, 4, 1) \
487+
F(IsAccessCheckNeeded, 1, 1)
487488

488489

489490
#define FOR_EACH_INTRINSIC_OBSERVE(F) \

deps/v8/src/scanner-character-streams.cc

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ size_t ExternalStreamingStream::FillBuffer(size_t position) {
346346
current_data_length_ = source_stream_->GetMoreData(&current_data_);
347347
current_data_offset_ = 0;
348348
bool data_ends = current_data_length_ == 0;
349+
bookmark_data_is_from_current_data_ = false;
349350

350351
// A caveat: a data chunk might end with bytes from an incomplete UTF-8
351352
// character (the rest of the bytes will be in the next chunk).
@@ -405,6 +406,15 @@ bool ExternalStreamingStream::SetBookmark() {
405406
// - buffer_[buffer_cursor_ .. buffer_end_] => bookmark_buffer_
406407
// - current_data_[.._offset_ .. .._length_] => bookmark_data_
407408
// - 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.
408418

409419
bookmark_ = pos_;
410420

@@ -414,10 +424,21 @@ bool ExternalStreamingStream::SetBookmark() {
414424
CopyCharsUnsigned(bookmark_buffer_.start(), buffer_cursor_, buffer_length);
415425

416426
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+
}
421442

422443
bookmark_utf8_split_char_buffer_length_ = utf8_split_char_buffer_length_;
423444
for (size_t i = 0; i < utf8_split_char_buffer_length_; i++) {
@@ -436,12 +457,14 @@ void ExternalStreamingStream::ResetToBookmark() {
436457

437458
// bookmark_data_* => current_data_*
438459
// (current_data_ assumes ownership of its memory.)
439-
uint8_t* data = new uint8_t[bookmark_data_.length()];
440460
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_);
443465
delete[] current_data_;
444466
current_data_ = data;
467+
bookmark_data_is_from_current_data_ = true;
445468

446469
// bookmark_buffer_ needs to be copied to buffer_.
447470
CopyCharsUnsigned(buffer_, bookmark_buffer_.begin(),
@@ -462,6 +485,7 @@ void ExternalStreamingStream::FlushCurrent() {
462485
current_data_ = NULL;
463486
current_data_length_ = 0;
464487
current_data_offset_ = 0;
488+
bookmark_data_is_from_current_data_ = false;
465489
}
466490

467491

deps/v8/src/scanner-character-streams.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class ExternalStreamingStream : public BufferedUtf16CharacterStream {
9494
current_data_length_(0),
9595
utf8_split_char_buffer_length_(0),
9696
bookmark_(0),
97+
bookmark_data_is_from_current_data_(false),
98+
bookmark_data_offset_(0),
9799
bookmark_utf8_split_char_buffer_length_(0) {}
98100

99101
virtual ~ExternalStreamingStream() {
@@ -134,6 +136,8 @@ class ExternalStreamingStream : public BufferedUtf16CharacterStream {
134136
size_t bookmark_;
135137
Vector<uint16_t> bookmark_buffer_;
136138
Vector<uint8_t> bookmark_data_;
139+
bool bookmark_data_is_from_current_data_;
140+
size_t bookmark_data_offset_;
137141
uint8_t bookmark_utf8_split_char_buffer_[4];
138142
size_t bookmark_utf8_split_char_buffer_length_;
139143
};

deps/v8/test/cctest/test-object-observe.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,3 +885,39 @@ TEST(UseCountObjectGetNotifier) {
885885
CompileRun("Object.getNotifier(obj)");
886886
CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
887887
}
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+
}

0 commit comments

Comments
 (0)