Do not save script object on the class constructor.
authoryangguo <yangguo@chromium.org>
Wed, 12 Aug 2015 13:06:03 +0000 (06:06 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 12 Aug 2015 13:06:20 +0000 (13:06 +0000)
We don't need it, as we can grab it from the shared function info.
Having it triggers an assertion if we define classes in native JS.

R=bmeurer@chromium.org, rossberg@chromium.org

Review URL: https://codereview.chromium.org/1290703002

Cr-Commit-Position: refs/heads/master@{#30134}

src/compiler/ast-graph-builder.cc
src/full-codegen/full-codegen.cc
src/heap/heap.h
src/runtime/runtime-classes.cc
src/runtime/runtime.h

index a9825cf40022b59790224aa19775d5b595b772ec..2b792be89472ed2c5b8715ec286fd4ecf2101d30 100644 (file)
@@ -1562,14 +1562,13 @@ void AstGraphBuilder::VisitClassLiteralContents(ClassLiteral* expr) {
   Node* constructor = environment()->Pop();
   Node* extends = environment()->Pop();
   Node* name = environment()->Pop();
-  Node* script = jsgraph()->Constant(info()->script());
   Node* start = jsgraph()->Constant(expr->start_position());
   Node* end = jsgraph()->Constant(expr->end_position());
   const Operator* opc = javascript()->CallRuntime(
       is_strong(language_mode()) ? Runtime::kDefineClassStrong
                                  : Runtime::kDefineClass,
-      6);
-  Node* literal = NewNode(opc, name, extends, constructor, script, start, end);
+      5);
+  Node* literal = NewNode(opc, name, extends, constructor, start, end);
   PrepareFrameState(literal, expr->CreateLiteralId(),
                     OutputFrameStateCombine::Push());
 
index 1ea6231f7dc5939d43879148490af45087b711a1..bb7b637d4224e0764e1f72d803d46f318b9dc472 100644 (file)
@@ -1293,13 +1293,12 @@ void FullCodeGenerator::VisitClassLiteral(ClassLiteral* lit) {
 
     VisitForStackValue(lit->constructor());
 
-    __ Push(script());
     __ Push(Smi::FromInt(lit->start_position()));
     __ Push(Smi::FromInt(lit->end_position()));
 
     __ CallRuntime(is_strong(language_mode()) ? Runtime::kDefineClassStrong
                                               : Runtime::kDefineClass,
-                   6);
+                   5);
     PrepareForBailoutForId(lit->CreateLiteralId(), TOS_REG);
 
     int store_slot_index = 0;
index 982eddbfb4fcab637cac31b6a82a1609dd172b44..162849414bb449d08f63ea44f3f1fb2f3ec94604 100644 (file)
@@ -317,7 +317,6 @@ namespace internal {
   V(intl_impl_object_symbol)        \
   V(promise_debug_marker_symbol)    \
   V(promise_has_handler_symbol)     \
-  V(class_script_symbol)            \
   V(class_start_position_symbol)    \
   V(class_end_position_symbol)      \
   V(error_start_pos_symbol)         \
index 1b70f05a60d57d0dac197b3d2a4447a413dc7dc5..3db4330cec7d0f2a2e1f857b872d39f9164f805f 100644 (file)
@@ -97,7 +97,6 @@ RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) {
 static MaybeHandle<Object> DefineClass(Isolate* isolate, Handle<Object> name,
                                        Handle<Object> super_class,
                                        Handle<JSFunction> constructor,
-                                       Handle<Script> script,
                                        int start_position, int end_position) {
   Handle<Object> prototype_parent;
   Handle<Object> constructor_parent;
@@ -181,11 +180,6 @@ static MaybeHandle<Object> DefineClass(Isolate* isolate, Handle<Object> name,
                         constructor, DONT_ENUM);
 
   // Install private properties that are used to construct the FunctionToString.
-  RETURN_ON_EXCEPTION(
-      isolate, Object::SetProperty(constructor,
-                                   isolate->factory()->class_script_symbol(),
-                                   script, STRICT),
-      Object);
   RETURN_ON_EXCEPTION(
       isolate,
       Object::SetProperty(
@@ -204,31 +198,29 @@ static MaybeHandle<Object> DefineClass(Isolate* isolate, Handle<Object> name,
 
 RUNTIME_FUNCTION(Runtime_DefineClass) {
   HandleScope scope(isolate);
-  DCHECK(args.length() == 6);
+  DCHECK(args.length() == 5);
   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
   CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1);
   CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2);
-  CONVERT_ARG_HANDLE_CHECKED(Script, script, 3);
-  CONVERT_SMI_ARG_CHECKED(start_position, 4);
-  CONVERT_SMI_ARG_CHECKED(end_position, 5);
+  CONVERT_SMI_ARG_CHECKED(start_position, 3);
+  CONVERT_SMI_ARG_CHECKED(end_position, 4);
 
   Handle<Object> result;
   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
       isolate, result, DefineClass(isolate, name, super_class, constructor,
-                                   script, start_position, end_position));
+                                   start_position, end_position));
   return *result;
 }
 
 
 RUNTIME_FUNCTION(Runtime_DefineClassStrong) {
   HandleScope scope(isolate);
-  DCHECK(args.length() == 6);
+  DCHECK(args.length() == 5);
   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
   CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1);
   CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2);
-  CONVERT_ARG_HANDLE_CHECKED(Script, script, 3);
-  CONVERT_SMI_ARG_CHECKED(start_position, 4);
-  CONVERT_SMI_ARG_CHECKED(end_position, 5);
+  CONVERT_SMI_ARG_CHECKED(start_position, 3);
+  CONVERT_SMI_ARG_CHECKED(end_position, 4);
 
   if (super_class->IsNull()) {
     THROW_NEW_ERROR_RETURN_FAILURE(
@@ -238,7 +230,7 @@ RUNTIME_FUNCTION(Runtime_DefineClassStrong) {
   Handle<Object> result;
   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
       isolate, result, DefineClass(isolate, name, super_class, constructor,
-                                   script, start_position, end_position));
+                                   start_position, end_position));
   return *result;
 }
 
@@ -283,32 +275,20 @@ RUNTIME_FUNCTION(Runtime_ClassGetSourceCode) {
   DCHECK(args.length() == 1);
   CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
 
-  Handle<Object> script;
-  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
-      isolate, script,
-      Object::GetProperty(fun, isolate->factory()->class_script_symbol()));
-  if (!script->IsScript()) {
-    return isolate->heap()->undefined_value();
-  }
-
   Handle<Symbol> start_position_symbol(
       isolate->heap()->class_start_position_symbol());
-  Handle<Object> start_position;
-  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
-      isolate, start_position, Object::GetProperty(fun, start_position_symbol));
+  Handle<Object> start_position =
+      JSReceiver::GetDataProperty(fun, start_position_symbol);
+  if (!start_position->IsSmi()) return isolate->heap()->undefined_value();
 
   Handle<Symbol> end_position_symbol(
       isolate->heap()->class_end_position_symbol());
-  Handle<Object> end_position;
-  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
-      isolate, end_position, Object::GetProperty(fun, end_position_symbol));
-
-  if (!start_position->IsSmi() || !end_position->IsSmi() ||
-      !Handle<Script>::cast(script)->HasValidSource()) {
-    return isolate->ThrowIllegalOperation();
-  }
+  Handle<Object> end_position =
+      JSReceiver::GetDataProperty(fun, end_position_symbol);
+  CHECK(end_position->IsSmi());
 
-  Handle<String> source(String::cast(Handle<Script>::cast(script)->source()));
+  Handle<String> source(
+      String::cast(Script::cast(fun->shared()->script())->source()));
   return *isolate->factory()->NewSubString(
       source, Handle<Smi>::cast(start_position)->value(),
       Handle<Smi>::cast(end_position)->value());
index fb6398845eb91743dfdea2495e530772ac1276be..1bc247ceeda4dd2ff757ef2d102374cea29701cb 100644 (file)
@@ -82,8 +82,8 @@ namespace internal {
   F(ThrowIfStaticPrototype, 1, 1)             \
   F(ToMethod, 2, 1)                           \
   F(HomeObjectSymbol, 0, 1)                   \
-  F(DefineClass, 6, 1)                        \
-  F(DefineClassStrong, 6, 1)                  \
+  F(DefineClass, 5, 1)                        \
+  F(DefineClassStrong, 5, 1)                  \
   F(FinalizeClassDefinition, 2, 1)            \
   F(DefineClassMethod, 3, 1)                  \
   F(ClassGetSourceCode, 1, 1)                 \