Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions user/src/com/google/gwt/core/client/impl/Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
*/
public final class Impl {

static {
if (GWT.isScript() && StackTraceCreator.collector != null) {
// Just enforces loading of StackTraceCreator early on, nothing else to do here...
}
}

private static final int WATCHDOG_ENTRY_DEPTH_CHECK_INTERVAL_MS = 2000;

/**
Expand Down
25 changes: 5 additions & 20 deletions user/src/com/google/gwt/core/client/impl/StackTraceCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ abstract static class Collector {
* This legacy {@link Collector} simply crawls <code>arguments.callee.caller</code> for browsers
* that doesn't support {@code Error.stack} property.
*/
@Deprecated
static class CollectorLegacy extends Collector {

@Override
Expand Down Expand Up @@ -306,11 +307,11 @@ public StackTraceElement[] getStackTrace(Object ignored) {
* Collect necessary information to construct stack trace trace later in time.
*/
public static void captureStackTrace(Object error) {
collector.collect(error);
getCollector().collect(error);
}

public static StackTraceElement[] constructJavaStackTrace(Throwable thrown) {
StackTraceElement[] stackTrace = collector.getStackTrace(thrown);
StackTraceElement[] stackTrace = getCollector().getStackTrace(thrown);
return dropInternalFrames(stackTrace);
}

Expand Down Expand Up @@ -338,26 +339,10 @@ private static <T> void splice(Object[] arr, int length) {
}
}

// Visible for testing
static final Collector collector;

static {
// Ensure old Safari falls back to legacy Collector implementation.
boolean enforceLegacy = !supportsErrorStack();
Collector c = GWT.create(Collector.class);
collector = (c instanceof CollectorModern && enforceLegacy) ? new CollectorLegacy() : c;
static Collector getCollector() {
return GWT.create(Collector.class);
}

private static native boolean supportsErrorStack() /*-{
// Error.stackTraceLimit is cheaper to check and available in both IE and Chrome
if (Error.stackTraceLimit > 0) {
$wnd.Error.stackTraceLimit = Error.stackTraceLimit = 64;
return true;
}

return "stack" in new Error();
}-*/;

private static native JsArrayString getFnStack(Object e) /*-{
return (e && e["fnStack"]) ? e["fnStack"] : [];
}-*/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected String[] getTraceJse(Object thrown) {

@Override
public void testCollectorType() {
assertTrue(StackTraceCreator.collector instanceof StackTraceCreator.CollectorEmulated);
assertTrue(StackTraceCreator.getCollector() instanceof StackTraceCreator.CollectorEmulated);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static com.google.gwt.core.client.impl.StackTraceExamples.TYPE_ERROR;

import com.google.gwt.core.client.impl.StackTraceCreator.CollectorLegacy;
import com.google.gwt.core.client.impl.StackTraceCreator.CollectorModern;
import com.google.gwt.junit.DoNotRunWith;
import com.google.gwt.junit.Platform;
Expand Down Expand Up @@ -49,7 +48,7 @@ protected String[] getTraceJava() {
@Override
protected String[] getTraceRecursion() {
// First two frames are optional as they are automatically stripped by EDGE.
final String[] expectedModern = {
return new String[]{
"?" + Impl.getNameOf("@java.lang.Throwable::new(Ljava/lang/String;)"),
"?" + Impl.getNameOf("@java.lang.Exception::new(Ljava/lang/String;)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::throwException2(*)"),
Expand All @@ -62,16 +61,6 @@ protected String[] getTraceRecursion() {
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::getLiveException(*)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceTestBase::testTraceRecursion()"),
};

final String[] expectedLegacy = {
Impl.getNameOf("@java.lang.Throwable::new(Ljava/lang/String;)"),
Impl.getNameOf("@java.lang.Exception::new(Ljava/lang/String;)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::throwException2(*)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::throwException1(*)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::throwRecursive(*)"),
};

return isLegacyCollector() ? expectedLegacy : expectedModern;
}

@Override
Expand All @@ -87,12 +76,6 @@ protected String[] getTraceJse(Object thrown) {
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceTestBase::assertJse(*)"),
};

final String[] limited_wrap = {
Impl.getNameOf("@com.google.gwt.lang.Exceptions::toJava(*)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::getLiveException(*)"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceTestBase::assertJse(*)"),
};

final String[] limited_fillInStackTrace = {
Impl.getNameOf("@java.lang.Throwable::fillInStackTrace()"),
Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::getLiveException(*)"),
Expand All @@ -101,28 +84,14 @@ protected String[] getTraceJse(Object thrown) {

// For legacy browsers and non-error javascript exceptions (e.g. throw "string"), we can only
// construct stack trace from the catch block and below.
return isLegacyCollector()
? limited_wrap : (thrown != TYPE_ERROR ? limited_fillInStackTrace : full);
return thrown != TYPE_ERROR ? limited_fillInStackTrace : full;
}

public void testCollectorType() {
if (isSafari5()) {
assertTrue(isLegacyCollector());
} else {
assertTrue(isModernCollector());
}
}

private static boolean isLegacyCollector() {
return StackTraceCreator.collector instanceof CollectorLegacy;
assertTrue(isModernCollector());
}

private static boolean isModernCollector() {
return StackTraceCreator.collector instanceof CollectorModern;
return StackTraceCreator.getCollector() instanceof CollectorModern;
}

private static native boolean isSafari5() /*-{
return navigator.userAgent.match(' Safari/') && !navigator.userAgent.match(' Chrom')
&& !!navigator.userAgent.match(' Version/5.');
}-*/;
}
Loading