Handle<Script> Factory::NewScript(Handle<String> source) {
- static uint32_t next_id = 1;
-
+ // Generate id for this script.
+ int id;
+ if (Heap::last_script_id()->IsUndefined()) {
+ // Script ids start from one.
+ id = 1;
+ } else {
+ // Increment id, wrap when positive smi is exhausted.
+ id = Smi::cast(Heap::last_script_id())->value();
+ id++;
+ if (!Smi::IsValid(id)) {
+ id = 0;
+ }
+ }
+ Heap::SetLastScriptId(Smi::FromInt(id));
+
+ // Create and initialize script object.
Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
script->set_source(*source);
script->set_name(Heap::undefined_value());
- script->set_id(*Factory::NewNumberFromUint(next_id++));
+ script->set_id(Heap::last_script_id());
script->set_line_offset(Smi::FromInt(0));
script->set_column_offset(Smi::FromInt(0));
script->set_type(Smi::FromInt(SCRIPT_TYPE_NORMAL));
script->set_wrapper(*Factory::NewProxy(0, TENURED));
script->set_line_ends(Heap::undefined_value());
+
return script;
}
}
+void Heap::SetLastScriptId(Object* last_script_id) {
+ last_script_id_ = last_script_id;
+}
+
+
#define GC_GREEDY_CHECK() \
ASSERT(!FLAG_gc_greedy || v8::internal::Heap::GarbageCollectionGreedyCheck())
if (obj->IsFailure()) return false;
natives_source_cache_ = FixedArray::cast(obj);
+ // Handling of script id generation is in Factory::NewScript.
+ last_script_id_ = undefined_value();
+
// Initialize keyed lookup cache.
ClearKeyedLookupCache();
V(FixedArray, number_string_cache) \
V(FixedArray, single_character_string_cache) \
V(FixedArray, natives_source_cache) \
- V(Object, keyed_lookup_cache)
+ V(Object, keyed_lookup_cache) \
+ V(Object, last_script_id)
#define ROOT_LIST(V) \
static inline void SetKeyedLookupCache(LookupCache* cache);
static inline void ClearKeyedLookupCache();
+ // Update the next script id.
+ static inline void SetLastScriptId(Object* last_script_id);
+
#ifdef DEBUG
static void Print();
static void PrintHandles();
assertEquals('scriptName', response.body.type, json_response);
} else {
assertEquals('scriptId', response.body.type, json_response);
- print(response.body.script_id);
}
} else {
assertFalse(response.success, json_response);