📄 api.cc.svn-base
字号:
Local<Int32> Value::ToInt32() { if (IsDeadCheck("v8::Value::ToInt32()")) return Local<Int32>(); LOG_API("ToInt32"); i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> num; if (obj->IsSmi()) { num = obj; } else { EXCEPTION_PREAMBLE(); num = i::Execution::ToInt32(obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(Local<Int32>()); } return Local<Int32>(ToApi<Int32>(num));}Local<Uint32> Value::ToUint32() { if (IsDeadCheck("v8::Value::ToUint32()")) return Local<Uint32>(); LOG_API("ToUInt32"); i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> num; if (obj->IsSmi()) { num = obj; } else { EXCEPTION_PREAMBLE(); num = i::Execution::ToUint32(obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(Local<Uint32>()); } return Local<Uint32>(ToApi<Uint32>(num));}Local<Uint32> Value::ToArrayIndex() { if (IsDeadCheck("v8::Value::ToArrayIndex()")) return Local<Uint32>(); LOG_API("ToArrayIndex"); i::Handle<i::Object> obj = Utils::OpenHandle(this); if (obj->IsSmi()) { if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); return Local<Uint32>(); } EXCEPTION_PREAMBLE(); i::Handle<i::Object> string_obj = i::Execution::ToString(obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(Local<Uint32>()); i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); uint32_t index; if (str->AsArrayIndex(&index)) { i::Handle<i::Object> value; if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { value = i::Handle<i::Object>(i::Smi::FromInt(index)); } else { value = i::Factory::NewNumber(index); } return Utils::Uint32ToLocal(value); } return Local<Uint32>();}int32_t Value::Int32Value() { if (IsDeadCheck("v8::Value::Int32Value()")) return 0; LOG_API("Int32Value"); i::Handle<i::Object> obj = Utils::OpenHandle(this); if (obj->IsSmi()) { return i::Smi::cast(*obj)->value(); } else { LOG_API("Int32Value (slow)"); EXCEPTION_PREAMBLE(); i::Handle<i::Object> num = i::Execution::ToInt32(obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(0); if (num->IsSmi()) { return i::Smi::cast(*num)->value(); } else { return static_cast<int32_t>(num->Number()); } }}bool Value::Equals(Handle<Value> that) { if (IsDeadCheck("v8::Value::Equals()") || EmptyCheck("v8::Value::Equals()", this) || EmptyCheck("v8::Value::Equals()", that)) return false; LOG_API("Equals"); i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> other = Utils::OpenHandle(*that); i::Object** args[1] = { other.location() }; EXCEPTION_PREAMBLE(); i::Handle<i::Object> result = CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(false); return *result == i::Smi::FromInt(i::EQUAL);}bool Value::StrictEquals(Handle<Value> that) { if (IsDeadCheck("v8::Value::StrictEquals()") || EmptyCheck("v8::Value::StrictEquals()", this) || EmptyCheck("v8::Value::StrictEquals()", that)) return false; LOG_API("StrictEquals"); i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> other = Utils::OpenHandle(*that); // Must check HeapNumber first, since NaN !== NaN. if (obj->IsHeapNumber()) { if (!other->IsNumber()) return false; double x = obj->Number(); double y = other->Number(); // Must check explicitly for NaN:s on Windows, but -0 works fine. return x == y && !isnan(x) && !isnan(y); } else if (*obj == *other) { // Also covers Booleans. return true; } else if (obj->IsSmi()) { return other->IsNumber() && obj->Number() == other->Number(); } else if (obj->IsString()) { return other->IsString() && i::String::cast(*obj)->Equals(i::String::cast(*other)); } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { return other->IsUndefined() || other->IsUndetectableObject(); } else { return false; }}uint32_t Value::Uint32Value() { if (IsDeadCheck("v8::Value::Uint32Value()")) return 0; LOG_API("Uint32Value"); i::Handle<i::Object> obj = Utils::OpenHandle(this); if (obj->IsSmi()) { return i::Smi::cast(*obj)->value(); } else { EXCEPTION_PREAMBLE(); i::Handle<i::Object> num = i::Execution::ToUint32(obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(0); if (num->IsSmi()) { return i::Smi::cast(*num)->value(); } else { return static_cast<uint32_t>(num->Number()); } }}bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value, v8::PropertyAttribute attribs) { ON_BAILOUT("v8::Object::Set()", return false); i::Handle<i::Object> self = Utils::OpenHandle(this); i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); EXCEPTION_PREAMBLE(); i::Handle<i::Object> obj = i::SetProperty( self, key_obj, value_obj, static_cast<PropertyAttributes>(attribs)); has_pending_exception = obj.is_null(); EXCEPTION_BAILOUT_CHECK(false); return true;}Local<Value> v8::Object::Get(v8::Handle<Value> key) { ON_BAILOUT("v8::Object::Get()", return Local<v8::Value>()); i::Handle<i::Object> self = Utils::OpenHandle(this); i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); EXCEPTION_PREAMBLE(); i::Handle<i::Object> result = i::GetProperty(self, key_obj); has_pending_exception = result.is_null(); EXCEPTION_BAILOUT_CHECK(Local<Value>()); return Utils::ToLocal(result);}Local<Value> v8::Object::GetPrototype() { ON_BAILOUT("v8::Object::GetPrototype()", return Local<v8::Value>()); i::Handle<i::Object> self = Utils::OpenHandle(this); i::Handle<i::Object> result = i::GetPrototype(self); return Utils::ToLocal(result);}Local<String> v8::Object::ObjectProtoToString() { ON_BAILOUT("v8::Object::ObjectProtoToString()", return Local<v8::String>()); i::Handle<i::JSObject> self = Utils::OpenHandle(this); i::Handle<i::Object> name(self->class_name()); // Native implementation of Object.prototype.toString (v8natives.js): // var c = %ClassOf(this); // if (c === 'Arguments') c = 'Object'; // return "[object " + c + "]"; if (!name->IsString()) { return v8::String::New("[object ]"); } else { i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); if (class_name->IsEqualTo(i::CStrVector("Arguments"))) { return v8::String::New("[object Object]"); } else { const char* prefix = "[object "; Local<String> str = Utils::ToLocal(class_name); const char* postfix = "]"; size_t prefix_len = strlen(prefix); size_t str_len = str->Length(); size_t postfix_len = strlen(postfix); size_t buf_len = prefix_len + str_len + postfix_len; char* buf = i::NewArray<char>(buf_len); // Write prefix. char* ptr = buf; memcpy(ptr, prefix, prefix_len * v8::internal::kCharSize); ptr += prefix_len; // Write real content. str->WriteAscii(ptr, 0, str_len); ptr += str_len; // Write postfix. memcpy(ptr, postfix, postfix_len * v8::internal::kCharSize); // Copy the buffer into a heap-allocated string and return it. Local<String> result = v8::String::New(buf, buf_len); i::DeleteArray(buf); return result; } }}bool v8::Object::Delete(v8::Handle<String> key) { ON_BAILOUT("v8::Object::Delete()", return false); HandleScope scope; i::Handle<i::JSObject> self = Utils::OpenHandle(this); i::Handle<i::String> key_obj = Utils::OpenHandle(*key); return i::DeleteProperty(self, key_obj)->IsTrue();}bool v8::Object::Has(v8::Handle<String> key) { ON_BAILOUT("v8::Object::Has()", return false); i::Handle<i::JSObject> self = Utils::OpenHandle(this); i::Handle<i::String> key_obj = Utils::OpenHandle(*key); return self->HasProperty(*key_obj);}bool v8::Object::Delete(uint32_t index) { ON_BAILOUT("v8::Object::DeleteProperty()", return false); HandleScope scope; i::Handle<i::JSObject> self = Utils::OpenHandle(this); return i::DeleteElement(self, index)->IsTrue();}bool v8::Object::Has(uint32_t index) { ON_BAILOUT("v8::Object::HasProperty()", return false); i::Handle<i::JSObject> self = Utils::OpenHandle(this); return self->HasElement(index);}bool v8::Object::HasRealNamedProperty(Handle<String> key) { ON_BAILOUT("v8::Object::HasRealNamedProperty()", return false); return Utils::OpenHandle(this)->HasRealNamedProperty( *Utils::OpenHandle(*key));}bool v8::Object::HasRealIndexedProperty(uint32_t index) { ON_BAILOUT("v8::Object::HasRealIndexedProperty()", return false); return Utils::OpenHandle(this)->HasRealElementProperty(index);}bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { ON_BAILOUT("v8::Object::HasRealNamedCallbackProperty()", return false); return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( *Utils::OpenHandle(*key));}bool v8::Object::HasNamedLookupInterceptor() { ON_BAILOUT("v8::Object::HasNamedLookupInterceptor()", return false); return Utils::OpenHandle(this)->HasNamedInterceptor();}bool v8::Object::HasIndexedLookupInterceptor() { ON_BAILOUT("v8::Object::HasIndexedLookupInterceptor()", return false); return Utils::OpenHandle(this)->HasIndexedInterceptor();}Handle<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( Handle<String> key) { ON_BAILOUT("v8::Object::GetRealNamedPropertyInPrototypeChain()", return Local<Value>()); i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); i::Handle<i::String> key_obj = Utils::OpenHandle(*key); i::LookupResult lookup; self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); if (lookup.IsValid()) { PropertyAttributes attributes; i::Handle<i::Object> result(self_obj->GetProperty(*self_obj, &lookup, *key_obj, &attributes)); return Utils::ToLocal(result); } return Local<Value>(); // No real property was found in prototype chain.}Local<v8::Object> Function::NewInstance() { return NewInstance(0, NULL);}Local<v8::Object> Function::NewInstance(int argc, v8::Handle<v8::Value> argv[]) { ON_BAILOUT("v8::Function::NewInstance()", return Local<v8::Object>()); LOG_API("Function::NewInstance"); HandleScope scope; i::Handle<i::JSFunction> function = Utils::OpenHandle(this); STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); i::Object*** args = reinterpret_cast<i::Object***>(argv); EXCEPTION_PREAMBLE(); i::Handle<i::Object> returned = i::Execution::New(function, argc, args, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(Local<v8::Object>()); return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));}Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, v8::Handle<v8::Value> argv[]) { ON_BAILOUT("v8::Function::Call()", return Local<v8::Value>()); LOG_API("Function::Call"); i::Object* raw_result = NULL; { HandleScope scope; i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); i::Object*** args = reinterpret_cast<i::Object***>(argv); EXCEPTION_PREAMBLE(); i::Handle<i::Object> returned = i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(Local<Object>()); raw_result = *returned; } i::Handle<i::Object> result(raw_result); return Utils::ToLocal(result);}void Function::SetName(v8::Handle<v8::String> name) { i::Handle<i::JSFunction> func = Utils::OpenHandle(this); func->shared()->set_name(*Utils::OpenHandle(*name));}Handle<Value> Function::GetName() { i::Handle<i::JSFunction> func = Utils::OpenHandle(this); return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name()));}int String::Length() { if (IsDeadCheck("v8::String::Length()")) return 0; return Utils::OpenHandle(this)->length();}int String::Utf8Length() { if (IsDeadCheck("v8::String::Utf8Length()")) return 0; return Utils::OpenHandle(this)->Utf8Length();}int String::WriteUtf8(char* buffer, int capacity) { if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; LOG_API("String::WriteUtf8"); i::Handle<i::String> str = Utils::OpenHandle(this); write_input_buffer.Reset(0, *str); int len = str->length(); // Encode the first K - 3 bytes directly into the buffer since we // know there's room for them. If no capacity is given we copy all // of them here. int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -