Commit 5fd4fa2a authored by ager@chromium.org's avatar ager@chromium.org

Introduce experimental natives that are enabled by a runtime flag.

Clean up the use of js2c. We generated two identical files.

R=sgjesse@chromium.org,rossberg@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6865013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7630 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1eaa4d60
......@@ -297,6 +297,11 @@ debug-debugger.js
'''.split()
EXPERIMENTAL_LIBRARY_FILES = '''
proxy.js
'''.split()
def Abort(message):
print message
sys.exit(1)
......@@ -321,9 +326,16 @@ def ConfigureObjectFiles():
# compile it.
library_files = [s for s in LIBRARY_FILES]
library_files.append('macros.py')
libraries_src, libraries_empty_src = env.JS2C(['libraries.cc', 'libraries-empty.cc'], library_files, TYPE='CORE')
libraries_src = env.JS2C(['libraries.cc'], library_files, TYPE='CORE')
libraries_obj = context.ConfigureObject(env, libraries_src, CPPPATH=['.'])
# Combine the experimental JavaScript library files into a C++ file
# and compile it.
experimental_library_files = [ s for s in EXPERIMENTAL_LIBRARY_FILES ]
experimental_library_files.append('macros.py')
experimental_libraries_src = env.JS2C(['experimental-libraries.cc'], experimental_library_files, TYPE='EXPERIMENTAL')
experimental_libraries_obj = context.ConfigureObject(env, experimental_libraries_src, CPPPATH=['.'])
source_objs = context.ConfigureObject(env, source_files)
non_snapshot_files = [source_objs]
......@@ -340,7 +352,7 @@ def ConfigureObjectFiles():
mksnapshot_env = env.Copy()
mksnapshot_env.Replace(**context.flags['mksnapshot'])
mksnapshot_src = 'mksnapshot.cc'
mksnapshot = mksnapshot_env.Program('mksnapshot', [mksnapshot_src, libraries_obj, non_snapshot_files, empty_snapshot_obj], PDB='mksnapshot.exe.pdb')
mksnapshot = mksnapshot_env.Program('mksnapshot', [mksnapshot_src, libraries_obj, experimental_libraries_obj, non_snapshot_files, empty_snapshot_obj], PDB='mksnapshot.exe.pdb')
if context.use_snapshot:
if context.build_snapshot:
snapshot_cc = env.Snapshot('snapshot.cc', mksnapshot, LOGFILE=File('snapshot.log').abspath)
......@@ -349,7 +361,7 @@ def ConfigureObjectFiles():
snapshot_obj = context.ConfigureObject(env, snapshot_cc, CPPPATH=['.'])
else:
snapshot_obj = empty_snapshot_obj
library_objs = [non_snapshot_files, libraries_obj, snapshot_obj]
library_objs = [non_snapshot_files, libraries_obj, experimental_libraries_obj, snapshot_obj]
return (library_objs, d8_objs, [mksnapshot], preparser_objs)
......
......@@ -200,6 +200,7 @@ class Genesis BASE_EMBEDDED {
// Used for creating a context from scratch.
void InstallNativeFunctions();
bool InstallNatives();
bool InstallExperimentalNatives();
void InstallBuiltinFunctionIds();
void InstallJSFunctionResultCaches();
void InitializeNormalizedMapCaches();
......@@ -246,6 +247,7 @@ class Genesis BASE_EMBEDDED {
Handle<FixedArray> caller);
static bool CompileBuiltin(Isolate* isolate, int index);
static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
static bool CompileNative(Vector<const char> name, Handle<String> source);
static bool CompileScriptCached(Vector<const char> name,
Handle<String> source,
......@@ -1175,6 +1177,15 @@ bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
}
bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
Vector<const char> name = ExperimentalNatives::GetScriptName(index);
Factory* factory = isolate->factory();
Handle<String> source_code =
factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index));
return CompileNative(name, source_code);
}
bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) {
HandleScope scope;
Isolate* isolate = source->GetIsolate();
......@@ -1510,7 +1521,6 @@ bool Genesis::InstallNatives() {
for (int i = Natives::GetDebuggerCount();
i < Natives::GetBuiltinsCount();
i++) {
Vector<const char> name = Natives::GetScriptName(i);
if (!CompileBuiltin(isolate(), i)) return false;
// TODO(ager): We really only need to install the JS builtin
// functions on the builtins object after compiling and running
......@@ -1628,6 +1638,18 @@ bool Genesis::InstallNatives() {
}
bool Genesis::InstallExperimentalNatives() {
if (FLAG_harmony_proxies) {
for (int i = ExperimentalNatives::GetDebuggerCount();
i < ExperimentalNatives::GetBuiltinsCount();
i++) {
if (!CompileExperimentalBuiltin(isolate(), i)) return false;
}
}
return true;
}
static Handle<JSObject> ResolveBuiltinIdHolder(
Handle<Context> global_context,
const char* holder_expr) {
......@@ -2108,6 +2130,9 @@ Genesis::Genesis(Isolate* isolate,
isolate->counters()->contexts_created_from_scratch()->Increment();
}
// Install experimental natives.
if (!InstallExperimentalNatives()) return;
result_ = global_context_;
}
......
......@@ -61,6 +61,7 @@
'variables': {
'js_files': [
'd8.js',
'macros.py',
],
},
'actions': [
......@@ -72,7 +73,6 @@
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/d8-js.cc',
'<(SHARED_INTERMEDIATE_DIR)/d8-js-empty.cc',
],
'action': [
'python',
......
......@@ -75,7 +75,6 @@
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/i18n-js.cc',
'<(SHARED_INTERMEDIATE_DIR)/i18n-js-empty.cc'
],
'action': [
'python',
......
......@@ -96,6 +96,9 @@ private:
//
#define FLAG FLAG_FULL
// Flags for experimental language features.
DEFINE_bool(harmony_proxies, false, "enable harmony proxies")
// Flags for Crankshaft.
#ifdef V8_TARGET_ARCH_MIPS
DEFINE_bool(crankshaft, false, "use crankshaft")
......
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
......@@ -36,7 +36,7 @@ typedef bool (*NativeSourceCallback)(Vector<const char> name,
int index);
enum NativeType {
CORE, D8, I18N
CORE, EXPERIMENTAL, D8, I18N
};
template <NativeType type>
......@@ -57,6 +57,7 @@ class NativesCollection {
};
typedef NativesCollection<CORE> Natives;
typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives;
} } // namespace v8::internal
......
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
global.Proxy = new $Object();
......@@ -230,7 +230,8 @@
'../../src',
],
'sources': [
'<(SHARED_INTERMEDIATE_DIR)/libraries-empty.cc',
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'<(INTERMEDIATE_DIR)/snapshot.cc',
],
'actions': [
......@@ -259,6 +260,7 @@
],
'sources': [
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'../../src/snapshot-empty.cc',
],
'conditions': [
......@@ -722,6 +724,10 @@
'../../src/regexp.js',
'../../src/macros.py',
],
'experimental_library_files': [
'../../src/proxy.js',
'../../src/macros.py',
],
},
'actions': [
{
......@@ -732,7 +738,6 @@
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/libraries-empty.cc',
],
'action': [
'python',
......@@ -742,6 +747,23 @@
'<@(library_files)'
],
},
{
'action_name': 'js2c_experimental',
'inputs': [
'../../tools/js2c.py',
'<@(experimental_library_files)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
],
'action': [
'python',
'../../tools/js2c.py',
'<@(_outputs)',
'EXPERIMENTAL',
'<@(experimental_library_files)'
],
},
],
},
{
......
......@@ -204,7 +204,7 @@ def ReadMacros(lines):
HEADER_TEMPLATE = """\
// Copyright 2008 Google Inc. All Rights Reserved.
// Copyright 2011 Google Inc. All Rights Reserved.
// This file was generated from .js source files by SCons. If you
// want to make changes to this file you should either change the
......@@ -288,7 +288,6 @@ def JS2C(source, target, env):
minifier = jsmin.JavaScriptMinifier()
source_lines_empty = []
for module in modules:
filename = str(module)
debugger = filename.endswith('-debugger.js')
......@@ -305,7 +304,6 @@ def JS2C(source, target, env):
else:
ids.append((id, len(lines)))
source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
# Build debugger support functions
get_index_cases = [ ]
......@@ -356,25 +354,11 @@ def JS2C(source, target, env):
})
output.close()
if len(target) > 1:
output = open(str(target[1]), "w")
output.write(HEADER_TEMPLATE % {
'builtin_count': len(ids) + len(debugger_ids),
'debugger_count': len(debugger_ids),
'source_lines': "\n".join(source_lines_empty),
'get_index_cases': "".join(get_index_cases),
'get_script_source_cases': "".join(get_script_source_cases),
'get_script_name_cases': "".join(get_script_name_cases),
'type': env['TYPE']
})
output.close()
def main():
natives = sys.argv[1]
natives_empty = sys.argv[2]
type = sys.argv[3]
source_files = sys.argv[4:]
JS2C(source_files, [natives, natives_empty], { 'TYPE': type })
type = sys.argv[2]
source_files = sys.argv[3:]
JS2C(source_files, [natives], { 'TYPE': type })
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment