[V8] Add v8::Value::TypeOf to API
There is TypeOf static method on object inside V8. In this CL I've extracted it via API. LOG=Y R=yangguo@chromium.org BUG=chromium:595206 Review-Url: https://codereview.chromium.org/1829833002 Cr-Commit-Position: refs/heads/master@{#36113}
This commit is contained in:
parent
86d4a45586
commit
6f419dfe67
@ -2027,6 +2027,8 @@ class V8_EXPORT Value : public Data {
|
||||
|
||||
template <class T> V8_INLINE static Value* Cast(T* value);
|
||||
|
||||
Local<String> TypeOf(v8::Isolate*);
|
||||
|
||||
private:
|
||||
V8_INLINE bool QuickIsUndefined() const;
|
||||
V8_INLINE bool QuickIsNull() const;
|
||||
|
@ -3549,6 +3549,12 @@ bool Value::SameValue(Local<Value> that) const {
|
||||
return self->SameValue(*other);
|
||||
}
|
||||
|
||||
Local<String> Value::TypeOf(v8::Isolate* external_isolate) {
|
||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
|
||||
ENTER_V8(isolate);
|
||||
LOG_API(isolate, "v8::Value::TypeOf()");
|
||||
return Utils::ToLocal(i::Object::TypeOf(isolate, Utils::OpenHandle(this)));
|
||||
}
|
||||
|
||||
Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
|
||||
v8::Local<Value> key, v8::Local<Value> value) {
|
||||
|
@ -6391,6 +6391,46 @@ THREADED_TEST(Equality) {
|
||||
CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate)));
|
||||
}
|
||||
|
||||
THREADED_TEST(TypeOf) {
|
||||
LocalContext context;
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
v8::HandleScope scope(context->GetIsolate());
|
||||
|
||||
Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
|
||||
Local<v8::Function> fun = t1->GetFunction(context.local()).ToLocalChecked();
|
||||
|
||||
CHECK(v8::Undefined(isolate)
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("undefined"))
|
||||
.FromJust());
|
||||
CHECK(v8::Null(isolate)
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("object"))
|
||||
.FromJust());
|
||||
CHECK(v8_str("str")
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("string"))
|
||||
.FromJust());
|
||||
CHECK(v8_num(0.0)
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("number"))
|
||||
.FromJust());
|
||||
CHECK(v8_num(1)
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("number"))
|
||||
.FromJust());
|
||||
CHECK(v8::Object::New(isolate)
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("object"))
|
||||
.FromJust());
|
||||
CHECK(v8::Boolean::New(isolate, true)
|
||||
->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("boolean"))
|
||||
.FromJust());
|
||||
CHECK(fun->TypeOf(isolate)
|
||||
->Equals(context.local(), v8_str("function"))
|
||||
.FromJust());
|
||||
}
|
||||
|
||||
THREADED_TEST(MultiRun) {
|
||||
LocalContext context;
|
||||
|
Loading…
Reference in New Issue
Block a user