Fix exception scope verification failures in JSC profiler files.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Nov 2016 20:52:05 +0000 (20:52 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Nov 2016 20:52:05 +0000 (20:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164971

Reviewed by Saam Barati.

* profiler/ProfilerBytecodeSequence.cpp:
(JSC::Profiler::BytecodeSequence::addSequenceProperties):
* profiler/ProfilerCompilation.cpp:
(JSC::Profiler::Compilation::toJS):
* profiler/ProfilerDatabase.cpp:
(JSC::Profiler::Database::toJS):
(JSC::Profiler::Database::toJSON):
* profiler/ProfilerOSRExitSite.cpp:
(JSC::Profiler::OSRExitSite::toJS):
* profiler/ProfilerOriginStack.cpp:
(JSC::Profiler::OriginStack::toJS):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208968 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp
Source/JavaScriptCore/profiler/ProfilerCompilation.cpp
Source/JavaScriptCore/profiler/ProfilerDatabase.cpp
Source/JavaScriptCore/profiler/ProfilerOSRExitSite.cpp
Source/JavaScriptCore/profiler/ProfilerOriginStack.cpp

index f0c6bb4..c844bf5 100644 (file)
@@ -1,3 +1,22 @@
+2016-11-18  Mark Lam  <mark.lam@apple.com>
+
+        Fix exception scope verification failures in JSC profiler files.
+        https://bugs.webkit.org/show_bug.cgi?id=164971
+
+        Reviewed by Saam Barati.
+
+        * profiler/ProfilerBytecodeSequence.cpp:
+        (JSC::Profiler::BytecodeSequence::addSequenceProperties):
+        * profiler/ProfilerCompilation.cpp:
+        (JSC::Profiler::Compilation::toJS):
+        * profiler/ProfilerDatabase.cpp:
+        (JSC::Profiler::Database::toJS):
+        (JSC::Profiler::Database::toJSON):
+        * profiler/ProfilerOSRExitSite.cpp:
+        (JSC::Profiler::OSRExitSite::toJS):
+        * profiler/ProfilerOriginStack.cpp:
+        (JSC::Profiler::OriginStack::toJS):
+
 2016-11-22  Mark Lam  <mark.lam@apple.com>
 
         Fix exception scope verification failures in JSONObject.cpp.
index 0470a37..09b8213 100644 (file)
@@ -82,14 +82,18 @@ void BytecodeSequence::addSequenceProperties(ExecState* exec, JSObject* result)
     auto scope = DECLARE_THROW_SCOPE(vm);
     JSArray* header = constructEmptyArray(exec, 0);
     RETURN_IF_EXCEPTION(scope, void());
-    for (unsigned i = 0; i < m_header.size(); ++i)
+    for (unsigned i = 0; i < m_header.size(); ++i) {
         header->putDirectIndex(exec, i, jsString(exec, String::fromUTF8(m_header[i])));
+        RETURN_IF_EXCEPTION(scope, void());
+    }
     result->putDirect(vm, exec->propertyNames().header, header);
     
     JSArray* sequence = constructEmptyArray(exec, 0);
     RETURN_IF_EXCEPTION(scope, void());
-    for (unsigned i = 0; i < m_sequence.size(); ++i)
+    for (unsigned i = 0; i < m_sequence.size(); ++i) {
         sequence->putDirectIndex(exec, i, m_sequence[i].toJS(exec));
+        RETURN_IF_EXCEPTION(scope, void());
+    }
     result->putDirect(vm, exec->propertyNames().bytecode, sequence);
 }
 
index 3d37446..255f831 100644 (file)
@@ -117,42 +117,60 @@ JSValue Compilation::toJS(ExecState* exec) const
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
     JSObject* result = constructEmptyObject(exec);
-    RETURN_IF_EXCEPTION(scope, JSValue());
+    RETURN_IF_EXCEPTION(scope, { });
     result->putDirect(vm, exec->propertyNames().bytecodesID, jsNumber(m_bytecodes->id()));
     result->putDirect(vm, exec->propertyNames().compilationKind, jsString(exec, String::fromUTF8(toCString(m_kind))));
     
     JSArray* profiledBytecodes = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_profiledBytecodes.size(); ++i)
-        profiledBytecodes->putDirectIndex(exec, i, m_profiledBytecodes[i].toJS(exec));
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_profiledBytecodes.size(); ++i) {
+        auto value = m_profiledBytecodes[i].toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        profiledBytecodes->putDirectIndex(exec, i, value);
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().profiledBytecodes, profiledBytecodes);
     
     JSArray* descriptions = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_descriptions.size(); ++i)
-        descriptions->putDirectIndex(exec, i, m_descriptions[i].toJS(exec));
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_descriptions.size(); ++i) {
+        auto value = m_descriptions[i].toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        descriptions->putDirectIndex(exec, i, value);
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().descriptions, descriptions);
     
     JSArray* counters = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
+    RETURN_IF_EXCEPTION(scope, { });
     for (auto it = m_counters.begin(), end = m_counters.end(); it != end; ++it) {
         JSObject* counterEntry = constructEmptyObject(exec);
-        counterEntry->putDirect(vm, exec->propertyNames().origin, it->key.toJS(exec));
+        RETURN_IF_EXCEPTION(scope, { });
+        auto value = it->key.toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        counterEntry->putDirect(vm, exec->propertyNames().origin, value);
         counterEntry->putDirect(vm, exec->propertyNames().executionCount, jsNumber(it->value->count()));
         counters->push(exec, counterEntry);
+        RETURN_IF_EXCEPTION(scope, { });
     }
     result->putDirect(vm, exec->propertyNames().counters, counters);
     
     JSArray* exitSites = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_osrExitSites.size(); ++i)
-        exitSites->putDirectIndex(exec, i, m_osrExitSites[i].toJS(exec));
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_osrExitSites.size(); ++i) {
+        auto value = m_osrExitSites[i].toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        exitSites->putDirectIndex(exec, i, value);
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().osrExitSites, exitSites);
     
     JSArray* exits = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_osrExits.size(); ++i)
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_osrExits.size(); ++i) {
         exits->putDirectIndex(exec, i, m_osrExits[i].toJS(exec));
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().osrExits, exits);
     
     result->putDirect(vm, exec->propertyNames().numInlinedGetByIds, jsNumber(m_numInlinedGetByIds));
index 2bf411f..8ed9f18 100644 (file)
@@ -104,21 +104,33 @@ JSValue Database::toJS(ExecState* exec) const
     JSObject* result = constructEmptyObject(exec);
     
     JSArray* bytecodes = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_bytecodes.size(); ++i)
-        bytecodes->putDirectIndex(exec, i, m_bytecodes[i].toJS(exec));
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_bytecodes.size(); ++i) {
+        auto value = m_bytecodes[i].toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        bytecodes->putDirectIndex(exec, i, value);
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().bytecodes, bytecodes);
     
     JSArray* compilations = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_compilations.size(); ++i)
-        compilations->putDirectIndex(exec, i, m_compilations[i]->toJS(exec));
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_compilations.size(); ++i) {
+        auto value = m_compilations[i]->toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        compilations->putDirectIndex(exec, i, value);
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().compilations, compilations);
     
     JSArray* events = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_events.size(); ++i)
-        events->putDirectIndex(exec, i, m_events[i].toJS(exec));
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_events.size(); ++i) {
+        auto value = m_events[i].toJS(exec);
+        RETURN_IF_EXCEPTION(scope, { });
+        events->putDirectIndex(exec, i, value);
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     result->putDirect(vm, exec->propertyNames().events, events);
     
     return result;
@@ -126,10 +138,14 @@ JSValue Database::toJS(ExecState* exec) const
 
 String Database::toJSON() const
 {
+    auto scope = DECLARE_THROW_SCOPE(m_vm);
     JSGlobalObject* globalObject = JSGlobalObject::create(
         m_vm, JSGlobalObject::createStructure(m_vm, jsNull()));
-    
-    return JSONStringify(globalObject->globalExec(), toJS(globalObject->globalExec()), 0);
+
+    auto value = toJS(globalObject->globalExec());
+    RETURN_IF_EXCEPTION(scope, String());
+    scope.release();
+    return JSONStringify(globalObject->globalExec(), value, 0);
 }
 
 bool Database::save(const char* filename) const
index 0187ed9..8b5568f 100644 (file)
@@ -39,9 +39,11 @@ JSValue OSRExitSite::toJS(ExecState* exec) const
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
     JSArray* result = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
-    for (unsigned i = 0; i < m_codeAddresses.size(); ++i)
+    RETURN_IF_EXCEPTION(scope, { });
+    for (unsigned i = 0; i < m_codeAddresses.size(); ++i) {
         result->putDirectIndex(exec, i, jsString(exec, toString(RawPointer(m_codeAddresses[i]))));
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     return result;
 }
 
index fcf00e4..61dfb63 100644 (file)
@@ -103,10 +103,12 @@ JSValue OriginStack::toJS(ExecState* exec) const
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
     JSArray* result = constructEmptyArray(exec, 0);
-    RETURN_IF_EXCEPTION(scope, JSValue());
+    RETURN_IF_EXCEPTION(scope, { });
     
-    for (unsigned i = 0; i < m_stack.size(); ++i)
+    for (unsigned i = 0; i < m_stack.size(); ++i) {
         result->putDirectIndex(exec, i, m_stack[i].toJS(exec));
+        RETURN_IF_EXCEPTION(scope, { });
+    }
     
     return result;
 }