summaryrefslogtreecommitdiffstats
path: root/src/v8/0008-QtScript-V8-Add-new-v8-api-to-check-if-a-value-is-an.patch
blob: 5e360242325e2118ec30ed4c6b583980cf70adfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From de3e14564f163d808a3d10397a3018e6aaeb727b Mon Sep 17 00:00:00 2001
From: Jedrzej Nowacki <jedrzej.nowacki@nokia.com>
Date: Tue, 7 Dec 2010 11:56:42 +0100
Subject: [PATCH 08/12] QtScript/V8: Add new v8 api to check if a value is an
 error.

New function v8::Value::IsError was created.

This API is experimental and added only for the purposes of our
research.
---
 include/v8.h |    5 +++++
 src/api.cc   |    6 ++++++
 src/heap.h   |    1 +
 3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/include/v8.h b/include/v8.h
index 229ddbd..d995e54 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -967,6 +967,11 @@ class Value : public Data {
    */
   V8EXPORT bool IsRegExp() const;
 
+  /**
+   * Returns true if this value is an Error.
+   */
+  V8EXPORT bool IsError() const;
+
   V8EXPORT Local<Boolean> ToBoolean() const;
   V8EXPORT Local<Number> ToNumber() const;
   V8EXPORT Local<String> ToString() const;
diff --git a/src/api.cc b/src/api.cc
index 974d702..a16ef65 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2316,6 +2316,12 @@ bool Value::IsRegExp() const {
   return obj->IsJSRegExp();
 }
 
+bool Value::IsError() const {
+  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsError()")) return false;
+  i::Handle<i::Object> obj = Utils::OpenHandle(this);
+  return obj->HasSpecificClassOf(HEAP->Error_symbol());
+}
+
 
 Local<String> Value::ToString() const {
   i::Handle<i::Object> obj = Utils::OpenHandle(this);
diff --git a/src/heap.h b/src/heap.h
index 5e90964..6166cde 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -190,6 +190,7 @@ inline Heap* _inline_get_heap_();
   V(string_symbol, "string")                                             \
   V(String_symbol, "String")                                             \
   V(Date_symbol, "Date")                                                 \
+  V(Error_symbol, "Error")                                               \
   V(this_symbol, "this")                                                 \
   V(to_string_symbol, "toString")                                        \
   V(char_at_symbol, "CharAt")                                            \
-- 
1.7.7.3