Index: includes/batch.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/batch.inc,v
retrieving revision 1.26
diff -u -p -r1.26 batch.inc
--- includes/batch.inc	22 Oct 2008 19:39:36 -0000	1.26
+++ includes/batch.inc	25 Oct 2008 01:18:04 -0000
@@ -84,7 +84,7 @@ function _batch_progress_page_js() {
   // error messages. Only safe strings should be passed in to batch_set().
   $current_set = _batch_current_set();
   drupal_set_title($current_set['title'], PASS_THROUGH);
-  drupal_add_js('misc/progress.js', array('type' => 'core', 'cache' => FALSE));
+  drupal_add_js('misc/progress.js', array('weight' => JS_WEIGHT_CORE, 'cache' => FALSE));
 
   $url = url($batch['url'], array('query' => array('id' => $batch['id'])));
   $js_setting = array(
@@ -95,7 +95,7 @@ function _batch_progress_page_js() {
     ),
   );
   drupal_add_js($js_setting, 'setting');
-  drupal_add_js('misc/batch.js', array('type' => 'core', 'cache' => FALSE));
+  drupal_add_js('misc/batch.js', array('weight' => JS_WEIGHT_CORE, 'cache' => FALSE));
 
   $output = '<div id="progress"></div>';
   return $output;
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.810
diff -u -p -r1.810 common.inc
--- includes/common.inc	22 Oct 2008 19:39:36 -0000	1.810
+++ includes/common.inc	25 Oct 2008 01:18:06 -0000
@@ -25,6 +25,26 @@ define('SAVED_UPDATED', 2);
 define('SAVED_DELETED', 3);
 
 /**
+ * The weight of JavaScript libraries being added to the page.
+ */
+define('JS_WEIGHT_LIBRARY', -100);
+
+/**
+ * The weight of core JavaScript code being added to the page.
+ */
+define('JS_WEIGHT_CORE', -20);
+
+/**
+ * The weight of module JavaScript code being added to the page.
+ */
+define('JS_WEIGHT_MODULE', 0);
+
+/**
+ * The weight of theme JavaScript code being added to the page.
+ */
+define('JS_WEIGHT_THEME', 20);
+
+/**
  * Set content for a specified region.
  *
  * @param $region
@@ -2030,7 +2050,7 @@ function drupal_clear_css_cache() {
  * reference to an existing file or as inline code. The following actions can be
  * performed using this function:
  *
- * - Add a file ('core', 'module' and 'theme'):
+ * - Add a file ('file'):
  *   Adds a reference to a JavaScript file to the page. JavaScript files
  *   are placed in a certain order, from 'core' first, to 'module' and finally
  *   'theme' so that files, that are added later, can override previously added
@@ -2049,7 +2069,7 @@ function drupal_clear_css_cache() {
  * Examples:
  * @code
  *   drupal_add_js('misc/collapse.js');
- *   drupal_add_js('misc/collapse.js', 'module');
+ *   drupal_add_js('misc/collapse.js', 'file');
  *   drupal_add_js('$(document).ready(function(){alert("Hello!");});',
  *     array('type' => 'inline', 'scope' => 'footer')
  *   );
@@ -2057,7 +2077,7 @@ function drupal_clear_css_cache() {
  *
  * @param $data
  *   (optional) If given, the value depends on the $options parameter:
- *   - 'core', 'module' or 'theme': Path to the file relative to base_path().
+ *   - 'file': Path to the file relative to base_path().
  *   - 'inline': The JavaScript code that should be placed in the given scope.
  *   - 'setting': An array with configuration options as associative array. The
  *       array is directly placed in Drupal.settings. You might want to wrap your
@@ -2065,17 +2085,18 @@ function drupal_clear_css_cache() {
  *       of the Drupal.settings namespace.
  * @param $options
  *   (optional) A string defining the type of JavaScript that is being added
- *   in the $data parameter ('core', 'module', 'theme', 'setting', 'inline'),
- *   or an array which can have any or all of the following keys (these are
- *   not valid with type => 'setting'):
+ *   in the $data parameter ('file', 'setting', 'inline'), or an array which
+ *   can have any or all of the following keys (these are not valid when the
+ *   type is 'setting'):
  *   - type
  *       The type of JavaScript that should be added to the page. Allowed
- *       values are 'core', 'module', 'theme', 'inline' and 'setting'. Defaults
- *       to 'module'.
+ *       values are 'file', 'inline' and 'setting'. Defaults to 'file'.
  *   - scope
  *       The location in which you want to place the script. Possible
  *       values are 'header' and 'footer'. If your theme implements different
  *       locations, however, you can also use these. Defaults to 'header'.
+ *   - weight
+ *       Defines the order in which the JavaScript is added to the page.
  *   - defer
  *       If set to TRUE, the defer attribute is set on the <script> tag.
  *       Defaults to FALSE. This parameter is not used with 'type' => 'setting'.
@@ -2105,12 +2126,13 @@ function drupal_add_js($data = NULL, $op
     $options = array();
   }
   $options += array(
-    'type' => 'module',
+    'type' => 'file',
+    'weight' => JS_WEIGHT_MODULE,
     // Default to a header scope only if we're adding some data.
     'scope' => isset($data) ? 'header' : NULL,
     'cache' => TRUE, 
     'defer' => FALSE,
-    'preprocess' => TRUE
+    'preprocess' => TRUE,
   );
   // Preprocess can only be set if caching is enabled.
   $options['preprocess'] = $options['cache'] ? $options['preprocess'] : FALSE;
@@ -2129,12 +2151,20 @@ function drupal_add_js($data = NULL, $op
     if (empty($javascript)) {
       $javascript = array(
         'header' => array(
-          'core' => array(
-            'misc/jquery.js' => array('cache' => TRUE, 'defer' => FALSE, 'preprocess' => TRUE),
-            'misc/drupal.js' => array('cache' => TRUE, 'defer' => FALSE, 'preprocess' => TRUE),
+          'file' => array(
+            JS_WEIGHT_LIBRARY => array(
+              'misc/jquery.js' => array(
+                'cache' => TRUE,
+                'defer' => FALSE,
+                'preprocess' => TRUE
+              ),
+              'misc/drupal.js' => array(
+                'cache' => TRUE,
+                'defer' => FALSE,
+                'preprocess' => TRUE
+              ),
+            ),
           ),
-          'module' => array(),
-          'theme' => array(),
           'setting' => array(
             array('basePath' => base_path()),
           ),
@@ -2144,7 +2174,7 @@ function drupal_add_js($data = NULL, $op
     }
 
     if (isset($scope) && !isset($javascript[$scope])) {
-      $javascript[$scope] = array('core' => array(), 'module' => array(), 'theme' => array(), 'setting' => array(), 'inline' => array());
+      $javascript[$scope] = array('file' => array(), 'setting' => array(), 'inline' => array());
     }
 
     if (isset($type) && isset($scope) && !isset($javascript[$scope][$type])) {
@@ -2156,10 +2186,14 @@ function drupal_add_js($data = NULL, $op
         $javascript[$scope][$type][] = $data;
         break;
       case 'inline':
-        $javascript[$scope][$type][] = array('code' => $data, 'defer' => $options['defer']);
+        $javascript[$scope][$type][$options['weight']][] = array('code' => $data, 'defer' => $options['defer']);
+        // Sort the JavaScript by weight.
+        ksort($javascript[$scope][$type]);
         break;
-      default:
-        $javascript[$scope][$type][$data] = $options;
+      case 'file':
+        $javascript[$scope][$type][$options['weight']][$data] = $options;
+        // Sort the JavaScript by weight.
+        ksort($javascript[$scope][$type]);
     }
   }
 
@@ -2204,7 +2238,7 @@ function drupal_get_js($scope = 'header'
 
   $output = '';
   $preprocessed = '';
-  $no_preprocess = array('core' => '', 'module' => '', 'theme' => '');
+  $no_preprocess = '';
   $files = array();
   $preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
   $directory = file_directory_path();
@@ -2232,19 +2266,23 @@ function drupal_get_js($scope = 'header'
         $output .= '<script type="text/javascript">' . $embed_prefix . 'jQuery.extend(Drupal.settings, ' . drupal_to_js(call_user_func_array('array_merge_recursive', $data)) . ");" . $embed_suffix . "</script>\n";
         break;
       case 'inline':
-        foreach ($data as $info) {
-          $output .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . '>' . $embed_prefix . $info['code'] . $embed_suffix . "</script>\n";
+        foreach ($data as $weight => $settings) {
+          foreach ($settings as $info) {
+            $output .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . '>' . $embed_prefix . $info['code'] . $embed_suffix . "</script>\n";
+          }
         }
         break;
-      default:
+      case 'file':
         // If JS preprocessing is off, we still need to output the scripts.
         // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
-        foreach ($data as $path => $info) {
-          if (!$info['preprocess'] || !$is_writable || !$preprocess_js) {
-            $no_preprocess[$type] .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . ' src="' . base_path() . $path . ($info['cache'] ? $query_string : '?' . REQUEST_TIME) . "\"></script>\n";
-          }
-          else {
-            $files[$path] = $info;
+        foreach ($data as $weight => $paths) {
+          foreach ($paths as $path => $info) {
+            if (!$info['preprocess'] || !$is_writable || !$preprocess_js) {
+              $no_preprocess .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . ' src="' . base_path() . $path . ($info['cache'] ? $query_string : '?' . REQUEST_TIME) . "\"></script>\n";
+            }
+            else {
+              $files[$path] = $info;
+            }
           }
         }
     }
@@ -2259,9 +2297,7 @@ function drupal_get_js($scope = 'header'
 
   // Keep the order of JS files consistent as some are preprocessed and others are not.
   // Make sure any inline or JS setting variables appear last after libraries have loaded.
-  $output = $preprocessed . implode('', $no_preprocess) . $output;
-
-  return $output;
+  return $preprocessed . $no_preprocess . $output;
 }
 
 /**
@@ -2374,7 +2410,7 @@ function drupal_get_js($scope = 'header'
 function drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE, $limit = 0) {
   static $js_added = FALSE;
   if (!$js_added) {
-    drupal_add_js('misc/tabledrag.js', 'core');
+    drupal_add_js('misc/tabledrag.js', array('weight' => JS_WEIGHT_CORE));
     $js_added = TRUE;
   }
 
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.297
diff -u -p -r1.297 form.inc
--- includes/form.inc	15 Oct 2008 14:17:26 -0000	1.297
+++ includes/form.inc	25 Oct 2008 01:18:08 -0000
@@ -1504,7 +1504,7 @@ function form_get_options($element, $key
  */
 function theme_fieldset($element) {
   if ($element['#collapsible']) {
-    drupal_add_js('misc/collapse.js');
+    drupal_add_js('misc/collapse.js', array('weight' => JS_WEIGHT_CORE));
 
     if (!isset($element['#attributes']['class'])) {
       $element['#attributes']['class'] = '';
@@ -1879,8 +1879,8 @@ function form_process_ahah($element) {
   // Adding the same javascript settings twice will cause a recursion error,
   // we avoid the problem by checking if the javascript has already been added.
   if (isset($element['#ahah']['path']) && isset($element['#ahah']['event']) && !isset($js_added[$element['#id']])) {
-    drupal_add_js('misc/jquery.form.js');
-    drupal_add_js('misc/ahah.js');
+    drupal_add_js('misc/jquery.form.js', array('weight' => JS_WEIGHT_CORE));
+    drupal_add_js('misc/ahah.js', array('weight' => JS_WEIGHT_CORE));
 
     $ahah_binding = array(
       'url'      => url($element['#ahah']['path']),
@@ -1905,7 +1905,7 @@ function form_process_ahah($element) {
 
     // Add progress.js if we're doing a bar display.
     if ($ahah_binding['progress']['type'] == 'bar') {
-      drupal_add_js('misc/progress.js');
+      drupal_add_js('misc/progress.js', array('weight' => JS_WEIGHT_CORE, 'cache' => FALSE));
     }
 
     drupal_add_js(array('ahah' => array($element['#id'] => $ahah_binding)), 'setting');
@@ -2092,7 +2092,7 @@ function theme_textfield($element) {
   $output = '';
 
   if ($element['#autocomplete_path'] && menu_valid_path(array('link_path' => $element['#autocomplete_path']))) {
-    drupal_add_js('misc/autocomplete.js');
+    drupal_add_js('misc/autocomplete.js', array('weight' => JS_WEIGHT_CORE));
     $class[] = 'form-autocomplete';
     $extra =  '<input class="autocomplete" type="hidden" id="' . $element['#id'] . '-autocomplete" value="' . check_url(url($element['#autocomplete_path'], array('absolute' => TRUE))) . '" disabled="disabled" />';
   }
@@ -2144,7 +2144,7 @@ function theme_textarea($element) {
 
   // Add teaser behavior (must come before resizable)
   if (!empty($element['#teaser'])) {
-    drupal_add_js('misc/teaser.js');
+    drupal_add_js('misc/teaser.js', array('weight' => JS_WEIGHT_CORE));
     // Note: arrays are merged in drupal_get_js().
     drupal_add_js(array('teaserCheckbox' => array($element['#id'] => $element['#teaser_checkbox'])), 'setting');
     drupal_add_js(array('teaser' => array($element['#id'] => $element['#teaser'])), 'setting');
@@ -2153,7 +2153,7 @@ function theme_textarea($element) {
 
   // Add resizable behavior
   if ($element['#resizable'] !== FALSE) {
-    drupal_add_js('misc/textarea.js');
+    drupal_add_js('misc/textarea.js', array('weight' => JS_WEIGHT_CORE));
     $class[] = 'resizable';
   }
 
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.445
diff -u -p -r1.445 theme.inc
--- includes/theme.inc	24 Oct 2008 07:14:51 -0000	1.445
+++ includes/theme.inc	25 Oct 2008 01:18:09 -0000
@@ -158,7 +158,7 @@ function _init_theme($theme, $base_theme
 
   // Add scripts used by this theme.
   foreach ($final_scripts as $script) {
-    drupal_add_js($script, 'theme');
+    drupal_add_js($script, array('weight' => JS_WEIGHT_THEME));
   }
 
   $theme_engine = NULL;
@@ -1313,7 +1313,7 @@ function theme_table($header, $rows, $at
 
   // Add sticky headers, if applicable.
   if (count($header)) {
-    drupal_add_js('misc/tableheader.js');
+    drupal_add_js('misc/tableheader.js', array('weight' => JS_WEIGHT_CORE));
     // Add 'sticky-enabled' class to the table to identify it for JS.
     // This is needed to target tables constructed by this function.
     $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : ($attributes['class'] . ' sticky-enabled');
@@ -1430,7 +1430,7 @@ function theme_table($header, $rows, $at
  * Returns a header cell for tables that have a select all functionality.
  */
 function theme_table_select_header_cell() {
-  drupal_add_js('misc/tableselect.js');
+  drupal_add_js('misc/tableselect.js', array('weight' => JS_WEIGHT_CORE));
 
   return array('class' => 'select-all');
 }
Index: modules/block/block-admin-display-form.tpl.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block-admin-display-form.tpl.php,v
retrieving revision 1.6
diff -u -p -r1.6 block-admin-display-form.tpl.php
--- modules/block/block-admin-display-form.tpl.php	15 May 2008 21:30:02 -0000	1.6
+++ modules/block/block-admin-display-form.tpl.php	25 Oct 2008 01:18:09 -0000
@@ -26,7 +26,7 @@
 ?>
 <?php
   // Add table javascript.
-  drupal_add_js('misc/tableheader.js');
+  drupal_add_js('misc/tableheader.js', array('weight' => JS_WEIGHT_CORE));
   drupal_add_js(drupal_get_path('module', 'block') . '/block.js');
   foreach ($block_regions as $region => $title) {
     drupal_add_tabledrag('blocks', 'match', 'sibling', 'block-region-select', 'block-region-' . $region, NULL, FALSE);
Index: modules/color/color.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.module,v
retrieving revision 1.48
diff -u -p -r1.48 color.module
--- modules/color/color.module	9 Oct 2008 00:02:28 -0000	1.48
+++ modules/color/color.module	25 Oct 2008 01:18:09 -0000
@@ -154,7 +154,7 @@ function color_scheme_form(&$form_state,
 
   // Add Farbtastic color picker.
   drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
-  drupal_add_js('misc/farbtastic/farbtastic.js');
+  drupal_add_js('misc/farbtastic/farbtastic.js', array('weight' => JS_WEIGHT_CORE));
 
   // Add custom CSS and JS.
   drupal_add_css($base . '/color.css', 'module', 'all', FALSE);
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.230
diff -u -p -r1.230 locale.module
--- modules/locale/locale.module	22 Oct 2008 19:39:36 -0000	1.230
+++ modules/locale/locale.module	25 Oct 2008 01:18:10 -0000
@@ -566,7 +566,7 @@ function locale_update_js_files() {
 
   // Add the translation JavaScript file to the page.
   if ($files && !empty($language->javascript)) {
-    drupal_add_js($dir . '/' . $language->language . '_' . $language->javascript . '.js', 'core');
+    drupal_add_js($dir . '/' . $language->language . '_' . $language->javascript . '.js', array('weight' => JS_WEIGHT_CORE));
   }
 }
 
Index: modules/node/node.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.admin.inc,v
retrieving revision 1.27
diff -u -p -r1.27 node.admin.inc
--- modules/node/node.admin.inc	12 Oct 2008 04:30:06 -0000	1.27
+++ modules/node/node.admin.inc	25 Oct 2008 01:18:10 -0000
@@ -254,7 +254,7 @@ function node_filter_form() {
     $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
   }
 
-  drupal_add_js('misc/form.js', 'core');
+  drupal_add_js('misc/form.js', array('weight' => JS_WEIGHT_CORE));
 
   return $form;
 }
Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.21
diff -u -p -r1.21 simpletest.module
--- modules/simpletest/simpletest.module	15 Oct 2008 14:17:27 -0000	1.21
+++ modules/simpletest/simpletest.module	25 Oct 2008 01:18:11 -0000
@@ -200,7 +200,7 @@ function simpletest_test_form() {
 
 function theme_simpletest_test_table($table) {
   drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css', 'module');
-  drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', 'module');
+  drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js');
 
   // Create header for test selection table.
   $header = array(
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.9
diff -u -p -r1.9 common.test
--- modules/simpletest/tests/common.test	22 Oct 2008 19:39:36 -0000	1.9
+++ modules/simpletest/tests/common.test	25 Oct 2008 01:18:11 -0000
@@ -257,6 +257,11 @@ class DrupalSetContentTestCase extends D
  */
 class JavaScriptTestCase extends DrupalWebTestCase {
   /**
+   * Store configured value for JavaScript preprocessing.
+   */
+  var $preprocess_js;
+
+  /**
    * Implementation of getInfo().
    */
   function getInfo() {
@@ -266,34 +271,47 @@ class JavaScriptTestCase extends DrupalW
       'group' => t('System')
     );
   }
-  
+
   /**
    * Implementation of setUp().
    */
   function setUp() {
     // Reset drupal_add_js() before each test.
     drupal_add_js(NULL, NULL, TRUE);
+    // Disable Preprocessing
+    $this->preprocess_js = variable_get('preprocess_js', 0);
+    variable_set('preprocess_js', 0);
+    parent::setUp();
+  }
+
+  /**
+   * Implementation of tearDown()
+   */
+  function tearDown() {
+    // Restore configured value for JavaScript preprocessing.
+    variable_set('preprocess_js', $this->preprocess_js);
+    parent::tearDown();
   }
-  
+
   /**
    * Test default JavaScript is empty.
    */
   function testDefault() {
     $this->assertEqual(array(), drupal_add_js(), t('Default JavaScript is empty.'));
   }
-  
+
   /**
    * Test adding a JavaScript file.
    */
   function testAddFile() {
     drupal_add_js('misc/collapse.js');
     $javascript = drupal_add_js();
-    $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['core']), t('jQuery is added when a file is added.'));
-    $this->assertTrue(array_key_exists('misc/drupal.js', $javascript['header']['core']), t('Drupal.js is added when file is added.'));
-    $this->assertTrue(array_key_exists('misc/collapse.js', $javascript['header']['module']), t('JavaScript files are correctly added.'));
+    $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['file'][JS_WEIGHT_LIBRARY]), t('jQuery is added when a file is added.'));
+    $this->assertTrue(array_key_exists('misc/drupal.js', $javascript['header']['file'][JS_WEIGHT_LIBRARY]), t('Drupal.js is added when file is added.'));
+    $this->assertTrue(array_key_exists('misc/collapse.js', $javascript['header']['file'][JS_WEIGHT_MODULE]), t('JavaScript files are correctly added.'));
     $this->assertEqual(base_path(), $javascript['header']['setting'][0]['basePath'], t('Base path JavaScript setting is correctly set.'));
   }
-  
+
   /**
    * Test adding settings.
    */
@@ -303,7 +321,7 @@ class JavaScriptTestCase extends DrupalW
     $this->assertEqual(280342800, $javascript['header']['setting'][1]['dries'], t('JavaScript setting is set correctly.'));
     $this->assertEqual('rocks', $javascript['header']['setting'][1]['drupal'], t('The other JavaScript setting is set correctly.'));
   }
-  
+
   /**
    * Test drupal_get_js() for JavaScript settings.
    */
@@ -314,16 +332,16 @@ class JavaScriptTestCase extends DrupalW
     $this->assertTrue(strpos($javascript, 'testSetting') > 0, t('Rendered JavaScript header returns custom setting.'));
     $this->assertTrue(strpos($javascript, 'misc/jquery.js') > 0, t('Rendered JavaScript header includes jQuery.'));
   }
-  
+
   /**
    * Test to see if resetting the JavaScript empties the cache.
    */
   function testReset() {
-    drupal_add_js('misc/collapse.js');
-    drupal_add_js(NULL, NULL, TRUE);    
+    drupal_add_js('misc/collapse.js', array('weight' => JS_WEIGHT_CORE));
+    drupal_add_js(NULL, NULL, TRUE);
     $this->assertEqual(array(), drupal_add_js(), t('Resetting the JavaScript correctly empties the cache.'));
   }
-  
+
   /**
    * Test adding inline scripts.
    */
@@ -331,10 +349,10 @@ class JavaScriptTestCase extends DrupalW
     $inline = '$(document).ready(function(){});';
     drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer'));
     $javascript = drupal_add_js();
-    $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['core']), t('jQuery is added when inline scripts are added.'));
-    $this->assertEqual($inline, $javascript['footer']['inline'][0]['code'], t('Inline JavaScript is correctly added to the footer.'));
+    $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['file'][JS_WEIGHT_LIBRARY]), t('jQuery is added when inline scripts are added.'));
+    $this->assertEqual($inline, $javascript['footer']['inline'][JS_WEIGHT_MODULE][0]['code'], t('Inline JavaScript is correctly added to the footer.'));
   }
-  
+
   /**
    * Test drupal_get_js() with a footer scope.
    */
@@ -344,14 +362,23 @@ class JavaScriptTestCase extends DrupalW
     $javascript = drupal_get_js('footer');
     $this->assertTrue(strpos($javascript, $inline) > 0, t('Rendered JavaScript footer returns the inline code.'));
   }
-  
+
   /**
    * Test drupal_add_js() sets preproccess to false when cache is set to false.
    */
   function testNoCache() {
-    drupal_add_js('misc/collapse.js', array('cache' => FALSE));
+    drupal_add_js('misc/collapse.js', array('weight' => JS_WEIGHT_CORE, 'cache' => FALSE));
+    $javascript = drupal_add_js();
+    $this->assertFalse($javascript['header']['file'][JS_WEIGHT_CORE]['misc/collapse.js']['preprocess'], t('Setting cache to FALSE sets proprocess to FALSE when adding JavaScript.'));
+  }
+
+  /**
+   * Test adding a JavaScript file with a different weight.
+   */
+  function testDifferentWeight() {
+    drupal_add_js('misc/collapse.js', array('weight' => JS_WEIGHT_THEME));
     $javascript = drupal_add_js();
-    $this->assertTrue(!$javascript['header']['module']['misc/collapse.js']['preprocess'], t('Setting cache to FALSE sets proprocess to FALSE when adding JavaScript.'));
+    $this->assertTrue(array_key_exists('misc/collapse.js', $javascript['header']['file'][JS_WEIGHT_THEME]), t('Adding a JavaScript file with a different weight.'));
   }
 }
 
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.102
diff -u -p -r1.102 system.admin.inc
--- modules/system/system.admin.inc	16 Oct 2008 20:23:08 -0000	1.102
+++ modules/system/system.admin.inc	25 Oct 2008 01:18:13 -0000
@@ -1528,7 +1528,7 @@ function system_rss_feeds_settings() {
  * @see system_date_time_settings_submit()
  */
 function system_date_time_settings() {
-  drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module');
+  drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
   drupal_add_js(array('dateTime' => array('lookup' => url('admin/settings/date-time/lookup'))), 'setting');
 
   // Date settings:
@@ -1736,7 +1736,7 @@ function system_clean_url_settings() {
 
   if (!variable_get('clean_url', 0)) {
     if (strpos(request_uri(), '?q=') !== FALSE) {
-      drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module');
+      drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
 
       $form['clean_url']['#description'] .= ' <span>' . t('Before enabling clean URLs, you must perform a test to determine if your server is properly configured. If you are able to see this page again after clicking the "Run the clean URL test" link, the test has succeeded and the radio buttons above will be available. If instead you are directed to a "Page not found" error, you will need to change the configuration of your server. The <a href="@handbook">handbook page on Clean URLs</a> has additional troubleshooting information.', array('@handbook' => 'http://drupal.org/node/15365')) . '</span>';
 
Index: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.30
diff -u -p -r1.30 user.admin.inc
--- modules/user/user.admin.inc	19 Oct 2008 21:19:02 -0000	1.30
+++ modules/user/user.admin.inc	25 Oct 2008 01:18:13 -0000
@@ -83,7 +83,7 @@ function user_filter_form() {
     );
   }
 
-  drupal_add_js('misc/form.js', 'core');
+  drupal_add_js('misc/form.js', array('weight' => JS_WEIGHT_CORE));
 
   return $form;
 }
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.929
diff -u -p -r1.929 user.module
--- modules/user/user.module	19 Oct 2008 20:55:07 -0000	1.929
+++ modules/user/user.module	25 Oct 2008 01:18:15 -0000
@@ -2160,7 +2160,7 @@ function _user_password_dynamic_validati
   global $user;
   // Only need to do once per page.
   if (!$complete) {
-    drupal_add_js(drupal_get_path('module', 'user') . '/user.js', 'module');
+    drupal_add_js(drupal_get_path('module', 'user') . '/user.js');
 
     drupal_add_js(array(
       'password' => array(
