Chromium Code Reviews| Index: src/api.cc |
| diff --git a/src/api.cc b/src/api.cc |
| index f259c1c4067faf8d71cdddca9de1cef93fea159b..0d7bda2ead08cdcf82ac610c578f76c48d7185f9 100644 |
| --- a/src/api.cc |
| +++ b/src/api.cc |
| @@ -969,6 +969,9 @@ static void InitializeFunctionTemplate( |
| info->set_flag(0); |
| } |
| +static Local<ObjectTemplate> ObjectTemplateNew( |
| + i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, |
| + bool do_not_cache); |
| Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
| i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
| @@ -976,8 +979,9 @@ Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
| i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), |
| i_isolate); |
| if (result->IsUndefined()) { |
| - v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(i_isolate); |
| - result = Utils::OpenHandle(*ObjectTemplate::New(isolate)); |
| + // Do not cache prototype objects. |
| + result = Utils::OpenHandle( |
| + *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true)); |
| Utils::OpenHandle(this)->set_prototype_template(*result); |
| } |
| return ToApiHandle<ObjectTemplate>(result); |
| @@ -1227,9 +1231,9 @@ Local<ObjectTemplate> ObjectTemplate::New() { |
| return New(i::Isolate::Current(), Local<FunctionTemplate>()); |
| } |
| - |
| -Local<ObjectTemplate> ObjectTemplate::New( |
| - i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { |
| +static Local<ObjectTemplate> ObjectTemplateNew( |
| + i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, |
| + bool do_not_cache) { |
| // Changes to the environment cannot be captured in the snapshot. Expect no |
| // object templates when the isolate is created for serialization. |
| DCHECK(!isolate->serializer_enabled()); |
| @@ -1240,12 +1244,22 @@ Local<ObjectTemplate> ObjectTemplate::New( |
| i::Handle<i::ObjectTemplateInfo> obj = |
| i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| + int next_serial_number = 0; |
| + if (!do_not_cache) { |
| + next_serial_number = isolate->next_serial_number() + 1; |
| + isolate->set_next_serial_number(next_serial_number); |
| + } |
| + obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
| if (!constructor.IsEmpty()) |
| obj->set_constructor(*Utils::OpenHandle(*constructor)); |
| obj->set_internal_field_count(i::Smi::FromInt(0)); |
| return Utils::ToLocal(obj); |
| } |
| +Local<ObjectTemplate> ObjectTemplate::New( |
| + i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { |
| + return ObjectTemplateNew(isolate, constructor, false); |
| +} |
| // Ensure that the object template has a constructor. If no |
| // constructor is available we create one. |
| @@ -1277,7 +1291,7 @@ static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| i::Isolate* isolate, |
| ObjectTemplate* object_template) { |
| - EnsureConstructor(isolate, object_template); |
| + // EnsureConstructor(isolate, object_template); |
|
Toon Verwaest
2016/01/29 14:37:45
You can now get rid of this function I presume, gi
Igor Sheludko
2016/02/01 20:43:55
Done.
|
| return Utils::OpenHandle(object_template); |
| } |
| @@ -3306,16 +3320,14 @@ double Value::NumberValue() const { |
| Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { |
| auto obj = Utils::OpenHandle(this); |
| - i::Handle<i::Object> num; |
| if (obj->IsNumber()) { |
| - num = obj; |
| - } else { |
| - PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); |
| - has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num); |
| - RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); |
| + return Just(NumberToInt64(*obj)); |
| } |
| - return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value()) |
| - : static_cast<int64_t>(num->Number())); |
| + PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); |
| + i::Handle<i::Object> num; |
| + has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num); |
| + RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); |
| + return Just(NumberToInt64(*num)); |
| } |