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

Side by Side Diff: src/api.cc

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/accessors.cc ('k') | src/arm/assembler-arm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "api.h" 30 #include "api.h"
31 #include "arguments.h" 31 #include "arguments.h"
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "compiler.h" 33 #include "compiler.h"
34 #include "debug.h" 34 #include "debug.h"
35 #include "execution.h" 35 #include "execution.h"
36 #include "global-handles.h" 36 #include "global-handles.h"
37 #include "globals.h" 37 #include "messages.h"
38 #include "platform.h" 38 #include "platform.h"
39 #include "serialize.h" 39 #include "serialize.h"
40 #include "snapshot.h" 40 #include "snapshot.h"
41 #include "top.h"
41 #include "utils.h" 42 #include "utils.h"
42 #include "v8threads.h" 43 #include "v8threads.h"
43 #include "version.h" 44 #include "version.h"
44 45
45 46
46 #define LOG_API(expr) LOG(ApiEntryCall(expr)) 47 #define LOG_API(expr) LOG(ApiEntryCall(expr))
47 48
48 #ifdef ENABLE_HEAP_PROTECTION 49 #ifdef ENABLE_HEAP_PROTECTION
49 #define ENTER_V8 i::VMState __state__(i::OTHER) 50 #define ENTER_V8 i::VMState __state__(i::OTHER)
50 #define LEAVE_V8 i::VMState __state__(i::EXTERNAL) 51 #define LEAVE_V8 i::VMState __state__(i::EXTERNAL)
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 bool V8::IsGlobalWeak(i::Object** obj) { 433 bool V8::IsGlobalWeak(i::Object** obj) {
433 LOG_API("IsGlobalWeak"); 434 LOG_API("IsGlobalWeak");
434 if (!i::V8::IsRunning()) return false; 435 if (!i::V8::IsRunning()) return false;
435 return i::GlobalHandles::IsWeak(obj); 436 return i::GlobalHandles::IsWeak(obj);
436 } 437 }
437 438
438 439
439 void V8::DisposeGlobal(i::Object** obj) { 440 void V8::DisposeGlobal(i::Object** obj) {
440 LOG_API("DisposeGlobal"); 441 LOG_API("DisposeGlobal");
441 if (!i::V8::IsRunning()) return; 442 if (!i::V8::IsRunning()) return;
442 if ((*obj)->IsGlobalContext()) i::Heap::NotifyContextDisposed();
443 i::GlobalHandles::Destroy(obj); 443 i::GlobalHandles::Destroy(obj);
444 } 444 }
445 445
446 // --- H a n d l e s --- 446 // --- H a n d l e s ---
447 447
448 448
449 HandleScope::HandleScope() : is_closed_(false) { 449 HandleScope::HandleScope() : is_closed_(false) {
450 API_ENTRY_CHECK("HandleScope::HandleScope"); 450 API_ENTRY_CHECK("HandleScope::HandleScope");
451 i::HandleScope::Enter(&previous_); 451 i::HandleScope::Enter(&previous_);
452 } 452 }
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1570 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1571 if (obj->IsSmi()) return true; 1571 if (obj->IsSmi()) return true;
1572 if (obj->IsNumber()) { 1572 if (obj->IsNumber()) {
1573 double value = obj->Number(); 1573 double value = obj->Number();
1574 return i::FastI2D(i::FastD2I(value)) == value; 1574 return i::FastI2D(i::FastD2I(value)) == value;
1575 } 1575 }
1576 return false; 1576 return false;
1577 } 1577 }
1578 1578
1579 1579
1580 bool Value::IsUint32() const {
1581 if (IsDeadCheck("v8::Value::IsUint32()")) return false;
1582 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1583 if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
1584 if (obj->IsNumber()) {
1585 double value = obj->Number();
1586 return i::FastUI2D(i::FastD2UI(value)) == value;
1587 }
1588 return false;
1589 }
1590
1591
1580 bool Value::IsDate() const { 1592 bool Value::IsDate() const {
1581 if (IsDeadCheck("v8::Value::IsDate()")) return false; 1593 if (IsDeadCheck("v8::Value::IsDate()")) return false;
1582 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1594 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1583 return obj->HasSpecificClassOf(i::Heap::Date_symbol()); 1595 return obj->HasSpecificClassOf(i::Heap::Date_symbol());
1584 } 1596 }
1585 1597
1586 1598
1587 Local<String> Value::ToString() const { 1599 Local<String> Value::ToString() const {
1588 if (IsDeadCheck("v8::Value::ToString()")) return Local<String>(); 1600 if (IsDeadCheck("v8::Value::ToString()")) return Local<String>();
1589 LOG_API("ToString"); 1601 LOG_API("ToString");
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 self, 1987 self,
1976 key_obj, 1988 key_obj,
1977 value_obj, 1989 value_obj,
1978 static_cast<PropertyAttributes>(attribs)); 1990 static_cast<PropertyAttributes>(attribs));
1979 has_pending_exception = obj.is_null(); 1991 has_pending_exception = obj.is_null();
1980 EXCEPTION_BAILOUT_CHECK(false); 1992 EXCEPTION_BAILOUT_CHECK(false);
1981 return true; 1993 return true;
1982 } 1994 }
1983 1995
1984 1996
1997 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) {
1998 ON_BAILOUT("v8::Object::Set()", return false);
1999 ENTER_V8;
2000 HandleScope scope;
2001 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2002 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2003 EXCEPTION_PREAMBLE();
2004 i::Handle<i::Object> obj = i::SetElement(
2005 self,
2006 index,
2007 value_obj);
2008 has_pending_exception = obj.is_null();
2009 EXCEPTION_BAILOUT_CHECK(false);
2010 return true;
2011 }
2012
2013
1985 bool v8::Object::ForceSet(v8::Handle<Value> key, 2014 bool v8::Object::ForceSet(v8::Handle<Value> key,
1986 v8::Handle<Value> value, 2015 v8::Handle<Value> value,
1987 v8::PropertyAttribute attribs) { 2016 v8::PropertyAttribute attribs) {
1988 ON_BAILOUT("v8::Object::ForceSet()", return false); 2017 ON_BAILOUT("v8::Object::ForceSet()", return false);
1989 ENTER_V8; 2018 ENTER_V8;
1990 HandleScope scope; 2019 HandleScope scope;
1991 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2020 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1992 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2021 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
1993 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 2022 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
1994 EXCEPTION_PREAMBLE(); 2023 EXCEPTION_PREAMBLE();
(...skipping 28 matching lines...) Expand all
2023 i::Handle<i::Object> self = Utils::OpenHandle(this); 2052 i::Handle<i::Object> self = Utils::OpenHandle(this);
2024 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2053 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2025 EXCEPTION_PREAMBLE(); 2054 EXCEPTION_PREAMBLE();
2026 i::Handle<i::Object> result = i::GetProperty(self, key_obj); 2055 i::Handle<i::Object> result = i::GetProperty(self, key_obj);
2027 has_pending_exception = result.is_null(); 2056 has_pending_exception = result.is_null();
2028 EXCEPTION_BAILOUT_CHECK(Local<Value>()); 2057 EXCEPTION_BAILOUT_CHECK(Local<Value>());
2029 return Utils::ToLocal(result); 2058 return Utils::ToLocal(result);
2030 } 2059 }
2031 2060
2032 2061
2062 Local<Value> v8::Object::Get(uint32_t index) {
2063 ON_BAILOUT("v8::Object::Get()", return Local<v8::Value>());
2064 ENTER_V8;
2065 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2066 EXCEPTION_PREAMBLE();
2067 i::Handle<i::Object> result = i::GetElement(self, index);
2068 has_pending_exception = result.is_null();
2069 EXCEPTION_BAILOUT_CHECK(Local<Value>());
2070 return Utils::ToLocal(result);
2071 }
2072
2073
2033 Local<Value> v8::Object::GetPrototype() { 2074 Local<Value> v8::Object::GetPrototype() {
2034 ON_BAILOUT("v8::Object::GetPrototype()", return Local<v8::Value>()); 2075 ON_BAILOUT("v8::Object::GetPrototype()", return Local<v8::Value>());
2035 ENTER_V8; 2076 ENTER_V8;
2036 i::Handle<i::Object> self = Utils::OpenHandle(this); 2077 i::Handle<i::Object> self = Utils::OpenHandle(this);
2037 i::Handle<i::Object> result = i::GetPrototype(self); 2078 i::Handle<i::Object> result = i::GetPrototype(self);
2038 return Utils::ToLocal(result); 2079 return Utils::ToLocal(result);
2039 } 2080 }
2040 2081
2041 2082
2042 bool v8::Object::SetPrototype(Handle<Value> value) { 2083 bool v8::Object::SetPrototype(Handle<Value> value) {
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 2656
2616 int String::WriteAscii(char* buffer, int start, int length) const { 2657 int String::WriteAscii(char* buffer, int start, int length) const {
2617 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; 2658 if (IsDeadCheck("v8::String::WriteAscii()")) return 0;
2618 LOG_API("String::WriteAscii"); 2659 LOG_API("String::WriteAscii");
2619 ENTER_V8; 2660 ENTER_V8;
2620 ASSERT(start >= 0 && length >= -1); 2661 ASSERT(start >= 0 && length >= -1);
2621 i::Handle<i::String> str = Utils::OpenHandle(this); 2662 i::Handle<i::String> str = Utils::OpenHandle(this);
2622 StringTracker::RecordWrite(str); 2663 StringTracker::RecordWrite(str);
2623 // Flatten the string for efficiency. This applies whether we are 2664 // Flatten the string for efficiency. This applies whether we are
2624 // using StringInputBuffer or Get(i) to access the characters. 2665 // using StringInputBuffer or Get(i) to access the characters.
2625 str->TryFlattenIfNotFlat(); 2666 str->TryFlatten();
2626 int end = length; 2667 int end = length;
2627 if ( (length == -1) || (length > str->length() - start) ) 2668 if ( (length == -1) || (length > str->length() - start) )
2628 end = str->length() - start; 2669 end = str->length() - start;
2629 if (end < 0) return 0; 2670 if (end < 0) return 0;
2630 write_input_buffer.Reset(start, *str); 2671 write_input_buffer.Reset(start, *str);
2631 int i; 2672 int i;
2632 for (i = 0; i < end; i++) { 2673 for (i = 0; i < end; i++) {
2633 char c = static_cast<char>(write_input_buffer.GetNext()); 2674 char c = static_cast<char>(write_input_buffer.GetNext());
2634 if (c == '\0') c = ' '; 2675 if (c == '\0') c = ' ';
2635 buffer[i] = c; 2676 buffer[i] = c;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 if (IsDeadCheck("v8::Int32::Value()")) return 0; 2769 if (IsDeadCheck("v8::Int32::Value()")) return 0;
2729 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2770 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2730 if (obj->IsSmi()) { 2771 if (obj->IsSmi()) {
2731 return i::Smi::cast(*obj)->value(); 2772 return i::Smi::cast(*obj)->value();
2732 } else { 2773 } else {
2733 return static_cast<int32_t>(obj->Number()); 2774 return static_cast<int32_t>(obj->Number());
2734 } 2775 }
2735 } 2776 }
2736 2777
2737 2778
2779 uint32_t Uint32::Value() const {
2780 if (IsDeadCheck("v8::Uint32::Value()")) return 0;
2781 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2782 if (obj->IsSmi()) {
2783 return i::Smi::cast(*obj)->value();
2784 } else {
2785 return static_cast<uint32_t>(obj->Number());
2786 }
2787 }
2788
2789
2738 int v8::Object::InternalFieldCount() { 2790 int v8::Object::InternalFieldCount() {
2739 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0; 2791 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0;
2740 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2792 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
2741 return obj->GetInternalFieldCount(); 2793 return obj->GetInternalFieldCount();
2742 } 2794 }
2743 2795
2744 2796
2745 Local<Value> v8::Object::CheckedGetInternalField(int index) { 2797 Local<Value> v8::Object::CheckedGetInternalField(int index) {
2746 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>(); 2798 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>();
2747 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2799 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2821 return i::V8::IdleNotification(); 2873 return i::V8::IdleNotification();
2822 } 2874 }
2823 2875
2824 2876
2825 void v8::V8::LowMemoryNotification() { 2877 void v8::V8::LowMemoryNotification() {
2826 if (!i::V8::IsRunning()) return; 2878 if (!i::V8::IsRunning()) return;
2827 i::Heap::CollectAllGarbage(true); 2879 i::Heap::CollectAllGarbage(true);
2828 } 2880 }
2829 2881
2830 2882
2883 int v8::V8::ContextDisposedNotification() {
2884 if (!i::V8::IsRunning()) return 0;
2885 return i::Heap::NotifyContextDisposed();
2886 }
2887
2888
2831 const char* v8::V8::GetVersion() { 2889 const char* v8::V8::GetVersion() {
2832 static v8::internal::EmbeddedVector<char, 128> buffer; 2890 static v8::internal::EmbeddedVector<char, 128> buffer;
2833 v8::internal::Version::GetString(buffer); 2891 v8::internal::Version::GetString(buffer);
2834 return buffer.start(); 2892 return buffer.start();
2835 } 2893 }
2836 2894
2837 2895
2838 static i::Handle<i::FunctionTemplateInfo> 2896 static i::Handle<i::FunctionTemplateInfo>
2839 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { 2897 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) {
2840 if (templ->constructor()->IsUndefined()) { 2898 if (templ->constructor()->IsUndefined()) {
2841 Local<FunctionTemplate> constructor = FunctionTemplate::New(); 2899 Local<FunctionTemplate> constructor = FunctionTemplate::New();
2842 Utils::OpenHandle(*constructor)->set_instance_template(*templ); 2900 Utils::OpenHandle(*constructor)->set_instance_template(*templ);
2843 templ->set_constructor(*Utils::OpenHandle(*constructor)); 2901 templ->set_constructor(*Utils::OpenHandle(*constructor));
2844 } 2902 }
2845 return i::Handle<i::FunctionTemplateInfo>( 2903 return i::Handle<i::FunctionTemplateInfo>(
2846 i::FunctionTemplateInfo::cast(templ->constructor())); 2904 i::FunctionTemplateInfo::cast(templ->constructor()));
2847 } 2905 }
2848 2906
2849 2907
2850 Persistent<Context> v8::Context::New( 2908 Persistent<Context> v8::Context::New(
2851 v8::ExtensionConfiguration* extensions, 2909 v8::ExtensionConfiguration* extensions,
2852 v8::Handle<ObjectTemplate> global_template, 2910 v8::Handle<ObjectTemplate> global_template,
2853 v8::Handle<Value> global_object) { 2911 v8::Handle<Value> global_object) {
2854 EnsureInitialized("v8::Context::New()"); 2912 EnsureInitialized("v8::Context::New()");
2855 LOG_API("Context::New"); 2913 LOG_API("Context::New");
2856 ON_BAILOUT("v8::Context::New()", return Persistent<Context>()); 2914 ON_BAILOUT("v8::Context::New()", return Persistent<Context>());
2857 2915
2858 #if defined(ANDROID)
2859 // On mobile device, full GC is expensive, leave it to the system to
2860 // decide when should make a full GC.
2861 #else
2862 // Give the heap a chance to cleanup if we've disposed contexts.
2863 i::Heap::CollectAllGarbageIfContextDisposed();
2864 #endif
2865
2866 // Enter V8 via an ENTER_V8 scope. 2916 // Enter V8 via an ENTER_V8 scope.
2867 i::Handle<i::Context> env; 2917 i::Handle<i::Context> env;
2868 { 2918 {
2869 ENTER_V8; 2919 ENTER_V8;
2870 v8::Handle<ObjectTemplate> proxy_template = global_template; 2920 v8::Handle<ObjectTemplate> proxy_template = global_template;
2871 i::Handle<i::FunctionTemplateInfo> proxy_constructor; 2921 i::Handle<i::FunctionTemplateInfo> proxy_constructor;
2872 i::Handle<i::FunctionTemplateInfo> global_constructor; 2922 i::Handle<i::FunctionTemplateInfo> global_constructor;
2873 2923
2874 if (!global_template.IsEmpty()) { 2924 if (!global_template.IsEmpty()) {
2875 // Make sure that the global_template has a constructor. 2925 // Make sure that the global_template has a constructor.
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
3562 } 3612 }
3563 } 3613 }
3564 3614
3565 3615
3566 void V8::TerminateExecution() { 3616 void V8::TerminateExecution() {
3567 if (!i::V8::IsRunning()) return; 3617 if (!i::V8::IsRunning()) return;
3568 i::StackGuard::TerminateExecution(); 3618 i::StackGuard::TerminateExecution();
3569 } 3619 }
3570 3620
3571 3621
3622 bool V8::IsExecutionTerminating() {
3623 if (!i::V8::IsRunning()) return false;
3624 if (i::Top::has_scheduled_exception()) {
3625 return i::Top::scheduled_exception() == i::Heap::termination_exception();
3626 }
3627 return false;
3628 }
3629
3630
3572 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) { 3631 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) {
3573 EnsureInitialized("v8::String::Utf8Value::Utf8Value()"); 3632 EnsureInitialized("v8::String::Utf8Value::Utf8Value()");
3574 if (obj.IsEmpty()) { 3633 if (obj.IsEmpty()) {
3575 str_ = NULL; 3634 str_ = NULL;
3576 length_ = 0; 3635 length_ = 0;
3577 return; 3636 return;
3578 } 3637 }
3579 ENTER_V8; 3638 ENTER_V8;
3580 HandleScope scope; 3639 HandleScope scope;
3581 TryCatch try_catch; 3640 TryCatch try_catch;
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3946 4005
3947 4006
3948 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 4007 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
3949 HandleScopeImplementer* thread_local = 4008 HandleScopeImplementer* thread_local =
3950 reinterpret_cast<HandleScopeImplementer*>(storage); 4009 reinterpret_cast<HandleScopeImplementer*>(storage);
3951 thread_local->IterateThis(v); 4010 thread_local->IterateThis(v);
3952 return storage + ArchiveSpacePerThread(); 4011 return storage + ArchiveSpacePerThread();
3953 } 4012 }
3954 4013
3955 } } // namespace v8::internal 4014 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/accessors.cc ('k') | src/arm/assembler-arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698