OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2167 | 2167 |
2168 | 2168 |
2169 bool Value::IsDate() const { | 2169 bool Value::IsDate() const { |
2170 i::Isolate* isolate = i::Isolate::Current(); | 2170 i::Isolate* isolate = i::Isolate::Current(); |
2171 if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false; | 2171 if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false; |
2172 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2172 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2173 return obj->HasSpecificClassOf(isolate->heap()->Date_symbol()); | 2173 return obj->HasSpecificClassOf(isolate->heap()->Date_symbol()); |
2174 } | 2174 } |
2175 | 2175 |
2176 | 2176 |
2177 bool Value::IsBoxedString() const { | |
2178 i::Isolate* isolate = i::Isolate::Current(); | |
2179 if (IsDeadCheck(isolate, "v8::Value::IsBoxedString()")) return false; | |
2180 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2181 return obj->HasSpecificClassOf(isolate->heap()->String_symbol()); | |
2182 } | |
2183 | |
2184 | |
2185 bool Value::IsBoxedNumber() const { | |
2186 i::Isolate* isolate = i::Isolate::Current(); | |
2187 if (IsDeadCheck(isolate, "v8::Value::IsBoxedNumber()")) return false; | |
2188 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2189 return obj->HasSpecificClassOf(isolate->heap()->Number_symbol()); | |
2190 } | |
2191 | |
2192 | |
2193 static i::Object* LookupBuiltin(i::Isolate* isolate, | |
2194 const char* builtin_name) { | |
2195 i::Handle<i::String> symbol = | |
2196 isolate->factory()->LookupAsciiSymbol(builtin_name); | |
2197 i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); | |
2198 return builtins->GetPropertyNoExceptionThrown(*symbol); | |
2199 } | |
2200 | |
2201 | |
2202 static bool CheckConstructor(i::Isolate* isolate, | |
2203 i::Handle<i::JSObject> obj, | |
2204 const char* class_name) { | |
2205 return obj->map()->constructor() == LookupBuiltin(isolate, class_name); | |
2206 } | |
2207 | |
2208 | |
2209 bool Value::IsNativeError() const { | |
2210 i::Isolate* isolate = i::Isolate::Current(); | |
2211 if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false; | |
2212 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2213 if (obj->IsJSObject()) { | |
2214 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); | |
2215 return CheckConstructor(isolate, js_obj, "$Error") || | |
2216 CheckConstructor(isolate, js_obj, "$EvalError") || | |
2217 CheckConstructor(isolate, js_obj, "$RangeError") || | |
2218 CheckConstructor(isolate, js_obj, "$ReferenceError") || | |
2219 CheckConstructor(isolate, js_obj, "$SyntaxError") || | |
2220 CheckConstructor(isolate, js_obj, "$TypeError") || | |
2221 CheckConstructor(isolate, js_obj, "$URIError"); | |
2222 } else { | |
2223 return false; | |
2224 } | |
2225 } | |
2226 | |
2227 | |
2228 bool Value::IsMath() const { | |
Vyacheslav Egorov (Chromium)
2011/07/12 20:38:12
Lets pull IsMath() from API for now.
zarko
2011/07/12 21:42:06
Done.
| |
2229 i::Isolate* isolate = i::Isolate::Current(); | |
2230 if (IsDeadCheck(isolate, "v8::Value::IsMath()")) return false; | |
2231 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2232 if (obj->IsJSObject()) { | |
2233 return i::JSObject::cast(*obj) == LookupBuiltin(isolate, "$Math"); | |
2234 } else { | |
2235 return false; | |
2236 } | |
2237 } | |
2238 | |
2239 | |
2240 bool Value::IsBoxedBoolean() const { | |
2241 i::Isolate* isolate = i::Isolate::Current(); | |
2242 if (IsDeadCheck(isolate, "v8::Value::IsBoxedBoolean()")) return false; | |
2243 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2244 return obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()); | |
2245 } | |
2246 | |
2247 | |
2177 bool Value::IsRegExp() const { | 2248 bool Value::IsRegExp() const { |
2178 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false; | 2249 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false; |
2179 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2250 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2180 return obj->IsJSRegExp(); | 2251 return obj->IsJSRegExp(); |
2181 } | 2252 } |
2182 | 2253 |
2183 | 2254 |
2184 Local<String> Value::ToString() const { | 2255 Local<String> Value::ToString() const { |
2185 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2256 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2186 i::Handle<i::Object> str; | 2257 i::Handle<i::Object> str; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2362 void v8::Date::CheckCast(v8::Value* that) { | 2433 void v8::Date::CheckCast(v8::Value* that) { |
2363 i::Isolate* isolate = i::Isolate::Current(); | 2434 i::Isolate* isolate = i::Isolate::Current(); |
2364 if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; | 2435 if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; |
2365 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2436 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
2366 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_symbol()), | 2437 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_symbol()), |
2367 "v8::Date::Cast()", | 2438 "v8::Date::Cast()", |
2368 "Could not convert to date"); | 2439 "Could not convert to date"); |
2369 } | 2440 } |
2370 | 2441 |
2371 | 2442 |
2443 void v8::BoxedString::CheckCast(v8::Value* that) { | |
2444 i::Isolate* isolate = i::Isolate::Current(); | |
2445 if (IsDeadCheck(isolate, "v8::BoxedString::Cast()")) return; | |
2446 i::Handle<i::Object> obj = Utils::OpenHandle(that); | |
2447 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_symbol()), | |
2448 "v8::BoxedString::Cast()", | |
2449 "Could not convert to boxed String"); | |
2450 } | |
2451 | |
2452 | |
2453 void v8::BoxedNumber::CheckCast(v8::Value* that) { | |
2454 i::Isolate* isolate = i::Isolate::Current(); | |
2455 if (IsDeadCheck(isolate, "v8::BoxedNumber::Cast()")) return; | |
2456 i::Handle<i::Object> obj = Utils::OpenHandle(that); | |
2457 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_symbol()), | |
2458 "v8::BoxedNumber::Cast()", | |
2459 "Could not convert to boxed Number"); | |
2460 } | |
2461 | |
2462 | |
2463 void v8::BoxedBoolean::CheckCast(v8::Value* that) { | |
2464 i::Isolate* isolate = i::Isolate::Current(); | |
2465 if (IsDeadCheck(isolate, "v8::BoxedBoolean::Cast()")) return; | |
2466 i::Handle<i::Object> obj = Utils::OpenHandle(that); | |
2467 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()), | |
2468 "v8::BoxedBoolean::Cast()", | |
2469 "Could not convert to boxed Boolean"); | |
2470 } | |
2471 | |
2472 | |
2372 void v8::RegExp::CheckCast(v8::Value* that) { | 2473 void v8::RegExp::CheckCast(v8::Value* that) { |
2373 if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return; | 2474 if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return; |
2374 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2475 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
2375 ApiCheck(obj->IsJSRegExp(), | 2476 ApiCheck(obj->IsJSRegExp(), |
2376 "v8::RegExp::Cast()", | 2477 "v8::RegExp::Cast()", |
2377 "Could not convert to regular expression"); | 2478 "Could not convert to regular expression"); |
2378 } | 2479 } |
2379 | 2480 |
2380 | 2481 |
2381 bool Value::BooleanValue() const { | 2482 bool Value::BooleanValue() const { |
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4395 i::Isolate* isolate = i::Isolate::Current(); | 4496 i::Isolate* isolate = i::Isolate::Current(); |
4396 EnsureInitializedForIsolate(isolate, "v8::Object::New()"); | 4497 EnsureInitializedForIsolate(isolate, "v8::Object::New()"); |
4397 LOG_API(isolate, "Object::New"); | 4498 LOG_API(isolate, "Object::New"); |
4398 ENTER_V8(isolate); | 4499 ENTER_V8(isolate); |
4399 i::Handle<i::JSObject> obj = | 4500 i::Handle<i::JSObject> obj = |
4400 isolate->factory()->NewJSObject(isolate->object_function()); | 4501 isolate->factory()->NewJSObject(isolate->object_function()); |
4401 return Utils::ToLocal(obj); | 4502 return Utils::ToLocal(obj); |
4402 } | 4503 } |
4403 | 4504 |
4404 | 4505 |
4506 Local<v8::Value> v8::BoxedNumber::New(double value) { | |
4507 i::Isolate* isolate = i::Isolate::Current(); | |
4508 EnsureInitializedForIsolate(isolate, "v8::BoxedNumber::New()"); | |
4509 LOG_API(isolate, "BoxedNumber::New"); | |
4510 ENTER_V8(isolate); | |
4511 i::Handle<i::Object> obj = isolate->factory()->NewBoxedNumber(value); | |
4512 return Utils::ToLocal(obj); | |
4513 } | |
4514 | |
4515 | |
4516 double v8::BoxedNumber::NumberValue() const { | |
4517 i::Isolate* isolate = i::Isolate::Current(); | |
4518 if (IsDeadCheck(isolate, "v8::BoxedNumber::NumberValue()")) return 0; | |
4519 LOG_API(isolate, "BoxedNumber::NumberValue"); | |
4520 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
4521 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | |
4522 return jsvalue->value()->Number(); | |
4523 } | |
4524 | |
4525 | |
4526 Local<v8::Value> v8::BoxedBoolean::New(bool value) { | |
4527 i::Isolate* isolate = i::Isolate::Current(); | |
4528 EnsureInitializedForIsolate(isolate, "v8::BoxedBoolean::New()"); | |
4529 LOG_API(isolate, "BoxedBoolean::New"); | |
4530 ENTER_V8(isolate); | |
4531 i::Handle<i::Object> obj = isolate->factory()->NewBoxedBoolean(value); | |
4532 return Utils::ToLocal(obj); | |
4533 } | |
4534 | |
4535 | |
4536 bool v8::BoxedBoolean::BooleanValue() const { | |
4537 i::Isolate* isolate = i::Isolate::Current(); | |
4538 if (IsDeadCheck(isolate, "v8::BoxedBoolean::BooleanValue()")) return 0; | |
4539 LOG_API(isolate, "BoxedBoolean::BooleanValue"); | |
4540 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
4541 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | |
4542 return jsvalue->value()->IsTrue(); | |
4543 } | |
4544 | |
4545 | |
4546 Local<v8::Value> v8::BoxedString::New(Handle<String> value) { | |
4547 i::Isolate* isolate = i::Isolate::Current(); | |
4548 EnsureInitializedForIsolate(isolate, "v8::BoxedString::New()"); | |
4549 LOG_API(isolate, "BoxedString::New"); | |
4550 ENTER_V8(isolate); | |
4551 i::Handle<i::Object> obj = | |
4552 isolate->factory()->NewBoxedString(Utils::OpenHandle(*value)); | |
4553 return Utils::ToLocal(obj); | |
4554 } | |
4555 | |
4556 | |
4557 Local<v8::String> v8::BoxedString::StringValue() const { | |
4558 i::Isolate* isolate = i::Isolate::Current(); | |
4559 if (IsDeadCheck(isolate, "v8::BoxedString::StringValue()")) { | |
4560 return Local<v8::String>(); | |
4561 } | |
4562 LOG_API(isolate, "BoxedString::StringValue"); | |
4563 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
4564 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | |
4565 return Utils::ToLocal( | |
4566 i::Handle<i::String>(i::String::cast(jsvalue->value()))); | |
4567 } | |
4568 | |
4569 | |
4405 Local<v8::Value> v8::Date::New(double time) { | 4570 Local<v8::Value> v8::Date::New(double time) { |
4406 i::Isolate* isolate = i::Isolate::Current(); | 4571 i::Isolate* isolate = i::Isolate::Current(); |
4407 EnsureInitializedForIsolate(isolate, "v8::Date::New()"); | 4572 EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
4408 LOG_API(isolate, "Date::New"); | 4573 LOG_API(isolate, "Date::New"); |
4409 if (isnan(time)) { | 4574 if (isnan(time)) { |
4410 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | 4575 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
4411 time = i::OS::nan_value(); | 4576 time = i::OS::nan_value(); |
4412 } | 4577 } |
4413 ENTER_V8(isolate); | 4578 ENTER_V8(isolate); |
4414 EXCEPTION_PREAMBLE(isolate); | 4579 EXCEPTION_PREAMBLE(isolate); |
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6066 | 6231 |
6067 | 6232 |
6068 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 6233 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
6069 HandleScopeImplementer* scope_implementer = | 6234 HandleScopeImplementer* scope_implementer = |
6070 reinterpret_cast<HandleScopeImplementer*>(storage); | 6235 reinterpret_cast<HandleScopeImplementer*>(storage); |
6071 scope_implementer->IterateThis(v); | 6236 scope_implementer->IterateThis(v); |
6072 return storage + ArchiveSpacePerThread(); | 6237 return storage + ArchiveSpacePerThread(); |
6073 } | 6238 } |
6074 | 6239 |
6075 } } // namespace v8::internal | 6240 } } // namespace v8::internal |
OLD | NEW |