Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: src/api.cc

Issue 7344013: Expose APIs for detecting boxed primitives, native errors and Math. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Get rid of unclear 'box' comments/strings. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/v8.h ('K') | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index a59b934d3456e5bb36882b2d108ae4a86737966f..aa5d8ba68e8b5dc0084c9a53719f760742edc366 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2174,6 +2174,65 @@ bool Value::IsDate() const {
}
+bool Value::IsStringObject() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false;
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ return obj->HasSpecificClassOf(isolate->heap()->String_symbol());
+}
+
+
+bool Value::IsNumberObject() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false;
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ return obj->HasSpecificClassOf(isolate->heap()->Number_symbol());
+}
+
+
+static i::Object* LookupBuiltin(i::Isolate* isolate,
+ const char* builtin_name) {
+ i::Handle<i::String> symbol =
+ isolate->factory()->LookupAsciiSymbol(builtin_name);
+ i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object();
+ return builtins->GetPropertyNoExceptionThrown(*symbol);
+}
+
+
+static bool CheckConstructor(i::Isolate* isolate,
+ i::Handle<i::JSObject> obj,
+ const char* class_name) {
+ return obj->map()->constructor() == LookupBuiltin(isolate, class_name);
+}
+
+
+bool Value::IsNativeError() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false;
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ if (obj->IsJSObject()) {
+ i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj));
+ return CheckConstructor(isolate, js_obj, "$Error") ||
+ CheckConstructor(isolate, js_obj, "$EvalError") ||
+ CheckConstructor(isolate, js_obj, "$RangeError") ||
+ CheckConstructor(isolate, js_obj, "$ReferenceError") ||
+ CheckConstructor(isolate, js_obj, "$SyntaxError") ||
+ CheckConstructor(isolate, js_obj, "$TypeError") ||
+ CheckConstructor(isolate, js_obj, "$URIError");
+ } else {
+ return false;
+ }
+}
+
+
+bool Value::IsBooleanObject() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false;
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ return obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol());
+}
+
+
bool Value::IsRegExp() const {
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false;
i::Handle<i::Object> obj = Utils::OpenHandle(this);
@@ -2369,6 +2428,36 @@ void v8::Date::CheckCast(v8::Value* that) {
}
+void v8::StringObject::CheckCast(v8::Value* that) {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return;
+ i::Handle<i::Object> obj = Utils::OpenHandle(that);
+ ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_symbol()),
+ "v8::StringObject::Cast()",
+ "Could not convert to StringObject");
+}
+
+
+void v8::NumberObject::CheckCast(v8::Value* that) {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return;
+ i::Handle<i::Object> obj = Utils::OpenHandle(that);
+ ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_symbol()),
+ "v8::NumberObject::Cast()",
+ "Could not convert to NumberObject");
+}
+
+
+void v8::BooleanObject::CheckCast(v8::Value* that) {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return;
+ i::Handle<i::Object> obj = Utils::OpenHandle(that);
+ ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()),
+ "v8::BooleanObject::Cast()",
+ "Could not convert to BooleanObject");
+}
+
+
void v8::RegExp::CheckCast(v8::Value* that) {
if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return;
i::Handle<i::Object> obj = Utils::OpenHandle(that);
@@ -4402,6 +4491,73 @@ Local<v8::Object> v8::Object::New() {
}
+Local<v8::Value> v8::NumberObject::New(double value) {
+ i::Isolate* isolate = i::Isolate::Current();
+ EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()");
+ LOG_API(isolate, "NumberObject::New");
+ ENTER_V8(isolate);
+ i::Handle<i::Object> number = isolate->factory()->NewNumber(value);
+ i::Handle<i::Object> obj = isolate->factory()->ToObject(number);
+ return Utils::ToLocal(obj);
+}
+
+
+double v8::NumberObject::NumberValue() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0;
+ LOG_API(isolate, "NumberObject::NumberValue");
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
+ return jsvalue->value()->Number();
+}
+
+
+Local<v8::Value> v8::BooleanObject::New(bool value) {
+ i::Isolate* isolate = i::Isolate::Current();
+ EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()");
+ LOG_API(isolate, "BooleanObject::New");
+ ENTER_V8(isolate);
+ i::Handle<i::Object> boolean(value ? isolate->heap()->true_value()
+ : isolate->heap()->false_value());
+ i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean);
+ return Utils::ToLocal(obj);
+}
+
+
+bool v8::BooleanObject::BooleanValue() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0;
+ LOG_API(isolate, "BooleanObject::BooleanValue");
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
+ return jsvalue->value()->IsTrue();
+}
+
+
+Local<v8::Value> v8::StringObject::New(Handle<String> value) {
+ i::Isolate* isolate = i::Isolate::Current();
+ EnsureInitializedForIsolate(isolate, "v8::StringObject::New()");
+ LOG_API(isolate, "StringObject::New");
+ ENTER_V8(isolate);
+ i::Handle<i::Object> obj =
+ isolate->factory()->ToObject(Utils::OpenHandle(*value));
+ return Utils::ToLocal(obj);
+}
+
+
+Local<v8::String> v8::StringObject::StringValue() const {
+ i::Isolate* isolate = i::Isolate::Current();
+ if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) {
+ return Local<v8::String>();
+ }
+ LOG_API(isolate, "StringObject::StringValue");
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
+ return Utils::ToLocal(
+ i::Handle<i::String>(i::String::cast(jsvalue->value())));
+}
+
+
Local<v8::Value> v8::Date::New(double time) {
i::Isolate* isolate = i::Isolate::Current();
EnsureInitializedForIsolate(isolate, "v8::Date::New()");
« include/v8.h ('K') | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698