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

Side by Side Diff: src/api.cc

Issue 1294583006: Clean up native context slots and add new ones. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 2795 matching lines...) Expand 10 before | Expand all | Expand 10 after
2806 double value = obj->Number(); 2806 double value = obj->Number();
2807 return !i::IsMinusZero(value) && 2807 return !i::IsMinusZero(value) &&
2808 value >= 0 && 2808 value >= 0 &&
2809 value <= i::kMaxUInt32 && 2809 value <= i::kMaxUInt32 &&
2810 value == i::FastUI2D(i::FastD2UI(value)); 2810 value == i::FastUI2D(i::FastD2UI(value));
2811 } 2811 }
2812 return false; 2812 return false;
2813 } 2813 }
2814 2814
2815 2815
2816 static bool CheckConstructor(i::Isolate* isolate,
2817 i::Handle<i::JSObject> obj,
2818 const char* class_name) {
2819 i::Handle<i::Object> constr(obj->map()->GetConstructor(), isolate);
2820 if (!constr->IsJSFunction()) return false;
2821 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(constr);
2822 return func->shared()->native() && constr.is_identical_to(
2823 i::Object::GetProperty(isolate,
2824 isolate->js_builtins_object(),
2825 class_name).ToHandleChecked());
2826 }
2827
2828
2829 bool Value::IsNativeError() const { 2816 bool Value::IsNativeError() const {
2830 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2817 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2831 if (obj->IsJSObject()) { 2818 if (!obj->IsJSObject()) return false;
2832 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); 2819 i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
2833 i::Isolate* isolate = js_obj->GetIsolate(); 2820 i::Isolate* isolate = js_obj->GetIsolate();
2834 return CheckConstructor(isolate, js_obj, "$Error") || 2821 i::Handle<i::Object> constructor(js_obj->map()->GetConstructor(), isolate);
2835 CheckConstructor(isolate, js_obj, "$EvalError") || 2822 if (!constructor->IsJSFunction()) return false;
2836 CheckConstructor(isolate, js_obj, "$RangeError") || 2823 i::Handle<i::JSFunction> function =
2837 CheckConstructor(isolate, js_obj, "$ReferenceError") || 2824 i::Handle<i::JSFunction>::cast(constructor);
2838 CheckConstructor(isolate, js_obj, "$SyntaxError") || 2825 if (!function->shared()->native()) return false;
2839 CheckConstructor(isolate, js_obj, "$TypeError") || 2826 return function.is_identical_to(isolate->error_function()) ||
2840 CheckConstructor(isolate, js_obj, "$URIError"); 2827 function.is_identical_to(isolate->eval_error_function()) ||
2841 } else { 2828 function.is_identical_to(isolate->range_error_function()) ||
2842 return false; 2829 function.is_identical_to(isolate->reference_error_function()) ||
2843 } 2830 function.is_identical_to(isolate->syntax_error_function()) ||
2831 function.is_identical_to(isolate->type_error_function()) ||
2832 function.is_identical_to(isolate->uri_error_function());
2844 } 2833 }
2845 2834
2846 2835
2847 bool Value::IsRegExp() const { 2836 bool Value::IsRegExp() const {
2848 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2837 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2849 return obj->IsJSRegExp(); 2838 return obj->IsJSRegExp();
2850 } 2839 }
2851 2840
2852 2841
2853 bool Value::IsGeneratorFunction() const { 2842 bool Value::IsGeneratorFunction() const {
(...skipping 4779 matching lines...) Expand 10 before | Expand all | Expand 10 after
7633 str_ = i::NewArray<uint16_t>(length_ + 1); 7622 str_ = i::NewArray<uint16_t>(length_ + 1);
7634 str->Write(str_); 7623 str->Write(str_);
7635 } 7624 }
7636 7625
7637 7626
7638 String::Value::~Value() { 7627 String::Value::~Value() {
7639 i::DeleteArray(str_); 7628 i::DeleteArray(str_);
7640 } 7629 }
7641 7630
7642 7631
7643 #define DEFINE_ERROR(NAME) \ 7632 #define DEFINE_ERROR(NAME, name) \
7644 Local<Value> Exception::NAME(v8::Local<v8::String> raw_message) { \ 7633 Local<Value> Exception::NAME(v8::Local<v8::String> raw_message) { \
7645 i::Isolate* isolate = i::Isolate::Current(); \ 7634 i::Isolate* isolate = i::Isolate::Current(); \
7646 LOG_API(isolate, #NAME); \ 7635 LOG_API(isolate, #NAME); \
7647 ENTER_V8(isolate); \ 7636 ENTER_V8(isolate); \
7648 i::Object* error; \ 7637 i::Object* error; \
7649 { \ 7638 { \
7650 i::HandleScope scope(isolate); \ 7639 i::HandleScope scope(isolate); \
7651 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \ 7640 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \
7652 error = *isolate->factory()->NewError("$" #NAME, message); \ 7641 i::Handle<i::JSFunction> constructor = isolate->name##_function(); \
7653 } \ 7642 error = *isolate->factory()->NewError(constructor, message); \
7654 i::Handle<i::Object> result(error, isolate); \ 7643 } \
7655 return Utils::ToLocal(result); \ 7644 i::Handle<i::Object> result(error, isolate); \
7645 return Utils::ToLocal(result); \
7656 } 7646 }
7657 7647
7658 DEFINE_ERROR(RangeError) 7648 DEFINE_ERROR(RangeError, range_error)
7659 DEFINE_ERROR(ReferenceError) 7649 DEFINE_ERROR(ReferenceError, reference_error)
7660 DEFINE_ERROR(SyntaxError) 7650 DEFINE_ERROR(SyntaxError, syntax_error)
7661 DEFINE_ERROR(TypeError) 7651 DEFINE_ERROR(TypeError, type_error)
7662 DEFINE_ERROR(Error) 7652 DEFINE_ERROR(Error, error)
7663 7653
7664 #undef DEFINE_ERROR 7654 #undef DEFINE_ERROR
7665 7655
7666 7656
7667 Local<Message> Exception::CreateMessage(Local<Value> exception) { 7657 Local<Message> Exception::CreateMessage(Local<Value> exception) {
7668 i::Handle<i::Object> obj = Utils::OpenHandle(*exception); 7658 i::Handle<i::Object> obj = Utils::OpenHandle(*exception);
7669 if (!obj->IsHeapObject()) return Local<Message>(); 7659 if (!obj->IsHeapObject()) return Local<Message>();
7670 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 7660 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
7671 ENTER_V8(isolate); 7661 ENTER_V8(isolate);
7672 i::HandleScope scope(isolate); 7662 i::HandleScope scope(isolate);
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
8455 Address callback_address = 8445 Address callback_address =
8456 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8446 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8457 VMState<EXTERNAL> state(isolate); 8447 VMState<EXTERNAL> state(isolate);
8458 ExternalCallbackScope call_scope(isolate, callback_address); 8448 ExternalCallbackScope call_scope(isolate, callback_address);
8459 callback(info); 8449 callback(info);
8460 } 8450 }
8461 8451
8462 8452
8463 } // namespace internal 8453 } // namespace internal
8464 } // namespace v8 8454 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698