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

Side by Side Diff: src/api.cc

Issue 7778013: NewGC: Merge bleeding edge up to 9009. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 3 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/api.h ('k') | src/apinatives.js » ('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 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 17 matching lines...) Expand all
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "api.h" 30 #include "api.h"
31 31
32 #include "arguments.h" 32 #include "arguments.h"
33 #include "bootstrapper.h" 33 #include "bootstrapper.h"
34 #include "compiler.h" 34 #include "compiler.h"
35 #include "debug.h" 35 #include "debug.h"
36 #include "deoptimizer.h" 36 #include "deoptimizer.h"
37 #include "execution.h" 37 #include "execution.h"
38 #include "flags.h"
38 #include "global-handles.h" 39 #include "global-handles.h"
39 #include "heap-profiler.h" 40 #include "heap-profiler.h"
40 #include "messages.h" 41 #include "messages.h"
41 #include "natives.h" 42 #include "natives.h"
42 #include "parser.h" 43 #include "parser.h"
43 #include "platform.h" 44 #include "platform.h"
44 #include "profile-generator-inl.h" 45 #include "profile-generator-inl.h"
45 #include "runtime-profiler.h" 46 #include "runtime-profiler.h"
46 #include "serialize.h" 47 #include "serialize.h"
47 #include "snapshot.h" 48 #include "snapshot.h"
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); 1399 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
1399 } 1400 }
1400 1401
1401 1402
1402 // --- S c r i p t D a t a --- 1403 // --- S c r i p t D a t a ---
1403 1404
1404 1405
1405 ScriptData* ScriptData::PreCompile(const char* input, int length) { 1406 ScriptData* ScriptData::PreCompile(const char* input, int length) {
1406 i::Utf8ToUC16CharacterStream stream( 1407 i::Utf8ToUC16CharacterStream stream(
1407 reinterpret_cast<const unsigned char*>(input), length); 1408 reinterpret_cast<const unsigned char*>(input), length);
1408 return i::ParserApi::PreParse(&stream, NULL); 1409 return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_block_scoping);
1409 } 1410 }
1410 1411
1411 1412
1412 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { 1413 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) {
1413 i::Handle<i::String> str = Utils::OpenHandle(*source); 1414 i::Handle<i::String> str = Utils::OpenHandle(*source);
1414 if (str->IsExternalTwoByteString()) { 1415 if (str->IsExternalTwoByteString()) {
1415 i::ExternalTwoByteStringUC16CharacterStream stream( 1416 i::ExternalTwoByteStringUC16CharacterStream stream(
1416 i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); 1417 i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length());
1417 return i::ParserApi::PreParse(&stream, NULL); 1418 return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_block_scoping);
1418 } else { 1419 } else {
1419 i::GenericStringUC16CharacterStream stream(str, 0, str->length()); 1420 i::GenericStringUC16CharacterStream stream(str, 0, str->length());
1420 return i::ParserApi::PreParse(&stream, NULL); 1421 return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_block_scoping);
1421 } 1422 }
1422 } 1423 }
1423 1424
1424 1425
1425 ScriptData* ScriptData::New(const char* data, int length) { 1426 ScriptData* ScriptData::New(const char* data, int length) {
1426 // Return an empty ScriptData if the length is obviously invalid. 1427 // Return an empty ScriptData if the length is obviously invalid.
1427 if (length % sizeof(unsigned) != 0) { 1428 if (length % sizeof(unsigned) != 0) {
1428 return new i::ScriptDataImpl(); 1429 return new i::ScriptDataImpl();
1429 } 1430 }
1430 1431
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 has_pending_exception = result.is_null(); 3157 has_pending_exception = result.is_null();
3157 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); 3158 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
3158 return Utils::ToLocal(result); 3159 return Utils::ToLocal(result);
3159 } 3160 }
3160 3161
3161 3162
3162 static i::Context* GetCreationContext(i::JSObject* object) { 3163 static i::Context* GetCreationContext(i::JSObject* object) {
3163 i::Object* constructor = object->map()->constructor(); 3164 i::Object* constructor = object->map()->constructor();
3164 i::JSFunction* function; 3165 i::JSFunction* function;
3165 if (!constructor->IsJSFunction()) { 3166 if (!constructor->IsJSFunction()) {
3166 // API functions have null as a constructor, 3167 // Functions have null as a constructor,
3167 // but any JSFunction knows its context immediately. 3168 // but any JSFunction knows its context immediately.
3168 ASSERT(object->IsJSFunction() && 3169 ASSERT(object->IsJSFunction());
3169 i::JSFunction::cast(object)->shared()->IsApiFunction());
3170 function = i::JSFunction::cast(object); 3170 function = i::JSFunction::cast(object);
3171 } else { 3171 } else {
3172 function = i::JSFunction::cast(constructor); 3172 function = i::JSFunction::cast(constructor);
3173 } 3173 }
3174 return function->context()->global_context(); 3174 return function->context()->global_context();
3175 } 3175 }
3176 3176
3177 3177
3178 Local<v8::Context> v8::Object::CreationContext() { 3178 Local<v8::Context> v8::Object::CreationContext() {
3179 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3179 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 int String::Utf8Length() const { 3614 int String::Utf8Length() const {
3615 i::Handle<i::String> str = Utils::OpenHandle(this); 3615 i::Handle<i::String> str = Utils::OpenHandle(this);
3616 if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0; 3616 if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0;
3617 return str->Utf8Length(); 3617 return str->Utf8Length();
3618 } 3618 }
3619 3619
3620 3620
3621 int String::WriteUtf8(char* buffer, 3621 int String::WriteUtf8(char* buffer,
3622 int capacity, 3622 int capacity,
3623 int* nchars_ref, 3623 int* nchars_ref,
3624 WriteHints hints) const { 3624 int options) const {
3625 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3625 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3626 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; 3626 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
3627 LOG_API(isolate, "String::WriteUtf8"); 3627 LOG_API(isolate, "String::WriteUtf8");
3628 ENTER_V8(isolate); 3628 ENTER_V8(isolate);
3629 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); 3629 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3630 i::Handle<i::String> str = Utils::OpenHandle(this); 3630 i::Handle<i::String> str = Utils::OpenHandle(this);
3631 isolate->string_tracker()->RecordWrite(str); 3631 isolate->string_tracker()->RecordWrite(str);
3632 if (hints & HINT_MANY_WRITES_EXPECTED) { 3632 if (options & HINT_MANY_WRITES_EXPECTED) {
3633 // Flatten the string for efficiency. This applies whether we are 3633 // Flatten the string for efficiency. This applies whether we are
3634 // using StringInputBuffer or Get(i) to access the characters. 3634 // using StringInputBuffer or Get(i) to access the characters.
3635 str->TryFlatten(); 3635 str->TryFlatten();
3636 } 3636 }
3637 write_input_buffer.Reset(0, *str); 3637 write_input_buffer.Reset(0, *str);
3638 int len = str->length(); 3638 int len = str->length();
3639 // Encode the first K - 3 bytes directly into the buffer since we 3639 // Encode the first K - 3 bytes directly into the buffer since we
3640 // know there's room for them. If no capacity is given we copy all 3640 // know there's room for them. If no capacity is given we copy all
3641 // of them here. 3641 // of them here.
3642 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); 3642 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
(...skipping 19 matching lines...) Expand all
3662 buffer[pos + j] = intermediate[j]; 3662 buffer[pos + j] = intermediate[j];
3663 pos += written; 3663 pos += written;
3664 nchars++; 3664 nchars++;
3665 } else { 3665 } else {
3666 // We've reached the end of the buffer 3666 // We've reached the end of the buffer
3667 break; 3667 break;
3668 } 3668 }
3669 } 3669 }
3670 } 3670 }
3671 if (nchars_ref != NULL) *nchars_ref = nchars; 3671 if (nchars_ref != NULL) *nchars_ref = nchars;
3672 if (i == len && (capacity == -1 || pos < capacity)) 3672 if (!(options & NO_NULL_TERMINATION) &&
3673 (i == len && (capacity == -1 || pos < capacity)))
3673 buffer[pos++] = '\0'; 3674 buffer[pos++] = '\0';
3674 return pos; 3675 return pos;
3675 } 3676 }
3676 3677
3677 3678
3678 int String::WriteAscii(char* buffer, 3679 int String::WriteAscii(char* buffer,
3679 int start, 3680 int start,
3680 int length, 3681 int length,
3681 WriteHints hints) const { 3682 int options) const {
3682 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3683 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3683 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; 3684 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0;
3684 LOG_API(isolate, "String::WriteAscii"); 3685 LOG_API(isolate, "String::WriteAscii");
3685 ENTER_V8(isolate); 3686 ENTER_V8(isolate);
3686 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); 3687 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3687 ASSERT(start >= 0 && length >= -1); 3688 ASSERT(start >= 0 && length >= -1);
3688 i::Handle<i::String> str = Utils::OpenHandle(this); 3689 i::Handle<i::String> str = Utils::OpenHandle(this);
3689 isolate->string_tracker()->RecordWrite(str); 3690 isolate->string_tracker()->RecordWrite(str);
3690 if (hints & HINT_MANY_WRITES_EXPECTED) { 3691 if (options & HINT_MANY_WRITES_EXPECTED) {
3691 // Flatten the string for efficiency. This applies whether we are 3692 // Flatten the string for efficiency. This applies whether we are
3692 // using StringInputBuffer or Get(i) to access the characters. 3693 // using StringInputBuffer or Get(i) to access the characters.
3693 str->TryFlatten(); 3694 str->TryFlatten();
3694 } 3695 }
3695 int end = length; 3696 int end = length;
3696 if ( (length == -1) || (length > str->length() - start) ) 3697 if ( (length == -1) || (length > str->length() - start) )
3697 end = str->length() - start; 3698 end = str->length() - start;
3698 if (end < 0) return 0; 3699 if (end < 0) return 0;
3699 write_input_buffer.Reset(start, *str); 3700 write_input_buffer.Reset(start, *str);
3700 int i; 3701 int i;
3701 for (i = 0; i < end; i++) { 3702 for (i = 0; i < end; i++) {
3702 char c = static_cast<char>(write_input_buffer.GetNext()); 3703 char c = static_cast<char>(write_input_buffer.GetNext());
3703 if (c == '\0') c = ' '; 3704 if (c == '\0') c = ' ';
3704 buffer[i] = c; 3705 buffer[i] = c;
3705 } 3706 }
3706 if (length == -1 || i < length) 3707 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length))
3707 buffer[i] = '\0'; 3708 buffer[i] = '\0';
3708 return i; 3709 return i;
3709 } 3710 }
3710 3711
3711 3712
3712 int String::Write(uint16_t* buffer, 3713 int String::Write(uint16_t* buffer,
3713 int start, 3714 int start,
3714 int length, 3715 int length,
3715 WriteHints hints) const { 3716 int options) const {
3716 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3717 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3717 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; 3718 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
3718 LOG_API(isolate, "String::Write"); 3719 LOG_API(isolate, "String::Write");
3719 ENTER_V8(isolate); 3720 ENTER_V8(isolate);
3720 ASSERT(start >= 0 && length >= -1); 3721 ASSERT(start >= 0 && length >= -1);
3721 i::Handle<i::String> str = Utils::OpenHandle(this); 3722 i::Handle<i::String> str = Utils::OpenHandle(this);
3722 isolate->string_tracker()->RecordWrite(str); 3723 isolate->string_tracker()->RecordWrite(str);
3723 if (hints & HINT_MANY_WRITES_EXPECTED) { 3724 if (options & HINT_MANY_WRITES_EXPECTED) {
3724 // Flatten the string for efficiency. This applies whether we are 3725 // Flatten the string for efficiency. This applies whether we are
3725 // using StringInputBuffer or Get(i) to access the characters. 3726 // using StringInputBuffer or Get(i) to access the characters.
3726 str->TryFlatten(); 3727 str->TryFlatten();
3727 } 3728 }
3728 int end = start + length; 3729 int end = start + length;
3729 if ((length == -1) || (length > str->length() - start) ) 3730 if ((length == -1) || (length > str->length() - start) )
3730 end = str->length(); 3731 end = str->length();
3731 if (end < 0) return 0; 3732 if (end < 0) return 0;
3732 i::String::WriteToFlat(*str, buffer, start, end); 3733 i::String::WriteToFlat(*str, buffer, start, end);
3733 if (length == -1 || end - start < length) { 3734 if (!(options & NO_NULL_TERMINATION) &&
3735 (length == -1 || end - start < length)) {
3734 buffer[end - start] = '\0'; 3736 buffer[end - start] = '\0';
3735 } 3737 }
3736 return end - start; 3738 return end - start;
3737 } 3739 }
3738 3740
3739 3741
3740 bool v8::String::IsExternal() const { 3742 bool v8::String::IsExternal() const {
3741 i::Handle<i::String> str = Utils::OpenHandle(this); 3743 i::Handle<i::String> str = Utils::OpenHandle(this);
3742 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { 3744 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) {
3743 return false; 3745 return false;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
4111 } 4113 }
4112 4114
4113 4115
4114 bool Context::InContext() { 4116 bool Context::InContext() {
4115 return i::Isolate::Current()->context() != NULL; 4117 return i::Isolate::Current()->context() != NULL;
4116 } 4118 }
4117 4119
4118 4120
4119 v8::Local<v8::Context> Context::GetEntered() { 4121 v8::Local<v8::Context> Context::GetEntered() {
4120 i::Isolate* isolate = i::Isolate::Current(); 4122 i::Isolate* isolate = i::Isolate::Current();
4121 if (IsDeadCheck(isolate, "v8::Context::GetEntered()")) { 4123 if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) {
4122 return Local<Context>(); 4124 return Local<Context>();
4123 } 4125 }
4124 i::Handle<i::Object> last = 4126 i::Handle<i::Object> last =
4125 isolate->handle_scope_implementer()->LastEnteredContext(); 4127 isolate->handle_scope_implementer()->LastEnteredContext();
4126 if (last.is_null()) return Local<Context>(); 4128 if (last.is_null()) return Local<Context>();
4127 i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); 4129 i::Handle<i::Context> context = i::Handle<i::Context>::cast(last);
4128 return Utils::ToLocal(context); 4130 return Utils::ToLocal(context);
4129 } 4131 }
4130 4132
4131 4133
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
5915 5917
5916 void Testing::SetStressRunType(Testing::StressType type) { 5918 void Testing::SetStressRunType(Testing::StressType type) {
5917 internal::Testing::set_stress_type(type); 5919 internal::Testing::set_stress_type(type);
5918 } 5920 }
5919 5921
5920 int Testing::GetStressRuns() { 5922 int Testing::GetStressRuns() {
5921 if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; 5923 if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs;
5922 #ifdef DEBUG 5924 #ifdef DEBUG
5923 // In debug mode the code runs much slower so stressing will only make two 5925 // In debug mode the code runs much slower so stressing will only make two
5924 // runs. 5926 // runs.
5925 return 2; 5927 return 5;
5926 #else 5928 #else
5927 return 5; 5929 return 5;
5928 #endif 5930 #endif
5929 } 5931 }
5930 5932
5931 5933
5932 static void SetFlagsFromString(const char* flags) { 5934 static void SetFlagsFromString(const char* flags) {
5933 V8::SetFlagsFromString(flags, i::StrLength(flags)); 5935 V8::SetFlagsFromString(flags, i::StrLength(flags));
5934 } 5936 }
5935 5937
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
6036 6038
6037 6039
6038 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6040 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6039 HandleScopeImplementer* scope_implementer = 6041 HandleScopeImplementer* scope_implementer =
6040 reinterpret_cast<HandleScopeImplementer*>(storage); 6042 reinterpret_cast<HandleScopeImplementer*>(storage);
6041 scope_implementer->IterateThis(v); 6043 scope_implementer->IterateThis(v);
6042 return storage + ArchiveSpacePerThread(); 6044 return storage + ArchiveSpacePerThread();
6043 } 6045 }
6044 6046
6045 } } // namespace v8::internal 6047 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/apinatives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698