Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1984 | 1984 |
| 1985 void v8::Date::CheckCast(v8::Value* that) { | 1985 void v8::Date::CheckCast(v8::Value* that) { |
| 1986 if (IsDeadCheck("v8::Date::Cast()")) return; | 1986 if (IsDeadCheck("v8::Date::Cast()")) return; |
| 1987 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 1987 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 1988 ApiCheck(obj->HasSpecificClassOf(i::Heap::Date_symbol()), | 1988 ApiCheck(obj->HasSpecificClassOf(i::Heap::Date_symbol()), |
| 1989 "v8::Date::Cast()", | 1989 "v8::Date::Cast()", |
| 1990 "Could not convert to date"); | 1990 "Could not convert to date"); |
| 1991 } | 1991 } |
| 1992 | 1992 |
| 1993 | 1993 |
| 1994 void v8::RegExp::CheckCast(v8::Value* that) { | |
| 1995 if (IsDeadCheck("v8::RegExp::Cast()")) return; | |
| 1996 i::Handle<i::Object> obj = Utils::OpenHandle(that); | |
| 1997 ApiCheck(obj->IsJSRegExp(), | |
| 1998 "v8::RegExp::Cast()", | |
| 1999 "Could not convert to regular expression"); | |
| 2000 } | |
| 2001 | |
| 2002 | |
| 1994 bool Value::BooleanValue() const { | 2003 bool Value::BooleanValue() const { |
| 1995 if (IsDeadCheck("v8::Value::BooleanValue()")) return false; | 2004 if (IsDeadCheck("v8::Value::BooleanValue()")) return false; |
| 1996 LOG_API("BooleanValue"); | 2005 LOG_API("BooleanValue"); |
| 1997 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2006 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1998 if (obj->IsBoolean()) { | 2007 if (obj->IsBoolean()) { |
| 1999 return obj->IsTrue(); | 2008 return obj->IsTrue(); |
| 2000 } else { | 2009 } else { |
| 2001 ENTER_V8; | 2010 ENTER_V8; |
| 2002 i::Handle<i::Object> value = i::Execution::ToBoolean(obj); | 2011 i::Handle<i::Object> value = i::Execution::ToBoolean(obj); |
| 2003 return value->IsTrue(); | 2012 return value->IsTrue(); |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3705 | 3714 |
| 3706 double v8::Date::NumberValue() const { | 3715 double v8::Date::NumberValue() const { |
| 3707 if (IsDeadCheck("v8::Date::NumberValue()")) return 0; | 3716 if (IsDeadCheck("v8::Date::NumberValue()")) return 0; |
| 3708 LOG_API("Date::NumberValue"); | 3717 LOG_API("Date::NumberValue"); |
| 3709 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 3718 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3710 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | 3719 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 3711 return jsvalue->value()->Number(); | 3720 return jsvalue->value()->Number(); |
| 3712 } | 3721 } |
| 3713 | 3722 |
| 3714 | 3723 |
| 3724 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { | |
| 3725 char flags_buf[3]; | |
| 3726 int num_flags = 0; | |
| 3727 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; | |
| 3728 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; | |
| 3729 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; | |
| 3730 ASSERT(num_flags <= static_cast<int>(sizeof(flags_buf))); | |
|
antonm
2010/10/04 14:44:55
You might prefer to use ARRAY_SIZE macro here
Vitaly Repeshko
2010/10/04 15:04:42
Done. But it's longer and still requires a cast to
| |
| 3731 if (num_flags == 0) return i::Factory::empty_string(); | |
|
antonm
2010/10/04 14:44:55
should we have this special case here? if it's pe
Vitaly Repeshko
2010/10/04 15:04:42
Changed to Factory::LookupSymbol.
| |
| 3732 return i::Factory::NewStringFromAscii( | |
| 3733 i::Vector<const char>(flags_buf, num_flags)); | |
| 3734 } | |
| 3735 | |
| 3736 | |
| 3737 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, | |
| 3738 Flags flags) { | |
| 3739 EnsureInitialized("v8::RegExp::New()"); | |
| 3740 LOG_API("RegExp::New"); | |
| 3741 ENTER_V8; | |
| 3742 EXCEPTION_PREAMBLE(); | |
| 3743 i::Handle<i::String> flags_string = RegExpFlagsToString(flags); | |
| 3744 i::Object** argv[2] = { | |
| 3745 i::Handle<i::Object>::cast(Utils::OpenHandle(*pattern)).location(), | |
| 3746 i::Handle<i::Object>::cast(flags_string).location() | |
| 3747 }; | |
| 3748 i::Handle<i::Object> obj = i::Execution::New( | |
|
Mads Ager (chromium)
2010/10/05 08:55:46
I think this code can be simplified by creating a
| |
| 3749 i::Handle<i::JSFunction>(i::Top::global_context()->regexp_function()), | |
| 3750 2, argv, | |
| 3751 &has_pending_exception); | |
| 3752 EXCEPTION_BAILOUT_CHECK(Local<v8::RegExp>()); | |
| 3753 if (!obj->IsJSRegExp()) return Local<v8::RegExp>(); | |
|
antonm
2010/10/04 14:44:55
could this condition be true?
Vitaly Repeshko
2010/10/04 15:04:42
With the current spec only if there's a bug in reg
| |
| 3754 return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); | |
| 3755 } | |
| 3756 | |
| 3757 | |
| 3758 Local<v8::String> v8::RegExp::GetSource() const { | |
| 3759 if (IsDeadCheck("v8::RegExp::GetSource()")) return Local<v8::String>(); | |
| 3760 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); | |
| 3761 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); | |
| 3762 } | |
| 3763 | |
| 3764 | |
| 3765 // Assert that the static flags cast in GetFlags is valid. | |
| 3766 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ | |
|
Mads Ager (chromium)
2010/10/05 08:55:46
Is this really worth the macro. Writing this out w
| |
| 3767 STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ | |
| 3768 static_cast<int>(i::JSRegExp::internal_flag)) | |
| 3769 REGEXP_FLAG_ASSERT_EQ(kNone, NONE); | |
| 3770 REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); | |
| 3771 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); | |
| 3772 REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); | |
| 3773 #undef REGEXP_FLAG_ASSERT_EQ | |
| 3774 | |
| 3775 v8::RegExp::Flags v8::RegExp::GetFlags() const { | |
| 3776 if (IsDeadCheck("v8::RegExp::GetFlags()")) return v8::RegExp::kNone; | |
| 3777 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); | |
| 3778 return static_cast<RegExp::Flags>(obj->GetFlags().value()); | |
| 3779 } | |
| 3780 | |
| 3781 | |
| 3715 Local<v8::Array> v8::Array::New(int length) { | 3782 Local<v8::Array> v8::Array::New(int length) { |
| 3716 EnsureInitialized("v8::Array::New()"); | 3783 EnsureInitialized("v8::Array::New()"); |
| 3717 LOG_API("Array::New"); | 3784 LOG_API("Array::New"); |
| 3718 ENTER_V8; | 3785 ENTER_V8; |
| 3719 i::Handle<i::JSArray> obj = i::Factory::NewJSArray(length); | 3786 i::Handle<i::JSArray> obj = i::Factory::NewJSArray(length); |
| 3720 return Utils::ToLocal(obj); | 3787 return Utils::ToLocal(obj); |
| 3721 } | 3788 } |
| 3722 | 3789 |
| 3723 | 3790 |
| 3724 uint32_t v8::Array::Length() const { | 3791 uint32_t v8::Array::Length() const { |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4894 | 4961 |
| 4895 | 4962 |
| 4896 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 4963 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 4897 HandleScopeImplementer* thread_local = | 4964 HandleScopeImplementer* thread_local = |
| 4898 reinterpret_cast<HandleScopeImplementer*>(storage); | 4965 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 4899 thread_local->IterateThis(v); | 4966 thread_local->IterateThis(v); |
| 4900 return storage + ArchiveSpacePerThread(); | 4967 return storage + ArchiveSpacePerThread(); |
| 4901 } | 4968 } |
| 4902 | 4969 |
| 4903 } } // namespace v8::internal | 4970 } } // namespace v8::internal |
| OLD | NEW |