Skip to content

Commit ea5e96f

Browse files
committed
Version 5.1.281.52 (cherry-pick)
Merged b3d793e [api] Introduce ReturnValue::Get [email protected] BUG=chromium:601073 Review URL: https://codereview.chromium.org/2026443002 . Cr-Commit-Position: refs/branch-heads/5.1@{#63} Cr-Branched-From: 167dc63-refs/heads/5.1.281@{#1} Cr-Branched-From: 03953f5-refs/heads/master@{#35282}
1 parent 8ec5136 commit ea5e96f

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

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 5
1212
#define V8_MINOR_VERSION 1
1313
#define V8_BUILD_NUMBER 281
14-
#define V8_PATCH_LEVEL 51
14+
#define V8_PATCH_LEVEL 52
1515

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

include/v8.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ class Local {
330330
template <class F1, class F2, class F3>
331331
friend class PersistentValueMapBase;
332332
template<class F1, class F2> friend class PersistentValueVector;
333+
template <class F>
334+
friend class ReturnValue;
333335

334336
explicit V8_INLINE Local(T* that) : val_(that) {}
335337
V8_INLINE static Local<T> New(Isolate* isolate, T* that);
@@ -3136,12 +3138,17 @@ class ReturnValue {
31363138
V8_INLINE void SetUndefined();
31373139
V8_INLINE void SetEmptyString();
31383140
// Convenience getter for Isolate
3139-
V8_INLINE Isolate* GetIsolate();
3141+
V8_INLINE Isolate* GetIsolate() const;
31403142

31413143
// Pointer setter: Uncompilable to prevent inadvertent misuse.
31423144
template <typename S>
31433145
V8_INLINE void Set(S* whatever);
31443146

3147+
// Getter. Creates a new Local<> so it comes with a certain performance
3148+
// hit. If the ReturnValue was not yet set, this will return the undefined
3149+
// value.
3150+
V8_INLINE Local<Value> Get() const;
3151+
31453152
private:
31463153
template<class F> friend class ReturnValue;
31473154
template<class F> friend class FunctionCallbackInfo;
@@ -7343,6 +7350,7 @@ class Internals {
73437350
kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
73447351
kApiPointerSize;
73457352
static const int kUndefinedValueRootIndex = 4;
7353+
static const int kTheHoleValueRootIndex = 5;
73467354
static const int kNullValueRootIndex = 6;
73477355
static const int kTrueValueRootIndex = 7;
73487356
static const int kFalseValueRootIndex = 8;
@@ -7822,14 +7830,22 @@ void ReturnValue<T>::SetEmptyString() {
78227830
*value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
78237831
}
78247832

7825-
template<typename T>
7826-
Isolate* ReturnValue<T>::GetIsolate() {
7833+
template <typename T>
7834+
Isolate* ReturnValue<T>::GetIsolate() const {
78277835
// Isolate is always the pointer below the default value on the stack.
78287836
return *reinterpret_cast<Isolate**>(&value_[-2]);
78297837
}
78307838

7831-
template<typename T>
7832-
template<typename S>
7839+
template <typename T>
7840+
Local<Value> ReturnValue<T>::Get() const {
7841+
typedef internal::Internals I;
7842+
if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
7843+
return Local<Value>(*Undefined(GetIsolate()));
7844+
return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
7845+
}
7846+
7847+
template <typename T>
7848+
template <typename S>
78337849
void ReturnValue<T>::Set(S* whatever) {
78347850
// Uncompilable to prevent inadvertent misuse.
78357851
TYPE_CHECK(S*, Primitive);

src/heap/heap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ class Heap {
551551

552552
STATIC_ASSERT(kUndefinedValueRootIndex ==
553553
Internals::kUndefinedValueRootIndex);
554+
STATIC_ASSERT(kTheHoleValueRootIndex == Internals::kTheHoleValueRootIndex);
554555
STATIC_ASSERT(kNullValueRootIndex == Internals::kNullValueRootIndex);
555556
STATIC_ASSERT(kTrueValueRootIndex == Internals::kTrueValueRootIndex);
556557
STATIC_ASSERT(kFalseValueRootIndex == Internals::kFalseValueRootIndex);

test/cctest/test-api.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ static void CheckReturnValue(const T& t, i::Address callback) {
1818
CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
1919
// Verify reset
2020
bool is_runtime = (*o)->IsTheHole();
21+
if (is_runtime) {
22+
CHECK(rv.Get()->IsUndefined());
23+
} else {
24+
i::Handle<i::Object> v = v8::Utils::OpenHandle(*rv.Get());
25+
CHECK_EQ(*v, *o);
26+
}
2127
rv.Set(true);
2228
CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined());
2329
rv.Set(v8::Local<v8::Object>());

0 commit comments

Comments
 (0)