<commit_before>/*******************************************************************************
 * Copyright (c) 2007 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.debug.internal.core.vm.js;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.debug.DebugFrame;
import org.mozilla.javascript.debug.DebuggableScript;
import org.mozilla.javascript.debug.Debugger;

/**
 * JsUtil
 */
public class JsUtil
{

	private JsUtil( )
	{
	}

	public static boolean checkBreakable( String source, int lineNumber )
	{
		return BreakableSourceChecker.check( source, lineNumber );
	}
}

class BreakableSourceChecker implements Debugger
{

	static boolean check( String source, int lineNumber )
	{
		Context cx = Context.enter( );

		Debugger oldDebugger = cx.getDebugger( );
		Object oldContext = cx.getDebuggerContextData( );
		boolean oldGenerate = cx.isGeneratingDebug( );
		int oldLevel = cx.getOptimizationLevel( );

		try
		{
			BreakableSourceChecker checker = new BreakableSourceChecker( );
			checker.lineNumber = lineNumber + 1;

			cx.setDebugger( checker, null );
			cx.setGeneratingDebug( true );
			cx.setOptimizationLevel( -1 );

			cx.compileString( source, "<check>", 1, null ); //$NON-NLS-1$

			return checker.breakable;
		}
		finally
		{
			cx.setDebugger( oldDebugger, oldContext );
			cx.setGeneratingDebug( oldGenerate );
			cx.setOptimizationLevel( oldLevel );

			Context.exit( );
		}
	}

	int lineNumber;
	boolean breakable;

	public DebugFrame getFrame( Context arg0, DebuggableScript arg1 )
	{
		return null;
	}

	public void handleCompilationDone( Context arg0, DebuggableScript arg1,
			String arg2 )
	{
		if ( !arg1.isTopLevel( ) )
		{
			return;<commit_msg>- Bugzilla Bug (s) Resolved: 223610 - Description: catch all exception when do breakable check.<commit_after>/*******************************************************************************
 * Copyright (c) 2007 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.debug.internal.core.vm.js;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.debug.DebugFrame;
import org.mozilla.javascript.debug.DebuggableScript;
import org.mozilla.javascript.debug.Debugger;

/**
 * JsUtil
 */
public class JsUtil
{

	private JsUtil( )
	{
	}

	public static boolean checkBreakable( String source, int lineNumber )
	{
		return BreakableSourceChecker.check( source, lineNumber );
	}
}

class BreakableSourceChecker implements Debugger
{

	static boolean check( String source, int lineNumber )
	{
		Context cx = Context.enter( );

		Debugger oldDebugger = cx.getDebugger( );
		Object oldContext = cx.getDebuggerContextData( );
		boolean oldGenerate = cx.isGeneratingDebug( );
		int oldLevel = cx.getOptimizationLevel( );

		try
		{
			BreakableSourceChecker checker = new BreakableSourceChecker( );
			checker.lineNumber = lineNumber + 1;

			cx.setDebugger( checker, null );
			cx.setGeneratingDebug( true );
			cx.setOptimizationLevel( -1 );

			cx.compileString( source, "<check>", 1, null ); //$NON-NLS-1$

			return checker.breakable;
		}
		catch ( Exception e )
		{
			return false;
		}
		finally
		{
			cx.setDebugger( oldDebugger, oldContext );
			cx.setGeneratingDebug( oldGenerate );
			cx.setOptimizationLevel( oldLevel );

			Context.exit( );
		}
	}

	int lineNumber;
	boolean breakable;

	public DebugFrame getFrame( Context arg0, DebuggableScript arg1 )
	{
		return null;
	}

	public void handleCompilationDone( Context arg0, DebuggableScript arg1,
			String arg2 )
	{
		if ( !arg1.isTopLevel( ) )
		{
			return;
{'fraction_non_alphanumeric': 0.16501498041023277, 'fraction_numerical': 0.009679649688868404, 'mean_word_length': 4.3316953316953315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5457266', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1255, 'n_words': 325}